How does opengl display the texture-rich and opengl
In the opengl Post Bar, someone turns up a previous help post:
// According to the NeHe tutorial lesson6, we got a texture-based ry # include
// Use auxDIBImageLoad to load the texture # include
# Pragma comment (lib, "GLAUX. lib") # include
GLuint texture [1]; AUX_RGBImageRec * LoadBMP (char * Filename) // read a BMP image {FILE * File = NULL; // FILE handle if (! Filename) // ensure that the File name {return NULL; // If Not Return NULL} File = fopen (Filename, "r") is provided; // check whether the File exists if (File) // does the file exist? {Fclose (File); // Close The HandleWCHAR wstrFilename [MAX_PATH] = {0}; MultiByteToWideChar (CP_ACP, 0, Filename,-1, wstrFilename, sizeof (wstrFilename )); return auxDIBImageLoad (wstrFilename); // load the bitmap and return the pointer} return NULL; // If loading fails, return NULL} int LoadGLTextures () // load the bitmap and generate the texture {int Status = FALSE; AUX_RGBImageRec * TextureImage [1]; memset (TextureImage, 0, sizeof (void *) * 1 ); if (TextureImage [0] = LoadBMP ("Data/NeHe.bmp") {Status = TRUE; glGenTextures (1, & texture [0]); // create a texture // use the glBindTexture (GL_TEXTURE_2D, texture [0]), glTexImage2D (GL_TEXTURE_2D, 0, 3, TextureImage [0]-> sizeX, textureImage [0]-> sizeY, 0, GL_RGB, histogram, TextureImage [0]-> data); glTexParameteri (GL_TEXTURE_2D, cosine, GL_LINEAR); // Linear Filter glTexParameteri (Cosine, cosine, GL_TEXTURE_MAG_FILTER, GL_LINEAR);} // Linear Filter if (TextureImage [0]) // check whether the texture exists {if (TextureImage [0]-> data) // check whether the texture image exists {free (TextureImage [0]-> data); // release the memory occupied by the texture image} free (TextureImage [0]); // release image structure} return Status; // return success Status} void init (void) // initialize {glable (GL_TEXTURE_2D); glClearColor (0.0, 0.0, 0.0, 0.0 ); glMatrixMode (GL_PROJECTION); glOrtho (0.0, 200.0, 200.0, 200.0, 0.0); glable (GL_DEPTH_TEST); glClearDepth (1.0f); LoadGLTextures ();} float angel2 = 200.0; // Rotation Angle void display (GLvoid) {// display glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); glTranslatef (0.5, 0.0, 0.0 ); glRotatef (angel2, 1.0, 1.0, 1.0); // rotate glBindTexture (GL_TEXTURE_2D, texture [0]); glBegin (GL_QUADS); glTexCoord2f (0.0f, 0.0f) by angle ); glVertex3f (-0.2f,-0.2f, 0.2f); // The bottom left glTexCoord2f (1.0f, 0.0f) of the texture and quadrilateral; glVertex3f (0.2f,-0.2f, 0.2f ); // texture and glTexCoord2f (1.0f, 1.0f) in the lower right of the quadrilateral; glVertex3f (0.2f, 0.2f, 0.2f); // texture and glTexCoord2f (0.0f, 1.0f) in the upper right of the quadrilateral ); glVertex3f (-0.2f, 0.2f, 0.2f); // the top left of the texture and quadrilateral // glTexCoord2f (1.0f, 0.0f); glVertex3f (-0.2f,-0.2f,-0.2f ); // glTexCoord2f (1.0f, 1.0f), glVertex3f (-0.2f, 0.2f,-0.2f), and glTexCoord2f (0.0f, 1.0f) on the right of the texture and quadrilateral ); glVertex3f (0.2f, 0.2f,-0.2f); // the upper left glTexCoord2f (0.0f, 0.0f) of the texture and quadrilateral; glVertex3f (0.2f,-0.2f,-0.2f,-0.2f ); // texture and left bottom of the Quadrilateral // top glTexCoord2f (0.0f, 1.0f); glVertex3f (-0.2f, 0.2f,-0.2f); // texture and top left glTexCoord2f (0.0f, 0.0f); glVertex3f (-0.2f, 0.2f, 0.2f); // The bottom left glTexCoord2f (1.0f, 0.0f) of the texture and quadrilateral; glVertex3f (0.2f, 0.2f, 0.2f ); // glTexCoord2f (1.0f, 1.0f), glVertex3f (0.2f, 0.2f,-0.2f), and glTexCoord2f (1.0f, 1.0f, 1.0f); glVertex3f (-0.2f,-0.2f,-0.2f); // the top right glTexCoord2f (0.0f, 1.0f) of the texture and quadrilateral; glVertex3f (0.2f,-0.2f,-0.2f ); // The top left glTexCoord2f (0.0f, 0.0f) of the texture and quadrilateral; glVertex3f (0.2f,-0.2f, 0.2f); // The bottom left glTexCoord2f (1.0f, 0.0f) of the texture and quadrilateral ); glVertex3f (-0.2f,-0.2f, 0.2f); // the bottom right of the texture and quadrilateral. // glTexCoord2f (1.0f, 0.0f); glVertex3f (0.2f,-0.2f,-0.2f ); // texture and glTexCoord2f (1.0f, 1.0f) in the lower right of the quadrilateral; glVertex3f (0.2f, 0.2f,-0.2f); // texture and glTexCoord2f (0.0f, 1.0f) in the upper right of the quadrilateral ); glVertex3f (0.2f, 0.2f, 0.2f); // the top left glTexCoord2f (0.0f, 0.0f) of the texture and quadrilateral; glVertex3f (0.2f,-0.2f, 0.2f ); // texture and left bottom of the Quadrilateral // glTexCoord2f (0.0f, 0.0f); glVertex3f (-0.2f,-0.2f,-0.2f); // texture and left bottom glTexCoord2f (1.0f, 1.0f, 0.0f); glVertex3f (-0.2f,-0.2f, 0.2f); // the bottom right glTexCoord2f (1.0f, 1.0f) of the texture and quadrilateral; glVertex3f (-0.2f, 0.2f, 0.2f ); // glTexCoord2f (0.0f, 1.0f); glVertex3f (-0.2f, 0.2f,-0.2f); // glEnd (); glFlush (); angel2 + = 0.015; // rotation angle step} void main (int argc, char ** argv) {LoadGLTextures (); gluinitwindowposition (100,100); gluinitwindowsize (500,500 ); glucreatewindow ("texture-rich "); init (); LoadGLTextures (); gludisplayfunc (display); glutIdleFunc (display); glumainloop ();}
Running diagram:
I remember a few examples of how to use opengl to display the 3DS model. Let's take a look at the following chapters and study 3D reconstruction later.