OpenGL entry functions

Source: Internet
Author: User
Glloadidentity ()// Reset the current model observation matrix call. After glloadidentity (), you actually move the current vertex to the center of the screen. Gltranslatef (x, y, z)// Move along the X, Y, and Z axes. Gltranslatef (-1.5f, 0.0f,-6.0f); // move 1.5 units to the left along the X axis, do not move the Y axis (0.0f), and finally move it to 6.0f units on the screen. When you move it using a function, you are not moving relative to the center of the screen, but relative to the current screen location. Polygon Painting Process: Glbegin (gl_triangles)It means starting to draw a triangle ...... The points between them are all set by three points, which is also applicable to the Quadrilateral Gl_quads. The first parameter of glvertex is X coordinate, followed by Y coordinate and zcoordinate. The first vertex is the upper vertex, then the lower left vertex and the lower right vertex. Glend ()Tells OpenGL that the triangle has been created. Color value:The color value ranges from 0.0f to 1.0f. 0.0f indicates the worst case, while 1.0f indicates the brightest case. The first parameter after glclearcolor is red intensity (Red weight), the second is green, and the third is blue. Glcolor3f (R, G, B ). The three parameters in brackets are red, green, and blue. Rotation Angle:Glfloat rtri; // defines the angle glfloat rquad for the triangle; // defines the angle glrotatef (angle, xvector, yvector, zvector) for the quadrilateral to rotate the object around a certain axis. Rtri + = 0.2f; // increase the rotation variable (speed) of the triangle. Place the variable rquad-= 0.15f in the angle parameter. // reduce the rotation variable of the Quadrilateral. Attach image:The width and height of the image must be the N power of 2; the minimum width and height must be 64 pixels; and for compatibility reasons, the width and height of the image should not exceed 256 pixels. If the width and height of your raw material are not 64,128,256 pixels, use the image processing software to re-resize the image. There is certainly a way to bypass these limitations, but now we only need to use standard texture sizes. Aux_rgbimagerec * loadbmp (char * filename) // Load bitmap image{File * file = NULL; // file handle if (! Filename) // make sure the file name has {return NULL;} // if not, return nullfile = fopen (filename, "R"); // try to open the file if (file) // does the file exist? {Fclose (File); // close the handle return auxdibimageload (filename); // load the bitmap and return the pointer} return NULL; // If loading fails, return NULL} int loadgltextures () // Load Bitmap ( Call the above Code) And convert to texture{Int status = false; // Status Indicator aux_rgbimagerec * textureimage [1]; // creates a texture storage space memset (textureimage, 0, sizeof (void *) * 1 ); // set the pointer to null // load the bitmap to check for any errors. If the bitmap is not found, exit if (textureimage [0] = loadbmp ("Data/nehe.bmp ")) {status = true; // set status to true glgentextures (1, & texture [0]); // create a texture // use the glbindtexture (gl_texture_2d, texture [0]) of the typical texture generated from the bitmap data; // generate the glteximage2d (gl_texture_2d, textureimage [0]-> sizex, textu Reimage [0]-> sizey, 0, gl_rgb, gl_unsigned_byte, textureimage [0]-> data); // The above line tells OpenGL that this texture is a 2D texture (gl_texture_2d ). The parameter "0" indicates the image details, which usually goes from zero. Parameter 3 is the score of the data. Because the image consists of three components: Red Data, green data, and blue data. Textureimage [0]-> sizex is the width of the texture. If you know the width, you can enter it here, but the computer can easily point this value for you. Textureimage [0]-> sizey is the texture height. Zero is the border value, which is generally "0 ". Gl_rgb tells OpenGL that image data is composed of three colors: Red, green, and blue. Gl_unsigned_byte means that the data that makes up the image is of the unsigned byte type. Finally... textureimage [0]-> data tells OpenGL the texture data source. In this example, point to the data stored in the textureimage [0] record. Gltexparameteri (gl_texture_2d, cosine, gl_linear); gltexparameteri (gl_texture_2d, gl_texture_mag_filter, gl_linear);} If (textureimage [0]) // whether the texture exists {If (textureimage [0]-> data) // whether the texture image exists {free (textureimage [0]-> data ); // release the memory occupied by the texture image} Free (textureimage [0]); // release the image structure} return status; // return status} The following figure shows the cubes used to draw textures (texture ing:The first parameter of gltexcoord2f is the X coordinate. 0.0f is the left side of the texture. 1.0f is the right side of the texture. The second parameter of gltexcoord2f is the Y coordinate. 0.0f is the bottom of the texture. 1.0f is the top of the texture. General expression:Glbegin (gl_quads); // gltexcoord2f (0.0f, 0.0f); glvertex3f (-1.0f,-1.0f, 1.0f); // The Left Bottom gltexcoord2f (1.0f, 0.0f) of the texture and quadrilateral ); glvertex3f (1.0f,-1.0f, 1.0f); // the bottom right gltexcoord2f (1.0f, 1.0f) of the texture and quadrilateral; glvertex3f (1.0f, 1.0f, 1.0f ); // The top right gltexcoord2f (0.0f, 1.0f) of the texture and quadrilateral; glvertex3f (-1.0f, 1.0f, 1.0f); // the top left of the texture and quadrilateral ...... Glend (); Illumination:Glfloat lightambient [] = {0.5f, 0.5f, 0.5f, 1.0f}; // the ambient light parameter is a half-bright (0.5f) White ambient light. If there is no ambient light, the area where the light is not diffuse will become very dark. Glfloat lightdiffuse [] = {1.0f, 1.0f, 1.0f, 1.0f}; // parameters of diffuse light glfloat lightposition [] = {0.0f, 0.0f, 2.0f, 1.0f }; // set the light source position in int initgl (glvoid): gllightfv (gl_light1, gl_ambient, Lightambient); // Sets the environment light gllightfv (gl_light1, gl_diffuse, Lightdiffuse); // Sets the gllightfv (gl_light1, gl_position, Lightposition); // Set the position of the light source to gl_light1; // enable light source 1 Keyboard control:If (Keys ['l'] &! LP) // is the L key pressed and released? {Lp = true; // LP is set to truelight =! Light; // switch the true/falseif (! Light) // if no light source exists {gldisable (gl_lighting); // disable the light source} else // otherwise {gl_lighting); // enable the light source} If (! Keys ['l']) // is the L key released? {Lp = false; // If yes, set LP to false} If (Keys [vk_prior]) // Pageup is pressed? {Z-= 0.02f; // if pressed, move the wooden box to the inside of the screen} If (Keys [vk_prior]) // Pageup is pressed? {Z-= 0.02f; // move the wooden box to the inside of the screen if pressed} Hybrid (Blend ):Most people think that the Alpha component represents the transparency of the material. This means that when the Alpha value is 0.0, the material is completely transparent. When the Alpha value is 1.0, the material is completely opaque. Glcolor4f (1.0f, 1.0f, 1.0f, 0.5f); // full brightness, 50% Alpha mixture (gl_rgba) glblendfunc (gl_src_alpha, gl_one ); // a semi-transparent hybrid function based on the Alpha Channel value of the source Pixel

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.