hi to everybody!

i'm trying to use a texture with a custom mipmap image, i.e. i want to choose by
hand a different image for each mipmap level of detail.

I found out that OpenSG has a reader for DDS format, which seems to support its
custom mipmap contents. The problem is that, unless OpenSG apparently
recognizes and loads the mipmap levels stored into the DDS file, they're not
displayed correctly (i can see only the first one).

here's a little test program showing this behaviour... am i forgetting something
important? is it an expected behaviour? is it a bug?

my DDS test image is here:
http://tina.polito.it/~macete/test.zip

thanks for your time

Francesco Tamagni

ps: the dds image in the zip archive contains 3 levels, 512x512 is red, 256x256
is green, 128x128 is blue

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
#include <string>
#include <vector>
#include <iostream>

#include <OpenSG/OSGGLUT.h>
#include <OpenSG/OSGGLUTWindow.h>
#include <OpenSG/OSGGLUTWindowBase.h>
#include <OpenSG/OSGConfig.h>
#include <OpenSG/OSGSimpleGeometry.h>
#include <OpenSG/OSGGLUTWindow.h>
#include <OpenSG/OSGSimpleSceneManager.h>
#include <OpenSG/OSGBaseFunctions.h>
#include <OpenSG/OSGTransform.h>
#include <OpenSG/OSGMatrixUtility.h>
#include <OpenSG/OSGMatrixCamera.h>
#include <OpenSG/OSGSceneFileHandler.h>

#include <OpenSG/OSGGLEXT.h>
#include <OpenSG/OSGImage.h>
#include <OpenSG/OSGTextureChunk.h>
#include <OpenSG/OSGTextureBackground.h>
#include <OpenSG/OSGChunkMaterial.h>


// Activate the OpenSG namespace
OSG_USING_NAMESPACE

// The pointer to the transformation
TransformPtr modelTrans;
NodePtr modelNode;

// The pointer to the dynamic image and the texture
ImagePtr        image;
TextureChunkPtr tex;

// The SimpleSceneManager to manage simple applications
SimpleSceneManager *mgr;

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

NodePtr rootScene;

void display( void )
{
    // redraw the screen
    mgr->redraw();
}

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

    // GLUT init
    int winid = setupGLUT(&argc, argv);

    // the connection between GLUT and OpenSG
    GLUTWindowPtr gwin= GLUTWindow::create();
    gwin->setId(winid);
        gwin->init();

    // To check OpenGL extensions, the Window needs to have run through
    // frameInit at least once. This automatically happens when rendering,
    // but we don't don't to wait for that here.
    gwin->activate();
    gwin->frameInit();
    
    // Ok, now for the meat of the code...
    // first we need an Image to hold the picture(s) to show
    image = Image::create();
    
   if ( !image->read("test.dds") )
   {
       exit(0);
   }
   else
   {
       printf("Image loaded with success.\n");
       printf("%d mipmap levels found.\n", image->getMipMapCount());
   }

    // Now create the texture to be used for the background
    tex = TextureChunk::create();
    
    beginEditCP(tex);
    {
        // Associate image and texture
        tex->setImage(image);
        // Set filtering modes. LINEAR is cheap and good if the image size
        // changes very little (i.e. the window is about the same size as 
        // the images).
        tex->setMinFilter(GL_LINEAR_MIPMAP_LINEAR);
        tex->setMagFilter(GL_LINEAR);        
        
    }
    endEditCP(tex);
    
        TransformPtr trans;
    trans = Transform::create();

        rootScene = Node::create();

    modelNode = makeBox(5.0f, 5.0f, 5.0f, 1, 1, 1);

    ChunkMaterialPtr ckMat = ChunkMaterial::create();

    beginEditCP(ckMat, ChunkMaterial::ChunksFieldMask);
        ckMat->addChunk(tex);
    endEditCP(ckMat, ChunkMaterial::ChunksFieldMask);

    GeometryPtr geo = GeometryPtr::dcast(modelNode->getCore());
    beginEditCP(geo, Geometry::MaterialFieldMask);
        geo->setMaterial(ckMat);
    endEditCP(geo, Geometry::MaterialFieldMask);

    beginEditCP(rootScene, Node::CoreFieldMask | Node::ChildrenFieldMask);
    {
                rootScene->setCore(trans);
        rootScene->addChild(modelNode);
    }
    endEditCP  (rootScene, Node::CoreFieldMask | Node::ChildrenFieldMask);

    // create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // tell the manager what to manage
    mgr->setWindow(gwin);
    mgr->setRoot  (rootScene);

    // GLUT main loop
    glutMainLoop();

    return 0;
}


//
// GLUT callback functions
//

// react to size changes
void reshape(int w, int h)
{
    mgr->resize(w, h);
    glutPostRedisplay();
}

// react to mouse button presses
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();
}



// setup the GLUT library which handles the windows for us
int setupGLUT(int *argc, char *argv[])
{
    glutInit(argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    glutInitWindowSize( 640, 480 );

    int winid = glutCreateWindow("OpenSG");
    
    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutKeyboardFunc(NULL);
        
    // call the redraw function whenever there's nothing else to do
    glutIdleFunc(display);

    return winid;
}
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to