I'm new to OpenGL, and am having a curious problem with my textures - looking for a nudge in the right direction.
I have an app which uses a Render to texture technique for accomplishing a certain effect - it's working marvelously. I draw to an offscreen buffer every time I need to, and am able to use this as a texture in my render loop.
This texture is only updated when necessary - it's drawn to the screen as is most frames.
I have some toolbars which are also drawn using OpenGL, on top of this surface using a texture atlas, and using blending.
I have recently begun trying to incorporate a particle system into the app, but whenever I try to render my particle system graphics, I "lose" my texture that I've rendered in the first step - ie it's contents disappear.
I have traced this to the call to glBindTexture that binds the texture of the particles.
EDIT: I can reproduce this in my simple toolbar drawing routine, code below. This is a crude routine that animates toolbar graphics on and off screen.
When I uncomment the first two lines in drawToolBar(), my rendered in memory texture disappears, ie the drawarrays call in my render loop renders nothing to the screen. Through testing, I have determined that the glBidTexture call is what triggers this. (For example, I can render colored quads over my texture, just not textured ones)
However, everything is fine if I allow drawToolbar() to run as below - the only difference is that the eventual call to drawTools() is wrapped in glPush/Pop, and is translated.
Note that the toolbar rendering always works - there is some unintended side effect, consequence, or bug issue going on here, which causes my background texture to disappear.
Any ideas are welcome - this is driving me nuts.
The code:
void drawTools()
{
//*Texture Coordinate Stuff Snipped*//
glBindTexture(GL_TEXTURE_2D, _buttontexture);
glEnable(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer (2, GL_FLOAT, 0,bottomToolQuads);
glTexCoordPointer(2, GL_FLOAT, 0,texc);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 4, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 8, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 12, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 16, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 20, 4);
glDisable(GL_TEXTURE_2D);
}
void drawToolBar()
{
//drawTools();
//return;
if(_toolbarState ==0)
{
drawTools();
}
else if(_toolbarState == 2)//hiding
{
_toolbarVisiblePct -= TOOLINC;
if(_toolbarVisiblePct <= 0.0)
{
_toolbarState = 1;
_toolbarVisiblePct = 0.0;
}
else
{
glPushMatrix();
glTranslatef(0.0, -(1-_toolbarVisiblePct) * 50, 0);
drawTools();
glPopMatrix();
}
}
else if(_toolbarState == 3) //showing
{
_toolbarVisiblePct += TOOLINC;
if(_toolbarVisiblePct >= 1.0)
{
_toolbarState = 0;
_toolbarVisiblePct = 1.0;
drawTools();
}
else
{
glPushMatrix();
glTranslatef(0.0, -(1-_toolbarVisiblePct) * 50, 0);
drawTools();
glPopMatrix();
}
}
}