Hey there. I am sorry for the long post in advance :(. I am relatively new to OpenGL, I managed to create my first program following some online tutorials, but now I am facing a really weird bug.
Since it is hard to explain the bug I’ll post a link to a video on youtube, that displays it.
With a cube model: Cube Model Issue - YouTube
With a pyramid model: Pyramid Model Issue - YouTube
In the videos I show the original model that I have in blender (a simple cube and pyramid primitives), and then I show how my program displays them.
I have set it to draw lines so that you can see the model structure a bit better.
All I am doing in the video is rotating them around the X axis (left-right) and this is what I get.
If someone needs it, I can give the source code, but since there is quite a lot of other stuff in it I will try to explain only the drawing-related parts
[ul]
[li]First, I export my model from blender and grab the vertex coordinates and put them in a GLfloat array. I do the same with the Vertex Indecies but I put them in a GLushort array.[/li][li]Next I create a VAO, VBO and IBO. (I have abstracted them in my own classes so it looks like Buffer * cVBO = new Buffer(cubeVertecies, 3, 8 * 3); [/li][LIST]
[li]cubeVertecies is the GLfloat[] are the vertex coordinates[/li][li]3 is the component count (I use it to set the size later when I call [b]glVertexAttribPointer/b in my VAO)[/li][li]8 * 3 is the total size of the buffer (I also multiply it by sizeof(GLfloat) in my class)[/li][/ul]
[li]I also have the exact same buffer, but for vertex colors, that I use for testing purposes (Im hopint this is not relevant to the bug)[/li][li]After that I create an IndexBuffer from my Glushort[] and bind the data to it.[/li][/LIST]
After this I add my VBO and ColorBuffer to the VAO and proceed inside the main loop to rendering.
In the loop I do the following stuff:
[ul]
[li]Bind the VAO[/li][li]Bind the IBO[/li][li]call glDrawElements() (I pass the IBO’s size for the count and 0 for the indicies)[/li][li]Unbind the IBO[/li][li]Unbind the VAO[/li][/ul]
And when I render I get the odd artifact, shown in the video
When rendering 2D rectangles everything seems to work fine but with 3d models it breaks.
*I believe it has something to do with my IBO’s since if I reorded some of the indices I get different parts of the model appearing/disappearing.
** Again, if its necessary, I can post my source code.