Hello, it's me again.
In this e-mail I will explain with more detail the first problem I still
have with the porting of my application to OpenSG 2.0;
the problem is related to text updates every frame (or so...)

I wrote a simple program to demonstrate the problem (it's a modified version
of testTextTXFGeo, actually...)
In this program a single TextTXFFace is created and used to update a
geometry (created with TextTXFFace->makeNode()) once per second with a
random number of lines of random characters.
The methods used to update the text are TextTXFFace ->layout(lines,
layoutParam, layoutResult) and TextTXFFace->fillGeo(geo, layoutResult,
scale)

Using OpenSG 1.8 it worked well, but now it sometimes generates a crappy
texture with old characters mixed with the new characters.
When the texture is wrong, a warning message is displayed:

WARNING: (..\..\..\Source\System\State\Base\OSGTextureObjChunk.cpp,2029):
TextureObjChunk::deactivate precheck failed: valore non valido (0x501)

Thank you for your help! :)

Christian Bar


---------------------------------------------------------------------------------------------------------------------------------------
#include "OSGGLUT.h"
#include "OSGConfig.h"
#include "OSGSimpleGeometry.h"
#include "OSGGLUTWindow.h"
#include "OSGSimpleSceneManager.h"
#include "OSGSimpleMaterial.h"
#include "OSGTextureObjChunk.h"
#include "OSGTextureEnvChunk.h"
#include "OSGBaseFunctions.h"
#include "OSGTransform.h"
#include "OSGGroup.h"
#include "OSGSolidBackground.h"
#include "OSGImage.h"
#include "OSGGeometry.h"
#include "OSGTypedGeoIntegralProperty.h"
#include "OSGTextTXFFace.h"
#include "OSGTextTXFGlyph.h"
#include "OSGTextLayoutParam.h"
#include "OSGTextLayoutResult.h"
#include "OSGTextFaceFactory.h"

using namespace std;

OSG::SimpleSceneManager *mgr;
OSG::NodeRecPtr scene;
OSG::GeometryRecPtr geo;
OSG::TextTXFFaceRefPtr face = 0;
OSG::TextLayoutParam layoutParam;
OSG::TextLayoutResult layoutResult;
vector<string> lines;
__int64 startingTime;

// forward declaration so we can have the interesting stuff upfront
int setupGLUT( int *argc, char *argv[] );

void createScene(void)
{
    // Put it all together into a Geometry NodeCore.
layoutParam.horizontal = true;
layoutParam.leftToRight = true;
layoutParam.topToBottom = true;
layoutParam.spacing = 1.f;
layoutParam.length.push_back(0.f);
layoutParam.maxExtend = 0.f;
    face->layout(lines, layoutParam, layoutResult);

    OSG::NodeUnrecPtr textNode = face->makeNode(layoutResult, 2.f);
    geo = dynamic_cast<OSG::Geometry *>(textNode->getCore());

    OSG::NodeUnrecPtr transNodePtr = OSG::Node::create();
    OSG::TransformUnrecPtr transPtr = OSG::Transform::create();
    OSG::Matrix transMatrix;
    transMatrix.setTranslate(0.f, 0.f, -0.03f);
    transPtr->setMatrix(transMatrix);
    transNodePtr->setCore(transPtr);
    transNodePtr->addChild(textNode);

    OSG::ImageUnrecPtr imagePtr = face->getTexture();
    OSG::TextureObjChunkUnrecPtr texObjChunk =
OSG::TextureObjChunk::create();
    texObjChunk->setImage(imagePtr);
    texObjChunk->setWrapS(GL_CLAMP);
    texObjChunk->setWrapT(GL_CLAMP);
    texObjChunk->setMagFilter(GL_NEAREST);
    texObjChunk->setMinFilter(GL_NEAREST);
    OSG::TextureEnvChunkUnrecPtr texEnvChunk =
OSG::TextureEnvChunk::create();
    texEnvChunk->setEnvMode(GL_MODULATE);

    OSG::MaterialChunkUnrecPtr matChunk = OSG::MaterialChunk::create();
    matChunk->setAmbient(OSG::Color4f(1.f, 1.f, 1.f, 1.f));
    matChunk->setDiffuse(OSG::Color4f(1.f, 1.f, 1.f, 1.f));
    matChunk->setEmission(OSG::Color4f(0.f, 0.f, 0.f, 1.f));
    matChunk->setSpecular(OSG::Color4f(0.f, 0.f, 0.f, 1.f));
    matChunk->setShininess(0);

    OSG::BlendChunkUnrecPtr blendChunk = OSG::BlendChunk::create();
    blendChunk->setSrcFactor(GL_SRC_ALPHA);
    blendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

    OSG::ChunkMaterialUnrecPtr m = OSG::ChunkMaterial::create();
    m->addChunk(texObjChunk);
    m->addChunk(texEnvChunk);
    m->addChunk(matChunk);
    m->addChunk(blendChunk);
    geo->setMaterial(m);

    scene->addChild(transNodePtr);

    mgr->showAll();
    glutPostRedisplay();
}

// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    OSG::osgInit(argc,argv);

// Create GLUT window
    int winid = setupGLUT(&argc, argv);
    OSG::GLUTWindowUnrecPtr gwin= OSG::GLUTWindow::create();
    gwin->setGlutId(winid);
    gwin->init();

    lines.push_back("Hello World!");
    lines.push_back("Powered by OpenSG");
    lines.push_back("3rd line");

    // put the geometry core into a node
    scene = OSG::Node::create();
    scene->setCore(OSG::Group::create());

    // create the SimpleSceneManager helper
    mgr = new OSG::SimpleSceneManager;
    mgr->setWindow(gwin );
    mgr->setRoot  (scene);

    // Create the background
    OSG::SolidBackgroundUnrecPtr bg = OSG::SolidBackground::create();
    bg->setColor(OSG::Color3f(0.1f, 0.1f, 0.5f));
gwin->getPort(0)->setBackground(bg);

// Try to create new face
OSG::TextTXFParam textTXFParam;
textTXFParam.size = 48;
textTXFParam.gap = 1;
textTXFParam.textureWidth = 0;
face = OSG::TextTXFFace::create("SANS", OSG::TextFace::STYLE_PLAIN,
textTXFParam);
if (face == 0)
return 1;

// create the scene
    createScene();
startingTime = (__int64)GetTickCount();

    // GLUT main loop
    glutMainLoop();

    return 0;
}

void display( void )
{
__int64 now = (__int64)GetTickCount();
if(now - startingTime > 1000) // update the text randomly once per second
{
// generate up to 9 lines of up to 9 characters from 33 '!' to 122 'z'
lines.clear();
int nLines = (int)(OSG::osgRand()*10.f);
for(int i=0; i<nLines; i++)
{
char str[10];
int nChars = (int)(OSG::osgRand()*10.f);
int j;
for(j=0; j<nChars; j++)
str[j] = (int)(OSG::osgRand()*90.f+32.f);
str[j] = '\0';
lines.push_back(string(str));
}

// update the geometry with the new text lines
face->layout(lines, layoutParam, layoutResult);
face->fillGeo(geo, layoutResult, 2.f);
startingTime = now;
}
    mgr->redraw();
}

void reshape(int w, int h)
{
    mgr->resize(w, h);
    glutPostRedisplay();
}

void mouse(int button, int state, int x, int y)
{
    if (state)
        mgr->mouseButtonRelease(button, x, y);
    else
        mgr->mouseButtonPress(button, x, y);
    glutPostRedisplay();
}

// react to mouse motions with pressed buttons
void motion(int x, int y)
{
    mgr->mouseMove(x, y);
    glutPostRedisplay();
}

// react to keys
void keyboard(unsigned char k, int x, int y)
{
    switch(k)
    {
        case 27:
        {
            delete mgr;
            face   = NULL;
            scene  = NULL;
            OSG::osgExit();
            exit(0);
        }
        break;
    }
}

int setupGLUT(int *argc, char *argv[])
{
    glutInit(argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    int winid = glutCreateWindow("OpenSG");
    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
glutIdleFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutKeyboardFunc(keyboard);
    return winid;
}
---------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to