Visual Studio 2008上的HelloWorld OpenGL程序中未处理的异常错误 [英] Unhandled exception error in HelloWorld OpenGL program on Visual Studio 2008

查看:85
本文介绍了Visual Studio 2008上的HelloWorld OpenGL程序中未处理的异常错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的opengl代码,它可能没有做任何有意义的事情.我在代码中使用了freeglut库.以下是所有代码:

Below is my opengl code, it might not do something meaningful. I used freeglut library in the code. Below is the all of the code:

#include <glload/gll.h>
#include <glload/gl_3_0.h>
#include <GL/glut.h>
#include "glfw3.h"

void ChangeSize(int w, int h)
{
    glViewport(0, 0, w, h);
}

void RenderScene(void)
{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    glLoadIdentity();
    glLineWidth(1);
    glColor3f(1.0f, 0.0f, 0.0f);

    glBegin(GL_LINE);
    glVertex3f(0.0f, 0.0f, 0.5f);
    glVertex3f(0.0f, 1.0f, 0.5f);
    glVertex3f(1.0f, 1.0f, 0.5f);
    glEnd();

    glMatrixMode(GL_PROJECTION);
    glOrtho(-2.0,2.0,-2.0,2.0,-1.0,1.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();



}

int main (int argc, char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
    glutInitWindowSize(800, 600);
    glutCreateWindow("Triangle");
//  glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
//  glShadeModel(GL_SMOOTH);

    glutReshapeFunc(ChangeSize);
    glutDisplayFunc(RenderScene);

    glutMainLoop();

    return 0;
}

这是错误消息:

Unhandled exception at 0x00000000 in HelloGL5.exe: 0xC0000005: Access violation.

请注意,我注释掉了两行代码,但是我没有收到此错误.当我将这两行之一添加到代码中时,为什么会出现此错误?

Please notice that I commented out two lines of code and this I am not getting this error. Why am I getting this error when I add one of those two lines to the code?

推荐答案

正如您在评论中所说.

我的目标是OpenGL 4.4.0

I am targeting OpenGL 4.4.0

出现访问冲突"错误的原因是因为您在OpenGL中使用了许多不推荐使用的功能.

The reason you you're getting an "Access violation" error is because you're using a lot of deprecated functions in OpenGL.

以下功能是OpenGL 3.1版中不推荐使用的某些功能

The following functions are some of the functions deprecated in OpenGL version 3.1

  • glMatrixMode()
  • glLoadIdentity()
  • glBegin()
  • glEnd()
  • glVertex3 *()
  • glTexCoord *()
  • glNormal *()
  • glColor *()

这是一个很棒的电子表格,其中包含所有" OpenGL函数以及是否已弃用,移除,删除了内核等. Khronos Group 的人制作的.

Here is a great spreadsheet about "all" the OpenGL functions and whether they are deprecated, removed, core, etc. Click here to see it. The reason I say "all" like that, is because the spreadsheet is made by people using OpenGL and not by the The Khronos Group.

现在您可能会问,如果不赞成使用 Matrix Stack ,那么我们应该怎么做,嗯...一切.底线现在,您应该构建/计算和控制自己的 MatrixStack .

Now you're maybe asking, well if the Matrix Stack is deprecated then how are we suppose to do, well... everything. Bottom line now you're suppose to build/calculate and control your own MatrixStack.

这里有一些链接,您可以在其中阅读有关Matrix计算和Matrix转换的信息.

Here is a few links where you can read about Matrix calculations and Matrix Transformations.

  • Matrix Mathematics
  • Transformation Matrix
  • OpenGL Programming/3D/Matrices

不推荐使用glBegin()glEnd()等的原因.是因为不推荐使用整个立即模式渲染.现在,您假设将 VAO

The reason behind why glBegin(), glEnd(), etc. is deprecated. Is because the whole Immediate Mode rendering was deprecated. Now you're suppose to use VAOs with VBOs (and IBOs).

顶点数组对象(VAO)是OpenGL对象,它封装了指定顶点数据所需的所有状态(下面有一个小例外).它们定义了顶点数据的格式以及顶点数组的源.请注意,VAO本身不包含数组.数组存储在缓冲区对象中(见下文). VAO只是引用已经存在的缓冲区对象.

A Vertex Array Object (VAO) is an OpenGL Object that encapsulates all of the state needed to specify vertex data (with one minor exception noted below). They define the format of the vertex data as well as the sources for the vertex arrays. Note that VAOs do not contain the arrays themselves; the arrays are stored in Buffer Objects (see below). The VAOs simply reference already existing buffer objects.

来源: http://www.opengl.org/wiki/Vertex_Array_Objects#Vertex_Array_Object

顶点缓冲区对象(VBO)是一个缓冲区对象,用作顶点数组数据的源.它与任何其他缓冲区对象没有什么不同,可以将用于变换反馈"或异步像素传输的缓冲区对象用作顶点数组的源值.

A Vertex Buffer Object (VBO) is a Buffer Object which is used as the source for vertex array data. It is no different from any other buffer object, and a buffer object used for Transform Feedback or asynchronous pixel transfers can be used as source values for vertex arrays.

来源: http://www.opengl.org/wiki/Vertex_Specification#Vertex_Buffer_Object

这篇关于Visual Studio 2008上的HelloWorld OpenGL程序中未处理的异常错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆