Jump to content
  • Advertisement
Sign in to follow this  
Decrius

Draw part of a texture

This topic is 3900 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have a texture of 20x40, but in certain cases I only want to draw the top part: 20x20. I've tried to do this with glTexCoord2f(), but this seems to smooth the texture. Can I somehow accomplish this without the smoothing? So just that part of the texture and no more... Thank you. Decrius

Share this post


Link to post
Share on other sites
Advertisement
Yes glTexCoord2f is the correct way to go. As for changing the smoothing, take a look at texture filters and glTexParameteri.

Share this post


Link to post
Share on other sites
I'm not sure I understand the problem. If you want to render only the top part of the texture (assuming you're mapping the texture to a quad), your texture coordiantes should be in the range [0,0.5] - [1,1].

If your problem is that doing this seems to stretch the top half of the texture across a 20x40 quad, well, you need to make your quad smaller. :-)

Cheers,
--Brian

Share this post


Link to post
Share on other sites
Alright, this is what I use:

glBindTexture(GL_TEXTURE_2D, filemanager.get_texture(0, 2));
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(((window.w - 220)/2), ((window.h - 20)/2));
glTexCoord2f(1, 0); glVertex2i(((window.w - 60)/2), ((window.h - 20)/2));
glTexCoord2f(1, (40/236)); glVertex2i(((window.w - 60)/2), ((window.h + 20)/2));
glTexCoord2f(0, (40/236)); glVertex2i(((window.w - 220)/2), ((window.h + 20)/2));
glEnd();


The texture is 236 pixels high, and it should only display the top 40 pixels.

These are the parameters I use:
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glGenTextures(1, &textures[i_min + i]);
glBindTexture(GL_TEXTURE_2D, textures[i_min + i]);

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

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->getWidth(), image->getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image->getPixels());


Thanks.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!