Jump to content
  • Advertisement
Sign in to follow this  
sadrius

OpenGL Drawing Subregions of Textures?

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

I apologize if this question is too remedial or is easily answered through some amazing website, but I checked google and haven't come up with anything. I'm trying to figure out how to bind a subregion of a texture and then use it to texture a quad. I'm working on a tilemap in OpenGL, and rather than have a texture object for each tile, I'd like to have a texture object for my tileset. When I have to draw an individual tile then, I'd calculate the tile's offset into the tileset and then bind the appropriate tile_size*tile_size chunk to a similarly sized quad. I'm certain there has to be an OpenGL or GLU function that can achieve this. I took a look at glTexSubImage2D, but it doesn't take a texture object pointer--it takes raw pixel data. So my question is: how would I go about doing this? Also, if I'm stuck using glTexSubImage2D, is there a way to retrieve raw pixel data from a texture object pointer? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
If you want to use a subregion of a texture for a quad, you can try modifying
the texture coordinates of the quad to reflect the portion of the texture you
want.

Share this post


Link to post
Share on other sites
Quote:
Original post by AcePilot
If you want to use a subregion of a texture for a quad, you can try modifying
the texture coordinates of the quad to reflect the portion of the texture you
want.


I've tried that, but all it seems to do is either scale the entire texture or cause it to repeat on the quad.

Unless I'm missing something?

Share this post


Link to post
Share on other sites
AcePilot is correct just use different texture coords
eg (0,0) (0.25,0) (0.25,0.25) (0,0.25) will use the bottom left 1/16 of a texture

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!