Thursday, 15 January 2015

OpenGL ES 2.0 Render to texture coordinate system -



OpenGL ES 2.0 Render to texture coordinate system -

i find if utilize glframebuffertexture2d render primitives texture in opengl es 2.0, coordinate scheme not same when rendering default framebuffer. e.g.: v0(-1,-1), think @ left bottom, if render texture, v0 @ right top. can tell me why?

(-1, -1) should not map top right. can appear top left, depending on how @ data.

in reality, (-1, -1) bottom left in default opengl coordinate system. reason can confusing because of way textures arranged in memory. stored bottom top, i.e. first row in memory bottom row. different image file formats, first row top row. root cause y-inversion issues.

a couple of scenarios can cause unexpected behavior:

you load image file format stores info top bottom, , utilize sampling. if want display image in original orientation, need utilize 1.0 v texture coordinate corresponding bottom vertices, , 0.0 top vertices, opposite direction utilize vertex coordinates. using 0.0 top texture coordinate set first row of texture @ top, matches order in memory.

you glreadpixels() default settings. rows of image in result ordered bottom top. if want save info image format stores info top bottom, need flip order of rows while writing out data.

you render texture using fbo, , utilize texture sampling. texture has rows arranged bottom top. v texture coordinates flipped compared used in illustration 1, texture info arranged top bottom.

opengl-es

No comments:

Post a Comment