When SDL is used with OpenGL, the UV coordinates of OpenGL textures are reversed up and down.

Source: Internet
Author: User

Write by nine days Yan Ling (jtianling) -- blog.csdn.net/vagrxie

Discuss newsgroups and documents

Same paragraphProgramIn SDL with OpenGL, it is correct when glfw is used and Windows API is used to add OpenGL.
As follows:
Glbegin (gl_quads );
Gltexcoord2f (0.0, 0.0); glvertex3f (-1.0,-1.0, 0.0 );
Gltexcoord2f (1.0, 0.0); glvertex3f (1.0,-1.0, 0.0 );
Gltexcoord2f (1.0, 1.0); glvertex3f (1.0, 1.0, 0.0 );
Gltexcoord2f (0.0, 1.0); glvertex3f (-1.0, 1.0, 0.0 );
Glend ();

By default, the origin of the UV coordinate of the texture is in the lower left corner, which is in the upper left corner by default in SDL. Therefore, you need to reverse the coordinate Y axis of the texture above, this shows that there is no problem. As shown below:
Glbegin (gl_quads );
Gltexcoord2f (0.0, 1.0); glvertex3f (-1.0,-1.0, 0.0 );
Gltexcoord2f (1.0, 1.0); glvertex3f (1.0,-1.0, 0.0 );
Gltexcoord2f (1.0, 0.0); glvertex3f (1.0, 1.0, 0.0 );
Gltexcoord2f (0.0, 0.0); glvertex3f (-1.0, 1.0, 0.0 );
Glend ();

 

OriginalArticleThe author retains the copyright reprinted. Please indicate the original author and give a link

Write by nine days Yan Ling (jtianling) -- blog.csdn.net/vagrxie

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.