diff --git a/Make/makedirdefs b/Make/makedirdefs index d211d8467..db392a785 100644 --- a/Make/makedirdefs +++ b/Make/makedirdefs @@ -76,6 +76,7 @@ DEMOS_DIRS = \ osggeometry\ osghud\ osgimpostor\ + osgmultitexture\ osgoccluder\ osgparticle\ osgprerender\ diff --git a/VisualStudio/Demos/osgmultitexture/osgmultitexture.dsp b/VisualStudio/Demos/osgmultitexture/osgmultitexture.dsp new file mode 100644 index 000000000..b827d61cd --- /dev/null +++ b/VisualStudio/Demos/osgmultitexture/osgmultitexture.dsp @@ -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 diff --git a/VisualStudio/VisualStudio.dsw b/VisualStudio/VisualStudio.dsw index 275f55a06..7ee1eb93c 100644 --- a/VisualStudio/VisualStudio.dsw +++ b/VisualStudio/VisualStudio.dsw @@ -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> diff --git a/include/osg/GLExtensions b/include/osg/GLExtensions index eb04bf918..0d8f3a88f 100644 --- a/include/osg/GLExtensions +++ b/include/osg/GLExtensions @@ -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 diff --git a/include/osg/State b/include/osg/State index 8815a0071..06a4b2de1 100644 --- a/include/osg/State +++ b/include/osg/State @@ -13,6 +13,8 @@ #include #include +#include + #include #include @@ -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 ModeMap; typedef std::vector TextureModeMapList; diff --git a/src/Demos/osgmultitexture/Makefile.inst b/src/Demos/osgmultitexture/Makefile.inst new file mode 100644 index 000000000..c8cb55d38 --- /dev/null +++ b/src/Demos/osgmultitexture/Makefile.inst @@ -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 diff --git a/src/Demos/osgmultitexture/osgmultitexture.cpp b/src/Demos/osgmultitexture/osgmultitexture.cpp new file mode 100644 index 000000000..ef54ba41a --- /dev/null +++ b/src/Demos/osgmultitexture/osgmultitexture.cpp @@ -0,0 +1,135 @@ +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include + + +#include + +void write_usage(std::ostream& out,const std::string& name) +{ + out << std::endl; + out <<"usage:"<< std::endl; + out <<" "< commandLine; + for(int i=1;isetImage(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"<