Jump to content

  • Log In with Google      Sign In   
  • Create Account


VBO is Rendering an extra triangle


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Matthewj234   Members   -  Reputation: 760

Like
0Likes
Like

Posted 26 May 2013 - 07:21 PM

Hey guys, I have been working on a 3D mesh system based on adding polygons to the mesh. However, I have run into an issue!

 

2013-05-27_0218.png

Whats happening is the extra triangle returning to the origin is being added, and I am clueless as to why.

 

 public void createMesh(){
        Tessellator t = new Tessellator();
        t.setColour(0.7f, 0.2f, 0.2f, 1f);
        t.addPoly(new Vector3f[]{
                new Vector3f(120, 120, 1f), new Vector3f(80, 120, 1f), new Vector3f(100, 200f, 1f)
        }, null);
        t.setColour(1f, 0f, 0f, 1f);
        t.addPoly(new Vector3f[]{
                new Vector3f(120, 120, 1f), new Vector3f(200, 120, 1f), new Vector3f(160, 200f, 1f),
        }, null);
        t.setColour(0f, 1f, 0f, 1f);
        t.addPoly(new Vector3f[]{
                new Vector3f(120, 120, 1f), new Vector3f(200, 120, 1f), new Vector3f(160, 80f, 1f)
        }, null);

        mesh = t.generateMesh();
    }

That is the code for setting the vertices and colours.

 

    public void render() {
        preRender();
        doRender();
        postRender();
    }

    public void preRender() {
        glEnableClientState(GL_VERTEX_ARRAY);
        if (hasTexCoords || hasTexLighting) glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        if (hasColour) glEnableClientState(GL_COLOR_ARRAY);
        if (hasNormals) glEnableClientState(GL_NORMAL_ARRAY);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboVertexBuffer);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboIndexBuffer);

        glVertexPointer(VERTEX_SIZE, GL11.GL_FLOAT, stride, vertexOffset);

        if (hasTexCoords) {
            GL13.glClientActiveTexture(GL13.GL_TEXTURE0);
            glTexCoordPointer(TEX_COORD_SIZE, GL11.GL_FLOAT, stride, texCoordOffset);
        }

        if (hasTexLighting) {
            GL13.glClientActiveTexture(GL13.GL_TEXTURE1);
            glTexCoordPointer(TEX_LIGHTING_SIZE, GL11.GL_FLOAT, stride, texLightingOffset);
        }

        if (hasColour) glColorPointer(COLOUR_SIZE, GL11.GL_FLOAT, stride, colourOffset);
        if (hasNormals) glNormalPointer(GL11.GL_FLOAT, stride, normalOffset);
    }

    public void postRender() {
        if (hasNormals) glDisableClientState(GL_NORMAL_ARRAY);
        if (hasColour) glDisableClientState(GL_COLOR_ARRAY);
        if (hasTexCoords || hasTexLighting) glDisableClientState(GL_TEXTURE_COORD_ARRAY);
        glDisableClientState(GL_VERTEX_ARRAY);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    }

    public void doRender() {
        GL11.glDrawElements(GL11.GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, 0);
    }

And thats the render code for the mesh.

 

 

If anyone can point me towards what I am doing wrong, I would be greatly appreciative!



Sponsor:

#2 marcClintDion   Members   -  Reputation: 431

Like
1Likes
Like

Posted 04 June 2013 - 03:12 AM

This can happen if the vertex count doesn't match up with the value being passed to the draw call.  You should check your variable 'indexCount' to make sure it's correct.


Consider it pure joy, my brothers and sisters, whenever you face trials of many kinds, because you know that the testing of your faith produces perseverance. Let perseverance finish its work so that you may be mature and complete, not lacking anything.


#3 shocobenn   Members   -  Reputation: 273

Like
0Likes
Like

Posted 04 June 2013 - 05:16 AM

Ok, so if your vertex count in your buffer is smaller than the "indexCount" you're passing you won't have an error but have an additions of points who are located at the corner left of you screen (or it's more random ?) 



#4 Brother Bob   Moderators   -  Reputation: 7779

Like
2Likes
Like

Posted 04 June 2013 - 05:32 AM

The situation is undefined. An error, or extra triangles, are both equally "valid" results in that they produce an undefined result for for a call with invalid parameters.



#5 marcClintDion   Members   -  Reputation: 431

Like
1Likes
Like

Posted 04 June 2013 - 05:33 AM

You end up overwriting or accessing memory from other areas of the program.  Sometimes nothings shows up at all until you start loading lots of other models, then the weird triangles can show up on models that are set up correctly.  Sometimes the program will crash.  What happens when you do this is definitely random.


Consider it pure joy, my brothers and sisters, whenever you face trials of many kinds, because you know that the testing of your faith produces perseverance. Let perseverance finish its work so that you may be mature and complete, not lacking anything.


#6 marcClintDion   Members   -  Reputation: 431

Like
0Likes
Like

Posted 04 June 2013 - 05:42 AM

The only program that I've come across that can give you easy to read info on VBO errors like this is a program for MacOS called 'Instruments' in the section iOS->graphics->openGL ES Analyzer.  Knowing this won't help you immediately but maybe someone passing through here will know of a similar tool for the platform you are using.


Consider it pure joy, my brothers and sisters, whenever you face trials of many kinds, because you know that the testing of your faith produces perseverance. Let perseverance finish its work so that you may be mature and complete, not lacking anything.


#7 marcClintDion   Members   -  Reputation: 431

Like
0Likes
Like

Posted 04 June 2013 - 06:26 AM

I've been staring at your code and the attached image for quite some time now and I'm convinced that you should not be using glDrawElements for this type of rendering.  Many of your vertices are standing out on their own.  Using an index buffer only offers optimization if calculations on redundant points can be eliminated, this only happens if your model has many triangles that share vertices with other triangles.  Also, you will have to process all the newly created geometry to determine whether or not points are being shared and then recalculate the index buffer every time more geometry is added, this is going to offset any performance benefit that glDrawElements offers since your doing more math just to use this function.  I'd suggest you use glDrawArrays instead.   Here's a quote from an Apple document: " ..an indexed triangle list requires additional memory for the indices and adds overhead to look up vertices." http://developer.apple.com/library/ios/#documentation/3ddrawing/conceptual/opengles_programmingguide/TechniquesforWorkingwithVertexData/TechniquesforWorkingwithVertexData.html After reading about someone else's problems with indices I decided to try the following. I entered the number 1000 to -> glBindBuffer(GL_ARRAY_BUFFER, 1000); in a program that only has a few dozen models and it not only crashed the program, it took down VirtualBox OS emulator running Windows7 instantly. Very nasty.


Consider it pure joy, my brothers and sisters, whenever you face trials of many kinds, because you know that the testing of your faith produces perseverance. Let perseverance finish its work so that you may be mature and complete, not lacking anything.


#8 Matthewj234   Members   -  Reputation: 760

Like
0Likes
Like

Posted 06 June 2013 - 07:28 AM

Thanks for the responses guys!

 

I will check the indexCount and test it with more triangles.  

 

As for the usage of glDrawElements, I am using this system to render 3D mesh's, I was just using the 3 triangles to test the setup.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS