Results 1 to 3 of 3

Thread: OpenGL GLUT/ GLEW problem (segmentation error)

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    9

    OpenGL GLUT/ GLEW problem (segmentation error)

    I am having trouble trouble trying to execute my openGL program and I think it has something to do with GLEW or GLUT. When I try to execute my program, a window appears for half a second, then closes and I get a segmentation error Some one please help me outt.



    #include "main.h" //g++ main.cpp -lGLEW -lGL -lglfw -lGLU -lglut -o triangle
    #define BUFFER_OFFSET(offset) ((void *)(offset))
    using namespace std;


    enum VAO_IDs {Triangles, NumVAOs};
    enum Buffer_IDs {ArrayBuffer, NumBuffers};
    enum Attrib_IDs {vPosition = 0};
    GLuint VAOs[NumVAOs];
    GLuint Buffers[NumBuffers];
    const GLuint NumVertices = 6;

    //assigning vertex data to buffer objects and preparing to send to
    void init() //Vertex Shaders.
    {
    glGenVertexArrays(NumVAOs, VAOs);
    glBindVertexArray(VAOs[Triangles]);

    GLfloat vertices [NumVertices] [2] =
    {
    { -0.90, -0.90 }, //Triangle 1
    { 0.85, -0.90 },
    { -0.90, 0.85 },
    { 0.90, -0.85 }, //Triangle 2
    { 0.90, 0.90 },
    { -0.85, 0.90 }
    };

    glGenBuffers(NumBuffers, Buffers);
    glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

    ShaderInfo shaders[] =
    {
    { GL_VERTEX_SHADER, "triangles.vert"},
    { GL_FRAGMENT_SHADER, "triangle.frag"},
    { GL_NONE, NULL}
    };

    glVertexAttribPointer(vPosition, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
    glEnableVertexAttribArray(vPosition );


    }

    void display()
    {
    glClearColor(1,0,1,0);
    glClear(GL_COLOR_BUFFER_BIT);
    glBindVertexArray(VAOs[Triangles]); //?
    glDrawArrays(GL_TRIANGLES, 0, NumVertices);

    glFlush();
    }



    int main(int argc, char** argv)
    {
    const int width = 400, height = 400;

    glutInit(&argc, argv);
    glutInitWindowSize(width, height);
    glutInitDisplayMode(GLUT_RGBA);
    glutInitContextVersion(3, 3);
    glutInitContextProfile(GLUT_CORE_PROFILE);
    glutCreateWindow(argv[0]);

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



    My shaders...

    triangle.frag:

    #version 330 core

    out vec4 fcolor;

    void main()
    {
    fcolor = vec4(0.0, 0.0, 1.0, 1.0);
    }


    triangle.vert:


    #version 330 core

    layout(location = 0) in vec4 vPostion;

    void main()
    {
    gl_Position = vPosition;
    }

  2. #2
    Newbie OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789
    See my answer to your previous question - you don't yet have function pointers loaded for your OpenGL entry points. If you'd run this in a debugger you would have seen that the value of e.g glGenVertexArrays is 0x00000000.

    Since you're linking to GLEW the same advice as I gave there applies: just make a call to glewInit at the very start of your init function.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    9
    Thanks again. I did follow your previous advice and added a glewInit call, but i had put it in my main function. Thanks for being patient

Similar Threads

  1. Replies: 3
    Last Post: 06-26-2018, 06:50 PM
  2. Error segmentation Fault -CL_ENQUEUENDRANGEKRNEL
    By akashsach15 in forum OpenCL
    Replies: 1
    Last Post: 02-22-2016, 04:10 AM
  3. Issues setting up OpenGL (segmentation error)
    By AdamVO in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-27-2013, 05:59 PM
  4. error using glut and glew in mex file
    By M77ATTAR in forum OpenGL: Windows
    Replies: 0
    Last Post: 11-14-2013, 09:58 AM
  5. segmentation error with glTexImage3D
    By Elias OpenGL in forum OpenGL: GLSL
    Replies: 3
    Last Post: 07-29-2010, 03:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean