“Access violation reading location 0x000000000” in a simple OpenGL app

I have a problem in openGL when using buffer object to store vertex array . when I run the code , a window appears that display message " access violation reading location 0x000000000 " and when I move the cursor to arrow beside glGenBuufers function I see description: this is the next statement to execute when this thread returns from current function.

Code:

int frame=0;
void display();
void datasource();

 GLuint vbo;

void datasource()
{
    GLfloat vertex1[]={-1.000000 ,0.500000 ,-0.700000 ,0.500000 ,-1.000000 ,0.800000 ,-0.700000 ,0.800000 ,-0.400000 ,0.500000 ,-0.100000 ,0.500000 ,-0.400000 ,0.800000 ,-0.100000 ,0.200000 ,0.500000 ,0.500000 ,0.500000 ,0.200000 ,0.800000 ,0.500000,0.800000 ,0.800000 ,0.800000 ,0.500000 ,1.100000 ,0.500000 ,0.800000 ,0.800000 ,1.100000,0.800000  };

    glGenBuffers(1,&vbo);
    glBindBuffer(GL_ARRAY_BUFFER,vbo);
    glBufferData(GL_ARRAY_BUFFER,sizeof(vertex1),vertex1,GL_STATIC_DRAW);
}


void init(int arc,char **arch)
{
    glutInit(&arc,arch);
    glutInitWindowSize(800,800);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
    glutCreateWindow("chess");
    glClearColor(0.0,0.0,0.0,0.0);
    glutDisplayFunc(display);
}

int main(int arc,char **arch)
{
    init(arc,arch);
    datasource();
    glutMainLoop();
    return 0;
}

void display()
{
    frame++;
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glDrawArrays(GL_TRIANGLE_STRIP,0,8);
    glutSwapBuffers();
    glutPostRedisplay();
}

What did I do wrong?

Answers


glGenBuffers, glBindBuffer and glBufferData are functions of either the Vertex Buffer Object extension or of OpenGL-1.5. The default system ABIs only go to OpenGL-1.2 so you need to post-load extended OpenGL functionality before you can use it. Just including the headers is not sufficient, because those just provide you the uninitialized symbols.

Most easy way to go:

  1. Download and install GLEW from http://glew.sf.net
  2. Replace all occurances of #include <GL/gl.h> with #include <GL/glew.h>
  3. Call glewInit() right after glutCreateWindow and check the error code
  4. Check if are VBOs are available (i.e. at least GL_ARB_vertex_buffer_object or OpenGL version >= 1.5)
  5. Add the GLEW library to your linker settings

Need Your Help

Proper way to save date input data to Firebase with simpleLogin

angularjs firebase firebasesimplelogin

I'm new to firebase, and I'm trying to add a Date Of Birth field to a form and save it to Firebase.

Visual Studio 2010 Wont Load Referenced DLLs

c# asp.net visual-studio-2010 dll reference

I have been working on an ASP.NET project for months now without issue. Recently my computer crashed mid compile and now when I load and run the project I get 'Could not load file or assembly 'Ioni...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.