Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: unhandled exception

  1. #1
    Intern Newbie
    Join Date
    Sep 2013
    Posts
    31

    unhandled exception

    Hello.
    I'm simply trying to draw 1 triangle with a mixed VBO like this:
    Code :
    glGenVertexArrays(1, &VAO);
    glBindVertexArray(VAO);
     
    static const GLfloat vrtClrB[] =
    	{
    	0.0f, 0.0f, 0.3f, 0.1f, 0.6f,
    	0.5f, 0.0f, 0.3f, 0.6f, 0.1f,
    	0.5f, 0.5f, 0.333f, 0.333f, 0.333f
    	};
     
    glGenBuffers(1, &VBO);
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vrtClrB), vrtClrB, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
     
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (const void*)0); // 2D position
    glEnableVertexAttribArray(1);
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (const void*)(2 * sizeof(GLfloat))); // color
    after which I continuously call
    Code :
    glDrawArrays(GL_TRIANGLES, 0, 3);

    I'm using MSVS 2013 and it throws an unhandled exception in nvoglv64.dll.
    The shaders compile and link just fine.
    I just can't see what I'm missing.

  2. #2
    Member Regular Contributor
    Join Date
    Dec 2009
    Posts
    251
    You pass 0-based pointers in glVertexAttribPointer, but at that time no VBO is bound to GL_ARRAY_BUFFER, so the address is not the start of your VBO, but the start of CPU memory, which is usually not accessible. Unbind the VBO after the glVertexAttribPointer calls.

  3. #3
    Intern Newbie
    Join Date
    Sep 2013
    Posts
    31
    Thanks. It doesn't show the exception but it doesn't show anything on the screen either. I was expecting a triangle on the right half of the screen...
    EDIT:
    Just to rule out the shaders:
    Vertex shader
    Code :
    #version 330 core
     
    layout(location = 0) in vec2 position;
    layout(location = 1) in vec3 colorV;
    out vec3 colorF;
     
    void main()
    	{
    	gl_Position.xy = position;
    	gl_Position.z = 0.0;
    	gl_Position.w = 1.0;
     
    	colorF = colorV;
    	}
    Fragment shader
    Code :
    #version 330 core
     
    in vec3 colorF;
    out vec3 color;
     
    void main()
    	{
    	color = colorF;
    	}
    Last edited by mireazma; 03-26-2015 at 12:01 PM.

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    894
    Stride should be 5 * sizeof(GLfloat) for both glVertexAttribPointer calls - it is the number of bytes the GL has to jump to get from one vertex to the next, i.e. when interleaving attributes like you do here it is the combined size of all attributes for a single vertex.

  5. #5
    Intern Newbie
    Join Date
    Sep 2013
    Posts
    31
    Right! Each attribute starts once every 5 floats
    Man, this is one of those times when no matter how many bugs you solve, you find one more and after solving it, the app implacably keeps being broken.
    After the stride correction the screen is still black. By my calculations, even with the wrong stride, a triangle should be drawn on the screen.

  6. #6
    Intern Newbie
    Join Date
    Sep 2013
    Posts
    31
    Ok, after hours of checking and reading I discovered that the effing triangle was drawn there all along! It was a black tri on a black background. This I never expected since in the fragment shader I specified the color myself:
    Code :
    #version 330 core
     
    out vec4 color;
     
    void main()
    	{
    	color = vec4(1.0, 1.0, 1.0, 1.0);
    	}
    and not only this but I tried with different colors. I discovered by accident when I changed the clear color to green. No matter what the tri is black.

    So what is the problem? Does somebody have a guess? Please?

    EDIT:
    I found the bug; seems that OpenGL doesn't complain and it goes on working fine, if you create the shaders but you don't create the program! I declared a GLuint for the program and used it as is without calling glCreateProgram().
    Shaders compiled and linked just fine, vertex shader executed as expected but fragment shader didn't.

    This under no circumstances should be allowed!
    Last edited by mireazma; 03-27-2015 at 04:23 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •