简体   繁体   中英

In OpenGL 2.1, is it safe to use a 3D tex coord, even in 2d space (with a 2D texture)?

Can I use the 3D tex coord function for 2D textures by setting the Z value to 0 in OpenGL 2.1? Are there any 3D functions that I can not use for 2D? I can't use 2D functions because this is for a 2D/3D wrapper and it's too inefficient to try and guess if the user is inputting 2D or 3D coords when both functions could be used together.

This is going to sound funny, but all texture coordinates in OpenGL are always 4D. As are vertex positions.

To help explain this better, consider a deprecated function like glTexCoord2f (...) - it automatically assigns r = 0.0 and q = 1.0 . This behavior is extended to vertex arrays, if you have a texture coordinate pointer that only supply 2 components, GL automatically assigns 0.0 and 1.0 to the remaining 2 as illustrated above.

I would suggest you use the nomenclature strq when referring to texture coordinates, by the way. You can access them as xyzw in a shader, but the (fixed-function) pipeline is always documented as referring to them by strq .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM