After the environment is configured successfully, run the sample code. You must find that the triangle is deformed as the window is stretched. The problem is solved below.
The Code is as follows:
# Include <Gl/glut. h> # include <Gl/Glu. h> # include <Gl/GL. h> # pragma comment (Lib, "opengl32.lib") # pragma comment (Lib, "glu32.lib") # pragma comment (Lib, "glu32.lib") # pragma comment (Lib, "glut. lib ") void renderscene (void) {glclear (gl_color_buffer_bit | callback); glbegin (gl_triangles); glvertex3f (0.0, 0.0, 0.0); glvertex3f (0.5, 0.0, 0.0 ); glvertex3f (0.0, 0.5, 0.0); glend (); glbegin (gl_quads); glvertex3 F (1.0, 1.0, 0.0); glvertex3f (2.0, 1.0, 0.0); glvertex3f (2.0, 0.0, 0.0); glvertex3f (1.0, 0.0, 0.0); glend (); gluswapbuffers ();} void changesize (int w, int h) {// prevent the divisor (that is, the height is 0) // (you can set the window width to 0 ). if (H = 0) H = 1; float ratio = 1.0 * W/H; // unitized projection matrix. Glmatrixmode (gl_projection); glloadidentity (); // you can specify the window size as glviewport (0, 0, W, h). // set the correct projection matrix gluperspective (45, ratio, 1, 1000); // The following is the set model view matrix glmatrixmode (gl_modelview); glloadidentity (); glulookat (0.0, 0.0, 5.0, 0.0, 0.0,-1.0, 0.0f, 1.0f, 0.0f); // set the observation point} int main (INT argc, char * argv []) {gluinit (& argc, argv ); fig ); // call the function glureshapefunc (changesize) when the specified program is idle; // specify the callback function glable (gl_depth_test) when the window shape changes; glumainloop (); Return 0 ;}
OpenGL path (2) setting the observation matrix and avoiding Drawing Deformation