Jump to content
  • Advertisement
Sign in to follow this  

OpenGL trying to use VBO - I get no error message, but nothing is drawn

This topic is 4387 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I write a program using managed c++ (.net) and opengl VBO extention. I want to use both array and element_array buffers. So I read data from file and save to array "Landscape->array" where it stored like this: vertex coordinates (x,y,z); coordinates of a normal to this vertex (x,y,z); texture coords (x,y). All data have type Single (float). I try to render quads, so there are 4 vertexes for each quad, even if some quads may have common vertexes. Here is the code where I initialize VBO's:
bool SetLandscape(LANDSCAPE *a_landscape)
      const GLuint __pin *vboId=&vboLandscapeId;
      delete[] LandscapeIndexes;
                    // SortByTextures function work correctly.
      LandscapeIndexes = new UInt32[Landscape->numberOfVertexes];
                    // Here I fullfil array LandscapeIndexes with indexes of vertexes which I want to draw (and to pass to vbo). I draw everything so I use all indexes.
      for(Int32 i=0; i < Landscape->numberOfVertexes; i++)
        LandscapeIndexes = i;
                    // Here I set offsets
      vboLandscapeVertexStart = 0;
      vboLandscapeNormalsStart = sizeof(Single)*3;
      vboLandscapeTexcoordsStart = vboLandscapeNormalsStart + vboLandscapeNormalsStart;
      vboLandscapeVertexOffset = sizeof(Single)*8;
      vboLandscapeNormalsOffset = vboLandscapeVertexOffset;
      vboLandscapeTexcoordsOffset = vboLandscapeVertexOffset;
      vboLandscapeSize = vboLandscapeVertexOffset * Landscape->numberOfVertexes;
                    // Then I save data to vbo
      DescryOGLCore::glBindBufferARB(GL_ARRAY_BUFFER_ARB,vboLandscapeId);    // Choose current buffer
      DescryOGLCore::glBufferDataARB(GL_ARRAY_BUFFER_ARB,vboLandscapeSize,Landscape->array,GL_STATIC_DRAW_ARB);  // Set buffer size & send vertexes to VBO
      Void __pin *li = &LandscapeIndexes[0];
      LandscapeIsSet = true;
      return true;

Those three functions I call only once when I render scene for the first time. It's ok. glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); Next section of code shows how I draw textured quads:
    Void DrawMap(Void)
      UInt32 index, count, j, tmp;

      j = 0;
      tmp = Landscape->numberOfTextures;
      for(UInt32 i=0; i < tmp; i++)                // Here I draw all quads: firstly with one texture, then with the next one, etc.
        index = j;         // index == number of the first quad with current texture
        }while(j < tmp && Landscape->land[j].texture==Landscape->land[j+1].texture);
        ++j; // Now j equals a number of the first quad with next texture.
        count = j - index;  // Here I calculate number of quads with current texture 
                              // Then I calculate the offset to the first (nearest) vertex which has the next texture
        Void __pin *li = (Void *)(index*vboLandscapeTexcoordsOffset+vboLandscapeTexcoordsStart);
        glBindTexture(GL_TEXTURE_2D,Landscape->texture);   // Choose texture
        glDrawElements(GL_QUADS,count,GL_UNSIGNED_INT,li);  // Render

In the code upwards I made comments where I have written how it is supposed to work. I hope this will help you to understand everything and to find where I had made an error. If you cannot find an error there I will be gratful if you at least tell me where my error (mistake?) may lie. Just right now, I stuck with it and I cannot even suggest what is wrong in my code. Thanks in advance.

Share this post

Link to post
Share on other sites
Maube your count value is not right here :

A quad needs 4 index to be drawn, so count should be a multiple of 4.
Also, you can use GL_UNSIGNED_SHORT instead GL_UNSIGNED_INT for better performance.

Share this post

Link to post
Share on other sites
So are indexes numbers of QUADS to be drawn or numbers of vertexes to be drawn?

e.g. if I render to quads I need to have array of indexes like this:
1, 2
or like this:
1, 2, 3, 4, 5, 6, 7, 8

Share this post

Link to post
Share on other sites
The IBO stores the vertices in the order you want to draw them.

So you would need to setup the IBO to draw them in the order that you need based on CCW or CW windings...

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!