Sign in to follow this  
TheShadow344

OpenGL problem

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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();

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
The LoadTexture() function is a near-exact copy of the one found here. Here is a copy so that you don't have to search for it on the page...


GLuint LoadTexture(char *TexName)
{
TGAImg Img;
GLuint Texture;

// Load our Texture
if(Img.Load(TexName)!=IMG_OK) { return(0); }

// Allocate memory for texture
glGenTextures(1,&Texture);
glBindTexture(GL_TEXTURE_2D,Texture);

// Create the texture
if(Img.GetBPP()==24)
{
glTexImage2D(GL_TEXTURE_2D,0,3,Img.GetWidth(),Img.GetHeight(),0,GL_RGB,GL_UNSIGNED_BYTE,
Img.GetImg());
}
else if(Img.GetBPP()==32)
{
glTexImage2D(GL_TEXTURE_2D,0,4,Img.GetWidth(),Img.GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,
Img.GetImg());
}
else
{
return(0);
}

// Specify filtering and edge actions
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);

return(Texture);
}



I only changed the formatting and I changed the "return -1;" statements to "return(0);", but it still functions the same.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this