Sign in to follow this  
Rydinare

OpenGL Textured Cube Renders Slowly

Recommended Posts

Hi all. I made a class which encapsulates an OpenGL textured cube. What I'm noticing is that the rendering rates are fairly slow on my hardware (GeForce 7300 GS). I was thinking that it might be due to the size of my texture. The texture I'm using is 2150 x 1250. I remember reading something that it's always best to use power-of-2 textures. In addition, thinking about it, I don't think I need such a high resolution texture, but I do want to keep the shape the same. What's the best way to approach this problem? Thanks in advance.

Share this post


Link to post
Share on other sites
Why do you want to keep the shape? If you're mapping it onto a cube, then it's going to end up a square, anyway. So just use your favorite image editing software to change the image size to something more manageable, like 1024x512.

If you absolutely have to keep the relative sizes, resize the image to something smaller, then pad around the top and right edges to make the texture a power of two in either direction. Then, when applying the texture, use modified texture coordinates:
glTexCoord2f(1.0f, 1.0f);
becomes
glTexCoord2f(originalWidth / biggerPowerOfTwoWidth, originalHeight / biggerPowerOfTwoHeight);

I'd say just go with the first approach, though.

Share this post


Link to post
Share on other sites
You have a good point that the shape of the texture doesn't really matter, as the texture coordinates are going to determine how it gets mapped anyway. I do have one concern, though. It's going to scale it down to fit the object proportionally, based on those texture coordinates. How smooth is the scaling? Will it get blocky if I do this?

I did scale the image down with an image program and I did notice a significant speed gain, so the size of the texture may have been at least part of my performance issue.

I appreciate your input and assistance.

Thanks!

Share this post


Link to post
Share on other sites
Quote:
Original post by Rydinare
I do have one concern, though. It's going to scale it down to fit the object proportionally, based on those texture coordinates. How smooth is the scaling? Will it get blocky if I do this?

Quick answer: How does it look?

A little more: glTexParameter determines what happens when textures have to become bigger or smaller, in particular the GL_TEXTURE_MIN_FILTER and GL_TEXTURE_MAG_FILTER parameters. You could make it look blocky with a value of GL_NEAREST, but you'll probably want to use something like GL_LINEAR. If that still won't do for you, you'll want to look into mipmaps. Google has plenty of information on that topic, but post away if you have questions after giving it a go if you deem it worthwhile.

[Edit: The above is for when the texture itself is either too big or too small for what's being presented to the screen. I see now that you're asking about fitting the texture on a different-sized object. That's nothing to worry about, the texels will be interpolated as well as they can be for a given resolution. So, the higher your resolution, the better it will look, naturally, but any modern resolution will be more than adequate.]

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