Jump to content
  • Advertisement
Sign in to follow this  

Accessing a part of a texture

This topic is 4078 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

Hey everyone, Hope you can help me out with this one. I load an image to a texture. I want to do this CPU to GPU transfer only once! I want to select process parts of this texture many times by copying it into a smaller textures .For eg if my orginal image was 256 X 256, I want to access 4 X 4 subtextures. The only thing I found was glTexSubImage2D. This is useless to me, since it needs pixels from the CPU. As i said I want to do only one transfer, and then access only parts of this large texture. I checked out this thread also. http://www.gamedev.net/community/forums/topic.asp?topic_id=325623 But then I dont think it solves my problem. Thanks in advance, Dhananjay

Share this post


Link to post
Share on other sites
Advertisement
You generally do this with texture coordinates. Look into glTexCoord2f. It takes values in the range [0.0, 1.0]. This is a value you set per vertex, so if you wanted to show just a quarter of an image on a quad, you might do something like this:


glBegin(GL_QUADS);
glTexCoord2f(0.5f, 0.0f); glVertex3f( 1.0f, -1.0f, 0.0f );
glTexCoord2f(0.5f, 0.5f); glVertex3f( 1.0f, 1.0f, 0.0f );
glTexCoord2f(0.0f, 0.5f); glVertex3f( -1.0f, 1.0f, 0.0f );
glTexCoord2f(0.0f, 0.0f); glVertex3f( -1.0f, -1.0f, 0.0f );
glEnd();


This will draw a quad on the screen and map the lower left 1/4 of the texture onto the quad.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!