2

I am just learning openGL and I have just found out that I should use the programable pipeline instead of the fixed pipeline..

Therefore I started using VAOs in order to make an array of verticies. This means using functions such as: glGenVertexArrays, glBindVertexArray and so on..

These functions are all a part of the glew library. And Ive come to the conclusion that something is wrong with glew library since non of the glew-methods work.

I get this error message:

Exception thrown at 0x00000000 in CUBE.exe: 0xC0000005: Access violation executing location 0x00000000.

I have read all forums regarding this error message and forums regarding disfunctional glew without any succes..

If tried using the trick to set glewExperimental = GL_TRUE; I have tried to create a context. And ofc. checked whether the glew library was linked correctly. I have also put glewInit() before any glew related method calls. And much more..

So its been a long day.. Here is my code for reference.

#include <stdio.h>
#include <GL\glew.h>
#include <GL\glut.h>

void display() {
    glClear(GL_COLOR_BUFFER_BIT);
    glFlush();
}

void Initialize() {
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}

void init(void) {

    glewInit();

    GLuint arrayID;
    glGenVertexArrays(1, &arrayID);
    glBindVertexArray(arrayID);

    static const GLfloat g_vertex_buffer_data[] = {
        -1.0f,-1.0f,-1.0f, // triangle 1 : begin
        -1.0f,-1.0f, 1.0f,
        -1.0f, 1.0f, 1.0f, // triangle 1 : end
         1.0f, 1.0f,-1.0f, // triangle 2 : begin
        -1.0f,-1.0f,-1.0f,
        -1.0f, 1.0f,-1.0f, // triangle 2 : end
         1.0f,-1.0f, 1.0f,
        -1.0f,-1.0f,-1.0f,
         1.0f,-1.0f,-1.0f,
         1.0f, 1.0f,-1.0f,
         1.0f,-1.0f,-1.0f,
        -1.0f,-1.0f,-1.0f,
        -1.0f,-1.0f,-1.0f,
        -1.0f, 1.0f, 1.0f,
        -1.0f, 1.0f,-1.0f,
         1.0f,-1.0f, 1.0f,
        -1.0f,-1.0f, 1.0f,
        -1.0f,-1.0f,-1.0f,
        -1.0f, 1.0f, 1.0f,
        -1.0f,-1.0f, 1.0f,
         1.0f,-1.0f, 1.0f,
         1.0f, 1.0f, 1.0f,
         1.0f,-1.0f,-1.0f,
         1.0f, 1.0f,-1.0f,
         1.0f,-1.0f,-1.0f,
         1.0f, 1.0f, 1.0f,
         1.0f,-1.0f, 1.0f,
         1.0f, 1.0f, 1.0f,
         1.0f, 1.0f,-1.0f,
        -1.0f, 1.0f,-1.0f,
         1.0f, 1.0f, 1.0f,
        -1.0f, 1.0f,-1.0f,
        -1.0f, 1.0f, 1.0f,
         1.0f, 1.0f, 1.0f,
        -1.0f, 1.0f, 1.0f,
         1.0f,-1.0f, 1.0f
    };

    GLuint vertexBuffer;
    glGenBuffers(1, &vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), 
    g_vertex_buffer_data, GL_STATIC_DRAW);

    glEnableVertexAttribArray(1);
    glVertexAttribPointer(
        1,                                
        3,                                
        GL_FLOAT,                         
        GL_FALSE,                         
        0,                                
        (void*)0                          
    );

    glDrawArrays(GL_TRIANGLES, 0, 12 * 3);
}

int main(int iArgc, char** cppArgv) {
    glutInit(&__argc,__argv);
    glDrawArrays(GL_TRIANGLES, 0, 12 * 3);
    glutInitDisplayMode(GLUT_RGBA);
    glutInitWindowSize(950, 500);
    glutInitWindowPosition(200, 200);
    glutCreateWindow(__argv[0]);
    wglCreateContext;
    wglMakeCurrent;
    glewExperimental = GL_TRUE;


    Initialize();
    init();
    wglMakeCurrent;
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
}

There are some incoherent stuff in my code (a result of a day full of different tries), but the essential thing is that my program will show a window if I clear out the glew stuff..

My version of OpenGL is 3.3 if is has any relevance.

Spektre
  • 49,595
  • 11
  • 110
  • 380
WillGates
  • 65
  • 1
  • 8
  • 4
    wglMakeCurrent -> wglMakeCurrent() . Otherwise you are just stating a function pointer... Compilers should warn you about this. Try compiling with -Wall – Andreas Sep 16 '17 at 09:54
  • You have a draw call (glDrawArrays, second statment in main) before opening any window. That cant be right – Andreas Sep 16 '17 at 09:55
  • When learning OpenGL omit the transformations until you get something on display working. If omitting glOrtho, glMatrixMode etc you render to NDC which is just fine when learning/testing. – Andreas Sep 16 '17 at 09:57
  • @Andreas ah I didnt know. But anyways, I am not sure whether its needed to define a context for my program to run, so not sure if it matters whether I make the wglCreatContext and wglMakeCurrent() work? – WillGates Sep 16 '17 at 10:43
  • btw the draw call was a mistake, its deleted now, thnx :) – WillGates Sep 16 '17 at 10:45
  • Another thing. You display function clears the display and then does nothing. You should put your draw calls in there. Consider running CodeXL or gDEBugger to figure out what your buffer are in memory, and what commands sent each frame. – Andreas Sep 16 '17 at 11:20
  • see [complete GL+VAO/VBO+GLSL+shaders example in C++](https://stackoverflow.com/a/31913542/2521214) and compare/adapt what is wrong with yours implementation. You have to call glewinit just once after OpenGL context is working. The VAO/VBO and shader stuff is not part of GLEW. GLEW is just a wrangler which register the OpenGL extensions from your gfx driver into your code. There are 2 versions of use one is dynamic linking via DLL and second is static. I use the latter so for that you need also the GLEW source (`glew.c`) and specific define before inclusion. – Spektre Sep 17 '17 at 08:15
  • The error code suggest you are using not yet loaded function (call `NULL` pointer) so either you are calling unsupproted function by your gfx HW/driver or you did not call glewinit properly. – Spektre Sep 17 '17 at 08:18

0 Answers0