Jump to content
  • Advertisement
Sign in to follow this  
Arks

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

This topic is 4470 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;
...
                        glEnable(GL_TEXTURE_2D);
      glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
      Landscape=a_landscape;
      delete[] LandscapeIndexes;
                    // SortByTextures function work correctly.
      Landscape->SortByTextures();
      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
      DescryOGLCore::glBindBufferARB(GL_ARRAY_BUFFER_ARB,0);
      DescryOGLCore::glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,vboLandscapeIndexes);
      Void __pin *li = &LandscapeIndexes[0];
      DescryOGLCore::glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,Landscape->numberOfVertexes,li,GL_STATIC_DRAW_ARB);
      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;
                        ...
             
      DescryOGLCore::glBindBufferARB(GL_ARRAY_BUFFER_ARB,vboLandscapeId);
      glVertexPointer(3,GL_FLOAT,vboLandscapeVertexOffset,(GLvoid*)vboLandscapeVertexStart);
      glNormalPointer(GL_FLOAT,vboLandscapeNormalsOffset,(GLvoid*)vboLandscapeNormalsStart);
      glTexCoordPointer(2,GL_FLOAT,vboLandscapeTexcoordsOffset,(GLvoid*)vboLandscapeTexcoordsStart);
      
      DescryOGLCore::glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,vboLandscapeIndexes);

      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
        do{
          ++j;
        }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
Advertisement
Maube your count value is not right here :
glDrawElements(GL_QUADS,count,GL_UNSIGNED_INT,li);

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!