The texture image is reversed.

Source: Internet
Author: User
Tags bmp image

In the afternoon, when I tried to use OpenGL to display the BMP image, I encountered a problem: the loaded BMP image was displayed in three dimensions. It was initially suspected that the texture coordinate was reversed. Check the correspondence between texture coordinates and vertex coordinates carefully, as shown in the following code. No error is found.

Glbindtexture (gl_texture_2d, texture); <br/> glbegin (gl_quads); <br/> glcolor3f (1, 1, 1); <br/> gltexcoord2f (0.0, 0.0 ); glvertex3f (-1000.0,-1000.0, 0.0); // the bottom left of the texture and quadrilateral <br/> gltexcoord2f (1.0, 0.0); glvertex3f (1000.0,-1000.0, 0.0 ); // texture and right bottom of the Quadrilateral <br/> gltexcoord2f (1.0, 1.0); glvertex3f (1000.0, 1000.0, 0.0 ); // texture and top right of the Quadrilateral <br/> gltexcoord2f (0.0, 1.0); glvertex3f (-1000.0, 1000.0, 0.0 ); // texture and top left of the Quadrilateral <br/> glend; <br/> 

 

We can only suspect that the BMP is loaded. I use a tbitmap class to load data from a BMP file, as shown below. It is also very simple and should not be faulty.

For I: = 0 downto obitmap. height-1 do <br/> begin <br/> P: = obitmap. scanline [I]; <br/> for J: = 0 to obitmap. width-1 do <br/> begin <br/> iimagedata [icount]: = byte (pchar (p) [3 * j + 2]); <br/> iimagedata [icount + 1]: = byte (pchar (p) [3 * j + 1]); <br/> iimagedata [icount + 2]: = byte (pchar (p) [3 * j]); <br/> Inc (icount, 3); <br/> end; <br/> 

Is the BMP storage method different from the data format required by glteximage2d. After searching through the Internet, the stored BMP is different from what we imagined. The record sequence is from left to right in the scanning row, and the scanning row is from bottom to top. Therefore, you only need to change the code above to for... downto.

For a detailed description of BMP format, see: http://blog.csdn.net/sjzlxd/archive/2009/02/22/3923907.aspx

 

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.