Added support for multitexturing to osg::State and added osgmultitexture

demo which adds as spherical environment map using texture 1 to any model.
This commit is contained in:
Robert Osfield
2002-07-11 16:12:24 +00:00
parent c4c97a0f64
commit 8219a0a63a
7 changed files with 347 additions and 19 deletions

View File

@@ -76,6 +76,7 @@ DEMOS_DIRS = \
osggeometry\
osghud\
osgimpostor\
osgmultitexture\
osgoccluder\
osgparticle\
osgprerender\

View File

@@ -0,0 +1,95 @@
# Microsoft Developer Studio Project File - Name="Demo osgmultitexture" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=Demo osgmultitexture - Win32 Release
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "osgmultitexture.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "osgmultitexture.mak" CFG="Demo osgmultitexture - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Demo osgmultitexture - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "Demo osgmultitexture - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "Demo osgmultitexture - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x809 /d "NDEBUG"
# ADD RSC /l 0x809 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 /nologo /subsystem:console /pdb:none /machine:I386 /out:"../../../bin/osgmultitexture.exe" /libpath:"../../../lib"
!ELSEIF "$(CFG)" == "Demo osgmultitexture - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MDd /W3 /Gm /vd0 /GR /GX /Zi /Od /I "../../../include" /D "_CONSOLE" /D "_MBCS" /D "FL_DLL" /D "WIN32" /D "_DEBUG" /FR /YX /FD /c
# ADD BASE RSC /l 0x809 /d "_DEBUG"
# ADD RSC /l 0x809 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 glut32.lib glu32.lib opengl32.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"libcmt" /out:"../../../bin/osgmultitextured.exe" /pdbtype:sept /libpath:"../../../lib"
# SUBTRACT LINK32 /incremental:no
!ENDIF
# Begin Target
# Name "Demo osgmultitexture - Win32 Release"
# Name "Demo osgmultitexture - Win32 Debug"
# Begin Source File
SOURCE=..\..\..\src\Demos\osgmultitexture\osgmultitexture.cpp
# End Source File
# End Target
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Project

View File

@@ -834,6 +834,60 @@ Package=<4>
Project: "Demo osgmultitexture"=.\Demos\osgmultitexture\osgmultitexture.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name Core osg
End Project Dependency
Begin Project Dependency
Project_Dep_Name Core osgDB
End Project Dependency
Begin Project Dependency
Project_Dep_Name Core osgGA
End Project Dependency
Begin Project Dependency
Project_Dep_Name Core osgGLUT
End Project Dependency
Begin Project Dependency
Project_Dep_Name Core osgUtil
End Project Dependency
}}}
###############################################################################
Project: "Demo osgoccluder"=.\Demos\osgoccluder\osgoccluder.dsp - Package Owner=<4>

View File

@@ -20,6 +20,18 @@ SG_EXPORT extern const bool isGLExtensionSupported(const char *extension);
*/
SG_EXPORT extern void* getGLExtensionFuncPtr(const char *funcName);
/** return the address of the specified OpenGL function, if not found then
* check a second function name, if this fails then return NULL as function is
* not supported by OpenGL library. This is usual for checking something
* like glActiveTexture (which is in OGL1.3) or glActiveTextureARB.
*/
inline void* getGLExtensionFuncPtr(const char *funcName,const char *fallbackFuncName)
{
void* ptr = getGLExtensionFuncPtr(funcName);
if (ptr) return ptr;
return getGLExtensionFuncPtr(fallbackFuncName);
}
}
#endif

View File

@@ -13,6 +13,8 @@
#include <osg/DisplaySettings>
#include <osg/Polytope>
#include <osg/GLExtensions>
#include <vector>
#include <map>
@@ -301,7 +303,7 @@ class SG_EXPORT State : public Referenced
* note, only updates values that change.*/
inline void disableIndexPointer()
{
//if (_indexArray._enabled)
if (_indexArray._enabled)
{
_indexArray._enabled = false;
glDisableClientState(GL_INDEX_ARRAY);
@@ -319,7 +321,7 @@ class SG_EXPORT State : public Referenced
if ( unit >= _texCoordArrayList.size()) _texCoordArrayList.resize(unit+1);
EnabledArrayPair& eap = _texCoordArrayList[unit];
//if (!eap._enabled)
if (!eap._enabled)
{
eap._enabled = true;
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
@@ -354,14 +356,22 @@ class SG_EXPORT State : public Referenced
* note, only updates values that change.*/
inline bool setClientActiveTextureUnit( unsigned int unit )
{
return unit==0;
// will need to check for extensions etc.
// if (unit!=_currentClientActiveTextureUnit)
// {
// glClientActiveTextureARB(GL_TEXTURE0_ARB+unit);
// _currentClientActiveTextureUnit = unit;
// }
// return true;
if (unit!=_currentClientActiveTextureUnit)
{
static ActiveTextureProc s_glClientActiveTexture =
(ActiveTextureProc) osg::getGLExtensionFuncPtr("glClientActiveTexture","glClientActiveTextureARB");
if (s_glClientActiveTexture)
{
s_glClientActiveTexture(GL_TEXTURE0_ARB+unit);
_currentClientActiveTextureUnit = unit;
}
else
{
return unit==0;
}
}
return true;
}
@@ -369,14 +379,22 @@ class SG_EXPORT State : public Referenced
* note, only updates values that change.*/
inline bool setActiveTextureUnit( unsigned int unit )
{
return unit==0;
//
// if (unit!=_currentActiveTextureUnit)
// {
// glActiveTextureARB(GL_TEXTURE0_ARB+unit);
// _currentActiveTextureUnit = unit;
// }
// return true;
if (unit!=_currentActiveTextureUnit)
{
static ActiveTextureProc s_glActiveTexture =
(ActiveTextureProc) osg::getGLExtensionFuncPtr("glActiveTexture","glActiveTextureARB");
if (s_glActiveTexture)
{
s_glActiveTexture(GL_TEXTURE0_ARB+unit);
_currentActiveTextureUnit = unit;
}
else
{
return unit==0;
}
}
return true;
}
@@ -500,7 +518,8 @@ class SG_EXPORT State : public Referenced
else
return false;
}
typedef void (APIENTRY * ActiveTextureProc) (GLenum texture);
typedef std::map<StateAttribute::GLMode,ModeStack> ModeMap;
typedef std::vector<ModeMap> TextureModeMapList;

View File

@@ -0,0 +1,12 @@
TOPDIR = ../..
include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgmultitexture.cpp\
LIBS += $(OSG_LIBS) $(GLUT_LIB) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
EXEC = osgmultitexture
include $(TOPDIR)/Make/makerules

View File

@@ -0,0 +1,135 @@
#include <osg/GL>
#include <osgGLUT/glut>
#include <osgGLUT/Viewer>
#include <osg/Notify>
#include <osg/Texture>
#include <osg/TexEnv>
#include <osg/TexGen>
#include <osgDB/Registry>
#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgUtil/Optimizer>
void write_usage(std::ostream& out,const std::string& name)
{
out << std::endl;
out <<"usage:"<< std::endl;
out <<" "<<name<<" [options] infile1 [infile2 ...]"<< std::endl;
out << std::endl;
out <<"options:"<< std::endl;
out <<" -l libraryName - load plugin of name libraryName"<< std::endl;
out <<" i.e. -l osgdb_pfb"<< std::endl;
out <<" Useful for loading reader/writers which can load"<< std::endl;
out <<" other file formats in addition to its extension."<< std::endl;
out <<" -e extensionName - load reader/wrter plugin for file extension"<< std::endl;
out <<" i.e. -e pfb"<< std::endl;
out <<" Useful short hand for specifying full library name as"<< std::endl;
out <<" done with -l above, as it automatically expands to"<< std::endl;
out <<" the full library name appropriate for each platform."<< std::endl;
out <<std::endl;
out <<" -stereo - switch on stereo rendering, using the default of,"<< std::endl;
out <<" ANAGLYPHIC or the value set in the OSG_STEREO_MODE "<< std::endl;
out <<" environmental variable. See doc/stereo.html for "<< std::endl;
out <<" further details on setting up accurate stereo "<< std::endl;
out <<" for your system. "<< std::endl;
out <<" -stereo ANAGLYPHIC - switch on anaglyphic(red/cyan) stereo rendering."<< std::endl;
out <<" -stereo QUAD_BUFFER - switch on quad buffered stereo rendering."<< std::endl;
out <<std::endl;
out <<" -stencil - use a visual with stencil buffer enabled, this "<< std::endl;
out <<" also allows the depth complexity statistics mode"<< std::endl;
out <<" to be used (press 'p' three times to cycle to it)."<< std::endl;
out << std::endl;
}
int main( int argc, char **argv )
{
// initialize the GLUT
glutInit( &argc, argv );
if (argc<2)
{
write_usage(std::cout,argv[0]);
return 0;
}
// create the commandline args.
std::vector<std::string> commandLine;
for(int i=1;i<argc;++i) commandLine.push_back(argv[i]);
// initialize the viewer.
osgGLUT::Viewer viewer;
viewer.setWindowTitle(argv[0]);
// configure the viewer from the commandline arguments, and eat any
// parameters that have been matched.
viewer.readCommandLine(commandLine);
// configure the plugin registry from the commandline arguments, and
// eat any parameters that have been matched.
osgDB::readCommandLine(commandLine);
// load the nodes from the commandline arguments.
osg::Node* rootnode = osgDB::readNodeFiles(commandLine);
if (!rootnode)
{
// write_usage(osg::notify(osg::NOTICE),argv[0]);
return 1;
}
osg::Image* image = osgDB::readImageFile("reflect.rgb");
if (image)
{
osg::Texture* texture = new osg::Texture;
texture->setImage(image);
osg::TexGen* texgen = new osg::TexGen;
texgen->setMode(osg::TexGen::SPHERE_MAP);
osg::TexEnv* texenv = new osg::TexEnv;
texenv->setMode(osg::TexEnv::MODULATE);
osg::StateSet* stateset = new osg::StateSet;
stateset->setTextureAttributeAndModes(1,texture,osg::StateAttribute::ON);
stateset->setTextureAttributeAndModes(1,texgen,osg::StateAttribute::ON);
stateset->setTextureAttribute(1,texenv);
rootnode->setStateSet(stateset);
}
else
{
notify(osg::NOTICE)<<"unable to load reflect map, model will not be mutlitextured"<<endl;
}
// run optimization over the scene graph
osgUtil::Optimizer optimzer;
optimzer.optimize(rootnode);
// add a viewport to the viewer and attach the scene graph.
viewer.addViewport( rootnode );
// register trackball, flight and drive.
viewer.registerCameraManipulator(new osgGA::TrackballManipulator);
viewer.registerCameraManipulator(new osgGA::FlightManipulator);
viewer.registerCameraManipulator(new osgGA::DriveManipulator);
// open the viewer window.
viewer.open();
// fire up the event loop.
viewer.run();
return 0;
}