Sign in to follow this  
sadrius

OpenGL Drawing Subregions of Textures?

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
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

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