Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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;
}

Here is the error message:

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
133 views
Welcome To Ask or Share your Answers For Others

1 Answer

As you said in the comments.

I am targeting OpenGL 4.4.0

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

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

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

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.

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.

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

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

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.

Source: 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.

Source: http://www.opengl.org/wiki/Vertex_Specification#Vertex_Buffer_Object


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...