c++ - X,Y Width,Height To OpenGL Texture Coord -


if got 256 x 256 texture, , image that's 32 x 32 @ x: 192 y: 128, algerithm used use gltexcoord2f draw 32 x 32 image @ x: 192 y: 128 (to cut out other parts of image)?

here example of want do. blue/red box i'd want use. want draw box, nothing surrounding it, or whole texture.

http://i.imgur.com/ltugfou.png

is want?

float f = 1.0f/256.0f; glbegin( gl_quads );     gltexcoord2f( 192 * f, 128  * f );     glvertex2f( 192, 128 );      gltexcoord2f( (192 + 32) * f, 128  * f );     glvertex2f( 192 + 32, 128 );      gltexcoord2f( (192 + 32) * f, (128 + 32) * f );     glvertex2f( 192 + 32, 128 + 32 );      gltexcoord2f( 192 * f, (128 + 32) * f );     glvertex2f( 192, 128 + 32 ); glend(); 

remeber texture coordinates scaled <0,1> interval. intermediate mode deprecated in opengl 3.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -