Skip to main content
Fixed formatting.
Source Link
user1118321
  • 2.6k
  • 14
  • 16

hello whenWhen I try to debug my program, this Exception is throwingbeing thrown in glgenbuffers ima call to glGenBuffers. I'm using openglOpenGL and sdl there areSDL. Here is my codescode:

itIt consists of two classclasses: m and sprite s

s is var of sprite class

class m is like that

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) {this:

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) {



}

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

        input();
        draw();
    }

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


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


}

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

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() {


}


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

}

}

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 s is var of sprite class

class m is like that

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

}

When I try to debug my program, this Exception is being thrown in a call to glGenBuffers. I'm using OpenGL and SDL. Here is my code:

It consists of two classes: m and sprite

s is var of sprite class

class m is like this:

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

}
added 4 characters in body
Source Link

it consists of two class m and sprite class m is like that s is var of sprite class void

class m is like that

void run() { init(); s.init(-1.0f,-1.0f,1.0f,1.0f); loop(); }

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

it consists of two class m and sprite s is var of sprite class

class m is like that

void run() { init(); s.init(-1.0f,-1.0f,1.0f,1.0f); loop(); }

Source Link

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

}