OpenGL problem

Started by
10 comments, last by TheShadow344 18 years, 10 months ago
Anytime that I try to draw a image to cover the entire screen in my SDL / OpenGL game, it suffers a major frame rate drop. And anytime that I try to texture a polygon with an image, polygons that I coloured using glColor3ub() turn into a black box. I think it has something to do with my glTexParameteri() commands...

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);


Is there any way to fix these?
Advertisement
For your first question, how are you drawing the image? Are you creating the texture every frame (which would be a no no)? I can't see how it would slow dramatically otherwise without further information.

For your second, I don't see how those would affect that. Have you tried using:
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );

In any event, some code would certainly help with that as well.
Sorry, I should have clarified...

With creating the texture, I'm using a display list that is built when the game is first run (based on NeHe tutorial #12). I'm loading the textures (as TGA files) with the TGA loader from this site. The texture is mapped to the quad when the list is built.

Here is the code that loads the title background display list...

  // Build TitleBG  glNewList(TitleBG, GL_COMPILE);    // Allocate texture  GLuint BG_Graphic = LoadTexture("Resource/TGA/Title.tga");  glBindTexture(GL_TEXTURE_2D,BG_Graphic);    glBegin(GL_QUADS);    glColor3f(255, 255, 255);    glTexCoord2f(0, 0); glVertex3f(1, 1, 1);    glTexCoord2f(1, 0); glVertex3f(-1, 1, 1);    glTexCoord2f(1, 1); glVertex3f(-1, -1, 1);    glTexCoord2f(0, 1); glVertex3f(1, -1, 1);  glEnd();    // Delete texture  glDeleteTextures(1, &BG_Graphic);    glEndList();
I think you may not have a problem at all. Going from nothing to drawing one quad could get 100s i the difference in frame rate. If drawing nothing you get 500fps, you could go down to 100 fps drawing just ONE fullscreen quad. When the numbers are that high, they don't really represent very well, whereas going from 30 to 20 does mean something is going on. You never posted what the actual framerates were before and after, so I don't know if this is the case. But I have seen this type of problem in many other posts.


Perhaps the frame rate is not an issue. Thanks for the pointer.

Still, I can't draw a textured quad without my single-shaded quads turning black, and I have no idea what the problem is.
Actually, based on the code you posted, what Brandon N suggested is definitely your problem. You're causing OpenGL to allocate, fill, and destroy the texture every time you call your list. Move the calls to glTexImage2D and glDeleteTextures outside of your display list (to program initialization and shutdown, respectively) and see what happens.

As for your other issue, you're going to have to provide more details or post code.
I think your framerate drop can be explained by the location of your LoadTexture call - inside the display list. From what I see in the specs every command gets added to the display list, including your texture creation calls. As pointed out earlier, this is bad, so try moving the loadtexture to outside the display list.
I tried your suggestion, but if the texture loading is called outside of the list, it doesn't draw the texture at all...

I managed to get a noticeable frame rate increase by changing from 32-bit colour to 16-bit though.

[grin]
You'll also want to move the glDeleteTextures call to the end of your program ;)
What happens inside your LoadTexture function? You're still going to want to make sure that texturing is enabled when you call your list, and leave the call to glBindTexture in there. Also, the above poster is right, move glDeleteTextures out too [grin]

Trust me, this is the right thing to do.

This topic is closed to new replies.

Advertisement