sorry, I don't understand good but how copy it on the stack; thanks
sorry, I don't understand good but how copy it on the stack; thanks
Regards
If you have something like:Originally Posted by mickey
then each time you invoke initializeGL() you will loose the previous value of _textureId member variable.Qt Code:
void GlWidget::initializeGL() { ... _textureId = generateTexture(); ... }To copy to clipboard, switch view to plain text mode
You can avoid that like this:
Qt Code:
void GlWidget::renderPixmap(...) { int oldTextureId = _textureId; _textureId = oldTextureId; return result; }To copy to clipboard, switch view to plain text mode
sorry but I can't understand what's the textureID; but after I call genPixmap (now I put It inside myWidget class and don't change everythings), I call updateGL(),and everythings appear as before; then I think my way to put texture is ok.; i think is only a context problem....could you explain better what do you want to do with saving this texture ids?? thanks
Regards
Could you post your initializeGL()? I might not remember your program well.Originally Posted by mickey
take it. thanks
Regards
What does plain.initGL() do?
it initialize every textures....gen tex, bind....plain it's an object and onto this I put the texture...
Regards
That's the place where the problem is. Can I see it?Originally Posted by mickey
it's very complicated. Can I mail it you? thanks
Regards
Yes, you can.Originally Posted by mickey
Here's the problematic part:Every time you invoke Plain::initGL() new textures are generated. The images are stored inside OpenGL context (represented by QGLContex) and your program receives only ID numbers of those textures (that's what you store in tex and lastTex).Qt Code:
void Plain::initGL() { ... glGenTextures(dimX*dimZ, tex); glGenTextures(1, &lastTex); ... glBindTexture(GL_TEXTURE_2D, lastTex ); ... glBindTexture(GL_TEXTURE_2D, tex[contite]); ... }To copy to clipboard, switch view to plain text mode
Now if you invoke initGL() for the second time (within the same context), tex and lastTex will be filled with new values --- the old textures will be still in memory, but you won't be able to access them, since those variables will hold IDs of the new textures. It's not a big problem (except for the resource leak).
But what happens when you invoke initGL() within a different context (just like it happens during renderPixmap())? initGL() will generate new textures, that will be stored in a new context, and it will store their IDs in tex and lastTex (the same ones, since you have only one Plain object). Now when renderPixmap() ends, it destroys that temporary context and the new textures are destroyed too, but tex and lastTex still hold their IDs. The problem is that when you will try to draw something later, you will use invalid texture IDs.
You can solve this problem like this:Qt Code:
void GlWidget::renderPixmap(...) { plain.store(); plain.restore(); return result; } ... void Plain::store() { // copy tex and lastTex values somewhere // for example onto QValueStack } void Plain::restore() { // restore tex and lastTex values }To copy to clipboard, switch view to plain text mode
Last edited by jacek; 14th July 2006 at 15:31.
mickey (21st July 2006)
I'm thinking to your solution...and other troubles arise: is there a way to clean the contextGL? (in the same way when app started)
then, I see that renderPixmap render my scene ok but don't render right texture multitextured; is it right? thanks
Regards
Bookmarks