Tag Archives: Visual Studio MFC programming

OpenGL learning notes: Problems and Solutions

This article records the problems and solutions encountered by the author when using OpenGL based on Visual Studio MFC.
directory
Add OpenGL form for dialog-based projects in VC++ MFC
Problem: Unable to open included file: “gl\glaux.h”
The glLodIdentity () function is relevant: OpenGL uses glLodIdentity () multiple times before the graph is displayed
Perspective setting related: GluLookAt and GluPerspective function parsing
Why call glPushMatrix and glPopMatrix
How does OpenGL set the coordinate system
Fatal error C1189: #error: gl.h included before glew.h
Problem: Solve VS “Could not start this program because OpenGL is missing from computer” in OpenGL programming
Rotation calculation of a rigid body in three dimensions
Several ways to draw cubes with OpenGL
How to draw cone/cylinder/sphere/sector/ring with OpenGL


 
Add OpenGL form for dialog-based projects in VC++ MFC
Reference Website:
https://www.cnblogs.com/wiener-zyj/p/4159310.html
Note: For actual debugging, “step one” in this URL is replaced by “include” in stdafx.h of the project:
#include< gl\gl.h>// OpenGL basic library
#include< gl\glu.h>// OpenGL utility library
#include< gl\glaux.h>// auxiliary OpenGL library

(↑ to replace the “step one”)
Problem: Unable to open included file: “gl\glaux.h”
Please refer to the following websites:
http://blog.csdn.net/mydangdang2/article/details/47361133
and
http://download.csdn.net/download/wyq1153/9646632
↑ (The second site is for downloading files from gl\glaux. H)
The glLodIdentity () function is relevant: OpenGL uses glLodIdentity () multiple times before the graph is displayed
Reference Website:
http://blog.sina.com.cn/s/blog_15bb06c270102ydsl.html
→ Site highlights:
Read a paragraph about glLoadIdentity() introduction, suddenly realize. GlLodIdentity () restores both the model world coordinates and the field of view to (0,0,0), with an orientation of -z and an upward orientation. OK, use glLoIdentity () and add a gluLookAt(), and you’ll be fine.
Perspective setting related: GluLookAt and GluPerspective function parsing
Reference Website:
https://www.2cto.com/kf/201611/565522.html
→ Site highlights:
Before calling the GluLookAt and GluPerspective functions, the glLoadidentity function is usually called (see code 20171117YC below).
// Set view and direction
glMatrixMode (GL_PROJECTION);
glLoadIdentity (); // Initialize the matrix (this line of code is necessary for setting viewpoints and viewing angles).   
GluPerspective (60.0, 1, 4, 10.0);//.
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); // Initialize the matrix (this line of code is necessary for setting viewpoints and viewing angles).
GluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);//.
 
OpenGL — GluLookat function for details:
http://blog.csdn.net/ivan_ljf/article/details/8764737
 
Why call glPushMatrix and glPopMatrix
Reference Website:
https://zhidao.baidu.com/question/1797166351991328427.html
How does OpenGL set the coordinate system
https://zhidao.baidu.com/question/169062940.html
→ X goes to the right, Y goes up, and Z goes out. This is the coordinate system you see. It does not change, but it can control the translation, rotation, and zoom in and out of the internal coordinate system through transfer, rotate, and scale, which can be understood as the change of coordinate system or the change of lens
 
GlRotated (90.0, 1.0, 0.0, 0.0); // Rotate 90 about x clockwise, Z vertical
GlRotated (45.0, 0.0, 0.0, 1.0); // The XY plane is 45 clockwise around Z.
GlRotated (45.0, 1.0, 1.0, 0.0); // rotate the Angle bisector 45 counterclockwise to see the effect
Fatal error C1189: #error: gl.h included before glew.h
Solutions:
The “# include< gl\gl.h>// OpenGL basic library “move to” # include “OpenGL_Interact/include/GL/glew. H”// “(to include. H file path) later.
Problem: Solve VS “Could not start this program because OpenGL is missing from computer” in OpenGL programming
This is mainly due to the reference to both the static libraries “Glut.lib” and “Glut32.lib”.
That is, in the project ->; Property – & gt; Configure properties ->; The linker – & gt; Glut.Lib and Glut32.Lib are added to the attached dependencies, and Glut.DLL comes first, glut32.DLL comes second, so the linker first looks for OpenGl32.DLL instead of OpenGL32.DLL.
→ After testing, removing Glut. DLL can solve the problem. 20171121YC
Rotation calculation of a rigid body in three dimensions

→ The above reference website:
http://blog.csdn.net/mulinb/article/details/51227597
Several ways to draw cubes with OpenGL
Refer to the website: https://www.cnblogs.com/brucemengbm/p/7281301.html
→20200414YC: The cube is drawn by drawing 6 faces.
How to draw cone/cylinder/sphere/sector/ring with OpenGL
Reference site 1:https://blog.csdn.net/biggbang/article/details/20552915
Reference site 2:https://www.cnblogs.com/foundkey/p/6024333.html