Skip to main content
1 of 3

Access violation executing location 0x00000000

hello when I try to debug this Exception is throwing in glgenbuffers im using opengl and sdl there are my codes

it consists of two class m and sprite class m is like that s is var of sprite class void run() { init(); s.init(-1.0f,-1.0f,1.0f,1.0f); loop(); }

void init() { SDL_Init(SDL_INIT_EVERYTHING); glewExperimental = GL_TRUE; SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); window = SDL_CreateWindow("mine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1024, 768, SDL_WINDOW_OPENGL); if (window == nullptr) {

    fatalerror("cant create (open) window");
}





SDL_GLContext context = SDL_GL_CreateContext(window);
if (context == nullptr) {

    fatalerror("context cant be created ");


}
GLenum cerror = glewInit();
if (cerror != GLEW_OK)
{
    fatalerror("cant init glew:(");
}
std::cout << "ok";


glClearColor(1.0f, 0.0f, 0.0f, 1.0f);

}

void looploop() { while (state != gamestate::exit) {

    input();
    draw();
}

} void M::input() { while (SDL_PollEvent(&events)) {

    switch (events.type)
    {
    case SDL_QUIT:
        state = gamestate::exit;
        SDL_DestroyWindow(window);
        break;
    case SDL_MOUSEMOTION:
        std::cout << events.motion.x << ',' << events.motion.y << "\n";
        break;
    }



}

}

void draw() { glClearDepth(1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnableClientState(GL_COLOR_ARRAY); s.draw();

SDL_GL_SwapWindow(window);

}

class sprite

void init(float x, float y, float w, float h) { _x = x; _y = y; _w = w; _h = h;

if (vboid == 0) {


    glGenBuffers(1, &vboid);
}

float vertexdata[12];
//first triangle
vertexdata[0] = x + w;
vertexdata[1] = y + w;
vertexdata[2] = x;
vertexdata[3] = y + h;
vertexdata[4] = x;
vertexdata[5] = y;
//second triangle
vertexdata[6] = x;
vertexdata[7] = y ;
vertexdata[8] = x+h;
vertexdata[9] =  y;
vertexdata[10] = x+w;
vertexdata[11] = y+h;
glBindBuffer(GL_ARRAY_BUFFER,vboid);
glBufferData(GL_ARRAY_BUFFER,sizeof(vertexdata),vertexdata,GL_STATIC_DRAW)
    ;

}

void draw() {

glBindBuffer(GL_ARRAY_BUFFER,vboid);
glEnableVertexAttribArray(0);
glVertexAttribLPointer(0,2,GL_FLOAT,GL_FALSE,0);
glDrawArrays(GL_TRIANGLES,0,6);
glDisableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vboid);

}