PDA

View Full Version : Rendering part of a texture with GL_REPEAT or GL_CLAMP?



07-12-2006, 03:21 PM
Say I have a 64x64 Texture that contains pictures to be used in drawing GUI. Obviously to display smaller parts of that image for each part of the GUI I would have to REPEAT or CLAMP the texture (as stretching makes it look uglier), how would I do this if my glTexCoord2f coords are different than 0 and 1, and instead something like 0.013f, 0.127f?

Scottc
07-12-2006, 03:58 PM
Also I was wondering, is there any way to set it so the top left corner of a texture is 0,0, rather than the bottom left? Kinda like how you can change the coordinates to 0,0 to top left with
glOrtho(0, x, y, 0, near_clip, far_clip);

Bob
07-12-2006, 05:18 PM
You can't clamp/repeat a sub image of a texture. At least not without a shader.

As for flipping the image. Well, flip the image. Open it in a paint program and mirror it up side down. Now the origin is effectively in the other corner.

Scottc
07-12-2006, 05:50 PM
Originally posted by Bob:
You can't clamp/repeat a sub image of a texture. At least not without a shader.

As for flipping the image. Well, flip the image. Open it in a paint program and mirror it up side down. Now the origin is effectively in the other corner. I guess i'll have to learn to create shaders.

Flipping it upside down would cause some obvious issues, I mean having the texture coordinates be in the actual top left corner of the textured quad thats being displayed.

zeoverlord
07-12-2006, 06:14 PM
as a workaround you could subivide the quad and give the smaller quads the same texture coordinates as the big one.

Scottc
07-13-2006, 11:15 PM
Originally posted by zeoverlord:
as a workaround you could subivide the quad and give the smaller quads the same texture coordinates as the big one. You mean draw multiple quads with the same texture?

07-22-2006, 11:24 AM
I have no experience, but what about splitting the original texture up into multiple textures (through some form of render to texture) and then using 0,1 for coords and being able to clamp.

Or split the texture up outside of opengl and only pass the split textures so you dont have to deal with sub images.

Scottc
07-22-2006, 08:24 PM
Originally posted by <saluk>:
I have no experience, but what about splitting the original texture up into multiple textures (through some form of render to texture) and then using 0,1 for coords and being able to clamp.

Or split the texture up outside of opengl and only pass the split textures so you dont have to deal with sub images. Yes but theres teh whole power of 2 thing, I believe you can load a part of an image as a texture of its own anyway.