diff --git a/VisualStudio/Demos/osghud/osghud.dsp b/VisualStudio/Demos/osghud/osghud.dsp new file mode 100755 index 000000000..744b3ac15 --- /dev/null +++ b/VisualStudio/Demos/osghud/osghud.dsp @@ -0,0 +1,95 @@ +# Microsoft Developer Studio Project File - Name="Demo osghud" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=Demo osghud - 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 "osghud.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 "osghud.mak" CFG="Demo osghud - Win32 Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "Demo osghud - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "Demo osghud - 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 osghud - 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/osghud.exe" /libpath:"../../../lib" + +!ELSEIF "$(CFG)" == "Demo osghud - 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 "WIN32" /D "_DEBUG" /D "FL_DLL" /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/osghudd.exe" /pdbtype:sept /libpath:"../../../lib" +# SUBTRACT LINK32 /incremental:no + +!ENDIF + +# Begin Target + +# Name "Demo osghud - Win32 Release" +# Name "Demo osghud - Win32 Debug" +# Begin Source File + +SOURCE=..\..\..\src\Demos\osghud\osghud.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/Demos/osgtext/osgtext.dsp b/VisualStudio/Demos/osgtext/osgtext.dsp index d9ff2b28f..72d1e927f 100644 --- a/VisualStudio/Demos/osgtext/osgtext.dsp +++ b/VisualStudio/Demos/osgtext/osgtext.dsp @@ -74,7 +74,7 @@ BSC32=bscmake.exe # 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 /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"libcmt" /out:"../../../bin/osgtextd.exe" /pdbtype:sept /libpath:"../../../lib" +# ADD LINK32 glut32.lib glu32.lib opengl32.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"libcmt" /out:"../../../bin/osgtextd.exe" /pdbtype:sept /libpath:"../../../lib" # SUBTRACT LINK32 /incremental:no !ENDIF @@ -85,7 +85,7 @@ LINK32=link.exe # Name "Demo osgtext - Win32 Debug" # Begin Source File -SOURCE=..\..\..\src\Demos\osgtext\main.cpp +SOURCE=..\..\..\src\Demos\osgtext\osgtext.cpp # End Source File # End Target # Begin Group "Resource Files" diff --git a/VisualStudio/VisualStudio.dsw b/VisualStudio/VisualStudio.dsw index 322e76a55..ba3451876 100644 --- a/VisualStudio/VisualStudio.dsw +++ b/VisualStudio/VisualStudio.dsw @@ -201,6 +201,33 @@ Package=<4> ############################################################################### +Project: "Demo osghud"=.\Demos\osghud\osghud.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 osgGLUT + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgUtil + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgText + End Project Dependency +}}} + +############################################################################### + Project: "Demo osgimpostor"=.\Demos\osgimpostor\osgimpostor.dsp - Package Owner=<4> Package=<5> diff --git a/src/Demos/Makefile b/src/Demos/Makefile index e2fa12d9b..50f319e85 100644 --- a/src/Demos/Makefile +++ b/src/Demos/Makefile @@ -8,6 +8,7 @@ DIRS = \ osgconv\ osgcopy\ osgcube\ + osghud\ osgimpostor\ osgreflect\ osgscribe\ diff --git a/src/Demos/osghud/Makefile b/src/Demos/osghud/Makefile new file mode 100644 index 000000000..d9b02e6a5 --- /dev/null +++ b/src/Demos/osghud/Makefile @@ -0,0 +1,16 @@ +TOPDIR = ../../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + osghud.cpp\ + +LINKARGS += -L/usr/local/lib +LIBS += -losgText $(OSG_LIBS) $(FREETYPE_LIB) $(GLUT_LIB) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) + +INSTFILES = \ + $(CXXFILES)\ + Makefile.inst=Makefile + +EXEC = osghud + +include $(TOPDIR)/Make/makerules diff --git a/src/Demos/osghud/osghud.cpp b/src/Demos/osghud/osghud.cpp new file mode 100644 index 000000000..3d6d8ca12 --- /dev/null +++ b/src/Demos/osghud/osghud.cpp @@ -0,0 +1,350 @@ +#include +#include +#include + +#include +#include +#include +#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 <<" "< > gTextList; +osgText::Text::AlignmentType gAlignment=osgText::Text::LEFT_BOTTOM; + +void set2dScene(osg::Group* rootNode) +{ + osgText::Text* text; + osg::Geode* geode; + osg::Material* textMaterial; + osg::StateSet* textState; + double xOffset=150; + double yOffset=gFontSize+10; + + /////////////////////////////////////////////////////////////////////////// + // setup the texts + + /////////////////////////////////////////////////////////////////////////// + // BitmapFont + osgText::BitmapFont* bitmapFont= osgNew osgText::BitmapFont(ttfPath, + gFontSize1); + text= osgNew osgText::Text(bitmapFont); + gTextList.push_back(text); + text->setText(std::string("2d ")+std::string(TEXT_BITMAP)); + text->setPosition(osg::Vec3(xOffset,yOffset,0)); + text->setDrawMode( osgText::Text::TEXT | + osgText::Text::BOUNDINGBOX | + osgText::Text::ALIGNEMENT ); + text->setAlignment(gAlignment); + geode = osgNew osg::Geode(); + geode->setName("BitmapFont"); + geode->addDrawable( text ); + + textMaterial = osgNew osg::Material(); + textMaterial->setColorMode( osg::Material::AMBIENT_AND_DIFFUSE); + textMaterial->setDiffuse( osg::Material::FRONT_AND_BACK, TEXT_COL_2D); + textState = osgNew osg::StateSet(); + textState->setAttribute(textMaterial ); + geode->setStateSet( textState ); + + rootNode->addChild(geode); + + xOffset+=90; + yOffset+=120; + + /////////////////////////////////////////////////////////////////////////// + // PixmapFont + osgText::PixmapFont* pixmapFont= osgNew osgText::PixmapFont(ttfPath, + gFontSize1); + text= osgNew osgText::Text(pixmapFont); + gTextList.push_back(text); + text->setText(std::string("2d ")+std::string(TEXT_PIXMAP)); + text->setPosition(osg::Vec3(xOffset,yOffset,0)); + text->setDrawMode( osgText::Text::TEXT | + osgText::Text::BOUNDINGBOX | + osgText::Text::ALIGNEMENT ); + text->setAlignment(gAlignment); + geode = osgNew osg::Geode(); + geode->setName("PixmapFont"); + geode->addDrawable( text ); + + textMaterial = osgNew osg::Material(); + textMaterial->setColorMode( osg::Material::AMBIENT_AND_DIFFUSE); + textMaterial->setDiffuse( osg::Material::FRONT_AND_BACK,TEXT_COL_2D); + // to get antiaA pixmapFonts we have to draw them with blending + osg::Transparency *transp= osgNew osg::Transparency(); + transp->setFunction(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + + + + + textState = osgNew osg::StateSet(); + textState->setAttribute(textMaterial ); + textState->setAttribute(transp); + textState->setMode(GL_BLEND,osg::StateAttribute::ON); + textState->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); + + + geode->setStateSet( textState ); + + rootNode->addChild(geode); + + xOffset+=90; + yOffset+=120; + + /////////////////////////////////////////////////////////////////////////// + // TextureFont + osgText::TextureFont* textureFont= osgNew osgText::TextureFont(ttfPath1, + gFontSize1); + text= osgNew osgText::Text(textureFont); + gTextList.push_back(text); + text->setText(std::string("2d ")+std::string(TEXT_TEXTURE)); + text->setPosition(osg::Vec3(xOffset,yOffset,0)); + text->setDrawMode( osgText::Text::TEXT | + osgText::Text::BOUNDINGBOX | + osgText::Text::ALIGNEMENT ); + text->setAlignment(gAlignment); + geode = osgNew osg::Geode(); + geode->setName("TextureFont"); + geode->addDrawable( text ); + + textMaterial = osgNew osg::Material(); + textMaterial->setColorMode( osg::Material::AMBIENT_AND_DIFFUSE); + textMaterial->setDiffuse( osg::Material::FRONT_AND_BACK, TEXT_COL_2D); + // to get antiaA pixmapFonts we have to draw them with blending + transp= osgNew osg::Transparency(); + transp->setFunction(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + textState = osgNew osg::StateSet(); + textState->setAttribute(textMaterial ); + textState->setAttribute(transp); + + textState->setMode(GL_TEXTURE_2D,osg::StateAttribute::ON); + textState->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); + geode->setStateSet( textState ); + + rootNode->addChild(geode); + + xOffset+=90; + yOffset+=120; + + /////////////////////////////////////////////////////////////////////////// + // PolygonFont + osgText::PolygonFont* polygonFont= osgNew osgText::PolygonFont(ttfPath, + gFontSize1, + 3); + text= osgNew osgText::Text(polygonFont); + gTextList.push_back(text); + text->setText(std::string("2d ")+std::string("TEXT_POLYGON")); + text->setPosition(osg::Vec3(xOffset,yOffset,0)); + text->setDrawMode( osgText::Text::TEXT | + osgText::Text::BOUNDINGBOX | + osgText::Text::ALIGNEMENT ); + text->setAlignment(gAlignment); + geode = osgNew osg::Geode(); + geode->setName("PolygonFont"); + geode->addDrawable( text ); + + textMaterial = osgNew osg::Material(); + textMaterial->setColorMode( osg::Material::AMBIENT_AND_DIFFUSE); + textMaterial->setDiffuse( osg::Material::FRONT_AND_BACK, TEXT_COL_2D); + textState = osgNew osg::StateSet(); + textState->setAttribute(textMaterial ); + geode->setStateSet( textState ); + + rootNode->addChild(geode); + + xOffset+=90; + yOffset+=120; + + /////////////////////////////////////////////////////////////////////////// + // OutlineFont + osgText::OutlineFont* outlineFont= osgNew osgText::OutlineFont(ttfPath, + gFontSize1, + 3); + + text= osgNew osgText::Text(outlineFont); + gTextList.push_back(text); + text->setText(std::string("2d ")+std::string(TEXT_OUTLINE)); + text->setPosition(osg::Vec3(xOffset,yOffset,0)); + text->setDrawMode( osgText::Text::TEXT | + osgText::Text::BOUNDINGBOX | + osgText::Text::ALIGNEMENT ); + text->setAlignment(gAlignment); + geode = osgNew osg::Geode(); + geode->setName("OutlineFont"); + geode->addDrawable( text ); + + textMaterial = osgNew osg::Material(); + textMaterial->setColorMode( osg::Material::AMBIENT_AND_DIFFUSE); + textMaterial->setDiffuse( osg::Material::FRONT_AND_BACK, TEXT_COL_2D); + textState = osgNew osg::StateSet(); + textState->setAttribute(textMaterial ); + geode->setStateSet( textState ); + + rootNode->addChild(geode); + + + // now add a depth attribute to the scene to force it to draw on top. + osg::Depth* depth = osgNew osg::Depth; + depth->setRange(0.0,0.0); + + osg::StateSet* rootState = osgNew osg::StateSet(); + rootState->setAttribute(depth); + rootState->setMode(GL_LIGHTING,osg::StateAttribute::OFF); + + rootNode->setStateSet(rootState); + +} + + + + + + +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 commandLine; + for(int i=1;i(rootnode); + if (!group) + { + group = osgNew osg::Group; + group->addChild(rootnode); + rootnode = group; + } + + // create the hud. + osg::Projection* projection = osgNew osg::Projection; + projection->setMatrix(osg::Matrix::ortho2D(0,1024,0,768)); + + osg::Transform* modelview_abs = osgNew osg::Transform; + modelview_abs->setReferenceFrame(osg::Transform::RELATIVE_TO_ABSOLUTE); + modelview_abs->setMatrix(osg::Matrix::identity()); + + + set2dScene(modelview_abs); + + projection->addChild(modelview_abs); + + group->addChild(projection); + + + // add a viewport to the viewer and attach the scene graph. + viewer.addViewport( rootnode ); + + // register trackball, flight and drive. + viewer.registerCameraManipulator(new osgUtil::TrackballManipulator); + viewer.registerCameraManipulator(new osgUtil::FlightManipulator); + viewer.registerCameraManipulator(new osgUtil::DriveManipulator); + + // open the viewer window. + viewer.open(); + + // fire up the event loop. + viewer.run(); + + return 0; +}