PDA

View Full Version : glGenTextures withing glNewList() glEndList()



Uther_Pendragon
07-03-2002, 09:32 PM
Hi guys !


The code below compiles correct but it crashes on the Linux verion of my program.

Is it OK to generate the texture 'within' the displaylist compilation ?
Or is it better to do this OUTSIDE the display list compile and just bind the texture ?

Thx,

Uther

if ( glIsList(listid) == GL_TRUE )
glDeleteLists( listid, 1 );

listid = glGenLists(1);

glNewList( listid, GL_COMPILE_AND_EXECUTE );

/ // Now create a duplicate image with the new dimension
Itf_BasicImage<color> *l_pTempGLTex = createGlTexmap(getTexture(), newCols, newRows, scale);

glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );

// Generate texture
glGenTextures(1,&iTextureId[0]);

glBindTexture(GL_TEXTURE_2D, iTextureId[0]);

// Set texture parameters......
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

// Create OpenGL texture
glTexImage2D(GL_TEXTURE_2D, 0, 3,
newCols, newRows,
0, GL_RGB, GL_UNSIGNED_BYTE,
(char *)((((Itf_BasicImage<color> *)l_pTempGLTex)->getPixels()).begin()) );

//**
//** Draw code here

glEndList();

BlackJack
07-03-2002, 11:26 PM
Hm.... I already sometimes wrote crazy things in my code, but that's...... topping all http://www.opengl.org/discussion_boards/ubb/smile.gif.

Does "(char *)((((Itf_BasicImage<color> *)l_pTempGLTex)->getPixels()).begin())" reserve memory and results a pointer to it? If so, that's already the first possible reason for the crash. Displaylists don't call your C code, they just execute the same commands again with exactly the same parameters as given the time you called them, when compiling the list.
I guess your program crashes because the memory of any of the pointers you send to the API have already been made free again when you call the displaylist again. There are many ways to save performance, but.... that one is none http://www.opengl.org/discussion_boards/ubb/wink.gif.

This of your source you can store in a list if you like to:
// Set texture parameters......
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

But everything else... no way.

BlackJack

Uther_Pendragon
07-04-2002, 12:03 AM
Don't worry 'bout the getPixels() functions... it works quite fine http://www.opengl.org/discussion_boards/ubb/wink.gif

The prog does not crash on W32 and SGI but only on RH Linux...

Anyway...

So ideally I should generate
(glGenTextures()) the texture 'outside' the display list ?
And then only do the texture bind inside the display list...

What about glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); ?

thx,

Uther

Tom Nuydens
07-04-2002, 12:09 AM
BlackJack, the glGenTextures() call is actually the only thing in there that can't be stored in a display list. Check paragraph 5.4 of the spec (page 195) -- even glTexImage() is stored in the list as long as the target isn't one of the proxy textures.

However, pointers are dereferenced during display list compilation, so even if he deletes the texture data right after glEndList(), his display list should still work (it would contain a copy of the data).

-- Tom

Uther_Pendragon
07-04-2002, 12:46 AM
Ok, thx for all the info... I'm currently re-organizy my code to get my texture code out of the display list.

Thanks again.

Uther