“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

How to call the defaults method of parent model in backbone

javascript inheritance backbone.js superclass

I have created a ParentModel and few other models which extend ParentModel. Each ChildModel has some additional properties than ParentModel.

What is the minimum cost of deploying an iphone app to a single phone from monotouch?

iphone ios monotouch monodevelop

If I want to deploy a iphone app just to my phone (not the app store to sell to others) what is the minimum things you need to purchase?

How to best compare two NSString objects while ignoring case?

objective-c ios

I want to compare two strings. It fails when the string have capital letter. How do I convert both string to capitalize and compare.

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.