When compiling OpenGL functions, many inexplicable problems are caused by unfamiliar or profound understanding.
For example, after you have had a great deal of hard work and finally compiled D successfully, excute it! However, we can see what the cannot read memory is. Obviously, the pointer is out of bounds.
We are unwilling, but we cannot give up. Single-step debugging!
We found that there was a null pointer when using OpenGL to obtain some functions or strings!
For example, when glteximage3d = (pfnglteximage3dproc): wglgetprocaddress ("glteximage3d"), the trail finds that glteximage3d = NULL;
For example, if char * str1 = 0; str1 = (char *) glgetstring (gl_version);, the trace finds that str1 = NULL;
Haha, the problem is found. In this case, accessing glteximage3d or str1 will definitely be out of bounds.
But why? Clearly, the compilation is correct, and the execution can be performed normally, but the output is not correct?
I have been searching for the answer for a long time on the Internet: http://tech.groups.yahoo.com/group/opengl-gamedev-l/message/41013!
One sentence: Before you call these GL functions, You need to initialize the rendering context (rendering context )!!!
Therefore, when you are not using MFC (for example, when using a console Program), first call the relevant GL function to initialize the program and then call the relevant GL function to return the correct value.
In the case of MFC, after wglmakecurrent () is called for initialization, the correct value can be returned.
OK! Solve the problem!