What I've tried from your suggestions I hope the code here is clear enough. I haven't had any success with your suggestions to this point. I have placed them in an easy format to try them all without getting commented code mixed up with other code. I'm posting here the four relevant sections of my code, in hopes it may help get me over this hump. I've tried putting the OSG initialization before the OpenGl initialization and the three different suggestions of initialization and rendering. I've ensured the DLL wrapper works, it will retun the values I set in them and I can step through it while debugging and see legit values being assigned to the font. "DartModelDll.dll" is poorly named and will be changed in the future. Anywhere that name is in the following, assume OsgDLL.
C# Form Constructor Code: public partial class Form1 : Form { OsgWrapper osgWrapper; // OpenGL contrrol object private static OpenGLControl openGLControl; public Form1() { // Initialze components InitializeComponent(); // Test osgWrapper = new OsgWrapper(); int blah = osgWrapper.Init(); // Initialize SharpGL initSharpGL(); ... C# OSG Drawing Function Code: private void openGLControl_OpenGLDraw(object sender, PaintEventArgs e) { // Get the OpenGL object. OpenGL gl = openGLControl.OpenGL; // Clear the color and depth buffer. gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); gl.ClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Load the identity matrix. gl.LoadIdentity(); scoreKeeper.calculateGameScore(); // Render the textures for the dartboard and background renderBackgroundTextures(); // render dartboard sections renderDartboardSections(); // render scoring sections renderScoringSection(); int blah = osgWrapper.TestText(); ... C# Wrapper Code for the Osg DLL Code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using WMPLib; using System.Runtime.InteropServices; namespace DartBoardApplication.Items { public class OsgWrapper { [DllImport("DartModelDll.dll")] static extern IntPtr dll_cOsgViewer(); [DllImport("DartModelDll.dll", CallingConvention = CallingConvention.Cdecl)] static extern int dll_initViewer(IntPtr dm); [DllImport("DartModelDll.dll", CallingConvention = CallingConvention.Cdecl)] static extern int dll_testText(IntPtr dm); IntPtr dartModel; public OsgWrapper() { dartModel = dll_cOsgViewer(); } public int Init() { return dll_initViewer(dartModel); } public int TestText() { return dll_testText(dartModel); } } } Osg DLL Code: #include "Windows.h" #include "gl/gl.h" #include "osg/Node" #include "osg/Geode" #include "osg/Group" #include "osgViewer/Viewer" #include "osgViewer/CompositeViewer" #include "osgViewer/GraphicsWindow" #include "osgDB/ReadFile" #include "osgText/Text" #include "osg/ShapeDrawable" #include "excpt.h" #include "osg/StateSet" #include "osgViewer/Viewer" #include "osg/MatrixTransform" using namespace osg; using namespace osgDB; using namespace osgText; class COsgViewer { public: COsgViewer() { }; ~COsgViewer() { } osg::ref_ptr<osgText::Font> font; osg::ref_ptr<osgViewer::Viewer> mViewer; osgViewer::CompositeViewer *viewer; osg::observer_ptr<osgViewer::GraphicsWindowEmbedded> mWindow; osg::ref_ptr<osg::Group> mRoot; osg::ref_ptr<osg::Geode> geode; osg::ref_ptr<osg::StateSet> mLastStateSet; int initViewer(void) { //initViewer1(); //initViewer2(); initViewer3(); return 4; } void initViewer1() { // Create the scene root mRoot = new osg::Group; geode = new osg::Geode; std::string fontFile("arial.ttf"); font = osgText::readFontFile(fontFile); if (font.valid()) { osgText::Text* text = new osgText::Text; if (text != 0) { text->setUseDisplayList(false); text->setFont(font); text->setColor(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); text->setCharacterSize(36.0f); text->setAutoRotateToScreen(true); text->setPosition(osg::Vec3(100.0f, 100.0f, 10.0f)); //text->setAxisAlignment(osgText::Text::XZ_PLANE); text->setText("SomeSome!"); text->setLayout(osgText::Text::LEFT_TO_RIGHT); geode->addDrawable(text); } } mRoot->addChild(geode); // The viewer mViewer = new osgViewer::Viewer; mWindow = mViewer->setUpViewerAsEmbeddedInWindow(0, 0, 1680, 1060); mViewer->getCamera()->setClearMask(0); mViewer->getCamera()->setComputeNearFarMode(osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR); mViewer->setSceneData(mRoot); mViewer->realize(); } void initViewer2() { // Create the scene root mRoot = new osg::Group; geode = new osg::Geode; std::string fontFile("arial.ttf"); font = osgText::readFontFile(fontFile); if (font.valid()) { osgText::Text* text = new osgText::Text; if (text != 0) { text->setUseDisplayList(false); text->setFont(font); text->setColor(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); text->setCharacterSize(36.0f); text->setAutoRotateToScreen(true); text->setPosition(osg::Vec3(100.0f, 100.0f, 10.0f)); //text->setAxisAlignment(osgText::Text::XZ_PLANE); text->setText("SomeSome!"); text->setLayout(osgText::Text::LEFT_TO_RIGHT); geode->addDrawable(text); } } viewer = new osgViewer::CompositeViewer(); osgViewer::GraphicsWindowEmbedded *gw = (osgViewer::GraphicsWindowEmbedded*) new osgViewer::GraphicsWindow(); gw->setWindowRectangle(0, 0, 1680, 1060); gw->setClearMask(0); osgViewer::View *view = new osgViewer::View; view->getCamera()->setGraphicsContext(gw); view->getCamera()->setViewport(0, 0, 1680, 1060); // somewhere inside OGL viewport/window that has origin in LL corner view->setSceneData(geode); viewer->addView(view); viewer->realize(); } void initViewer3() { // Create the scene root mRoot = new osg::Group; geode = new osg::Geode; std::string fontFile("arial.ttf"); font = osgText::readFontFile(fontFile); if (font.valid()) { osgText::Text* text = new osgText::Text; if (text != 0) { text->setUseDisplayList(false); text->setFont(font); text->setColor(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); text->setCharacterSize(36.0f); text->setAutoRotateToScreen(true); text->setPosition(osg::Vec3(100.0f, 100.0f, 10.0f)); //text->setAxisAlignment(osgText::Text::XZ_PLANE); text->setText("SomeSome!"); text->setLayout(osgText::Text::LEFT_TO_RIGHT); geode->addDrawable(text); } } mRoot->addChild(geode); mViewer = new osgViewer::Viewer(); osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> embeddedWindow; embeddedWindow = mViewer->setUpViewerAsEmbeddedInWindow(0, 0, 1680, 1060); osg::ref_ptr<osg::StateSet> mLastStateSet = new osg::StateSet(); mViewer->getCamera()->getGraphicsContext()->getState()->captureCurrentState(*mLastStateSet.get()); //mViewer->setSceneData(mRoot); //mViewer->realize(); } int testText() { //testText1(); //testText2(); testText3(); return 1; } int testText1() { // This function can be used to test rendering text. // Is called every frame glPushAttrib(GL_ALL_ATTRIB_BITS); glMatrixMode(GL_PROJECTION); glPushMatrix(); glMatrixMode(GL_TEXTURE); glPushMatrix(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); mViewer->frame(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glMatrixMode(GL_TEXTURE); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glPopAttrib(); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); return 1; } int testText2() { // This function can be used to test rendering text. // Is called every frame glPushAttrib(GL_ALL_ATTRIB_BITS); glMatrixMode(GL_PROJECTION); glPushMatrix(); glMatrixMode(GL_TEXTURE); glPushMatrix(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); viewer->frame(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glMatrixMode(GL_TEXTURE); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glPopAttrib(); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); return 1; } int testText3() { osg::State *osgState = mViewer->getCamera()->getGraphicsContext()->getState(); osgState->reset(); osgState->apply(mLastStateSet.get()); //render your osg frame here mViewer->frame(); //now get the state so you can restore next frame mViewer->getCamera()->getGraphicsContext()->getState()->captureCurrentState(*mLastStateSet.get()); return 1; } }; extern "C" { __declspec(dllexport) COsgViewer* dll_cOsgViewer() { return new COsgViewer(); } } extern "C" { __declspec(dllexport) int dll_initViewer(COsgViewer* dm) { return dm->initViewer(); } } extern "C" { __declspec(dllexport) int dll_testText(COsgViewer* dm) { return dm->testText(); } } Thank you! Cheers, Dainon ------------------ Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=50179#50179 _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org