These two days solved the texture problem.

xiaoxiao2021-03-05  23

The main code is as follows:

Gluint LoadBMP (CHAR * FNAME) / / Load BMP file and generates a texture, returns its ID {gluint tex; // texture identifier AUX_RGBIMAGEREC * IMG = 0; // Store the data structure of the image

/ * Define the size of the following typef struct _aux_rgbimagerec {glint sizex, size; // image in GLAUX.H, unsigned char * data; // pixel data} AUX_RGBIMAGEREC; * / IMG = AuxDibImageLoad (FNAME); // Tune BMP file IMG refers to the memory assert (IMG); // Success?

GLGENTEXTURES (/ / For texture allocation of memory 1, // How many texture? & tex); // assign its identity to TEX

GLBINDTEXTURE (// Set the current texture GL_TEXTURE_2D, / / ​​Is the two-dimensional texture or one-dimensional texture? TEX); // Which texture is used? GLTEXIMAGE2D (// Setting the pixel data for the current texture GL_TEXTURE_2D, / / ​​is a two-dimensional texture or one-dimensional texture? 0, // Texture Details 3, // Texture Each pixel contains several color components IMG-> SIZEX, // Image Width IMG-> Sizey, // Image of Height 0, // Texture boundary width (only 0 or 1) GL_RGB, // Image format GL_UNSIGNED_BYTE, // Image data Type IMG-> DATA); // Image of pixel array // if (img &&im-> data) free (img-> data); // Release IMG's memory // texture pixels have been called OpenGL / / Internal data structure, IMG / / no longer need to // if (img) free (IMG); return tex; // Return to generate textures}

转载请注明原文地址:https://www.9cbs.com/read-37263.html

New Post(0)