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 3 of 3

Thread: Binding Index Buffer Before Binding Vertex Array Causes Black Screen.

  1. #1
    Junior Member Newbie
    Join Date
    May 2018
    Posts
    5

    Binding Index Buffer Before Binding Vertex Array Causes Black Screen.

    Hello!

    I'm new to this forum and in OpenGL.

    After playing a little with what I've learn so far in OpenGL, I noticed that if i bind an Index Buffer, before binding a Vertex Array, nothing get's drawn on the screen. I can't understand why this is happening. Generally, by playing a little with the binding order, these was my results:

    1) Binding VAO before VBO and IBO (works)
    2) Binding VAO after VBO and before IBO (works)
    3) Binding VAO after VBO and after IBO (black screen)

    Of course, the atrribPointers are being set up after i bind VBO and VAO.

    Since VAO relates VBO's with atrribPointers, why does the IBO binding order matters?

    This is the code that causes the black screen:
    Code :
          float vertices[] = {
     
    		//Positions           //Colors             //Texture Coordinates.
    		-0.5f, -0.5f, 0.0f,   1.0f, 0.0f, 0.0f,    0.0f, 0.0f,
    		0.5f,  -0.5f, 0.0f,   0.0f, 1.0f, 0.0f,    1.0f, 0.0f,
    		0.0f,   0.5f, 0.0f,   0.0f, 0.0f, 1.0f,    0.5f, 1.0f
    	};
     
    	unsigned int indicies[] = {
    		0, 1, 2,
    	};
     
     
            unsigned int VBO;
    	glGenBuffers(1, &VBO);
    	glBindBuffer(GL_ARRAY_BUFFER, VBO);
    	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
     
            unsigned int IBO;
    	glGenBuffers(1, &IBO);
    	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
    	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indicies), indicies, GL_STATIC_DRAW);
     
     
            unsigned int VAO;
    	glGenVertexArrays(1, &VAO);
    	glBindVertexArray(VAO);
     
    	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);
    	glEnableVertexAttribArray(0);
     
    	glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(sizeof(float) * 3));
    	glEnableVertexAttribArray(1);
     
    	glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(sizeof(float) * 6));
    	glEnableVertexAttribArray(2);

    Thank you!!!
    Last edited by babaliaris; 05-14-2018 at 04:24 AM.

  2. #2
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,003
    Since VAO relates VBO's with atrribPointers, why does the IBO binding order matters?
    Because VAOs store all relevant vertex specification state. Including index buffers. `glBindBuffer(GL_ELEMENT_ARRAY_BUFFER` modifies the currently bound VAO. Binding a new VAO changes the state of the current GL_ELEMENT_ARRAY_BUFFER binding.

  3. #3
    Junior Member Newbie
    Join Date
    May 2018
    Posts
    5
    Quote Originally Posted by Alfonse Reinheart View Post
    Because VAOs store all relevant vertex specification state. Including index buffers. `glBindBuffer(GL_ELEMENT_ARRAY_BUFFER` modifies the currently bound VAO. Binding a new VAO changes the state of the current GL_ELEMENT_ARRAY_BUFFER binding.
    Thank you for your answer!! I didn't know that, now it makes sense!

Posting Permissions

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