x64 Debug BMP Image Import error solution in OpenGL

Source: Internet
Author: User
Tags bmp image

In the Win32 environment, the Glaux library has been provided, but for the x64 bit, basically the library does not provide 64 support. The following error will occur:

------Started Build: project: OpenGL, config: Debug x64------
1> OpenGL.cpp
1>opengl.cpp (746): Warning C4244: "return": Conversion from "WPARAM" to "int", possibly losing data
1>opengl.obj:error LNK2019: unresolved external symbol auxdibimageloada, the symbol in the function "struct _aux_rgbimagerec * __cdecl loadbmp (char *)" ([E Mail protected]@[email protected]@[email protected]) is referenced in
1>f:\opengl\x64\debug\opengl.exe:fatal error Lnk1120:1 an unresolved external command
========== Generation: Success 0, failure 1, latest 0, skip 0 ==========

The study of this afternoon did not make any significant discoveries; so simply wrote a function to load BMP, considering the compatibility of the upper and lower. Here I use the AUX_RGBIMAGEREC structure, in fact, is a structure, not willing to use the words can be rewritten, specifically as follows:

typedef struct _AUX_RGBIMAGEREC {
Glint Sizex, Sizey;
unsigned char *data;
} Aux_rgbimagerec;


Write your own BMP function as follows:

//custom load BMP file Aux_rgbimagerec * loadbmp (char *filename) { unsigned int Texture; Aux_rgbimagerec * Tex_result=new Aux_rgbimagerec; Be carefulfile* img = null;img = fopen (Filename, "R"); Glint bwidth = 0; Glint Bheight = 0;dword size = 0;fseek (img,, Seek_set) fread (&bwidth, 4, 1, IMG), Fread (&bheight, 4, 1, IMG); FSE Ek (img, 0, seek_end); size = Ftell (img)-54;unsigned char *data = (unsigned char*) malloc (size); Fseek (img, si, seek_set); Image Datafread (data, size, 1, img); fclose (IMG); glgentextures (1, &texture); Glbindtexture (gl_texture_2d, Texture); Glubuild2dmipmaps (gl_texture_2d, 3, Bwidth, Bheight, Gl_bgra, Gl_unsigned_byte, data); Gltexparameteri (GL_ texture_2d, Gl_texture_min_filter, gl_linear); Gltexparameteri (gl_texture_2d, Gl_texture_mag_filter, GL_LINEAR); Tex _result->sizex = Bwidth;tex_result->sizey = Bheight;tex_result->data = data;//if (data)//free (data); return Tex_result;}  
Here are a few places to be aware of:

(1) Pay attention to the pixel format, which is Gl_bgra, Gl_rgba, GL_RGB, etc., or the result of the resolution is not correct;

(2) Use this function to find out where you are using the image bit depth format: 32 or 24

x64 Debug BMP Image Import error solution in OpenGL

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.