Jump to content
  • Advertisement
Sign in to follow this  
zhyla

OpenGL Black cracks in my object... need a hint

This topic is 3661 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

Below is a 16-sided cylinder-ish object that is supposed to look like a missile. It is rendered using OpenGL ES on an iphone. It isn't textured or anything (yet). I don't really understand what is causing black cracks. Below is what I'm using to draw it. The data is an export from Blender. I've tried with and without normals and both GL_FLAT and GL_SMOOTH. Am I missing something? Is the order that the vertices are fed into the vertex engine important? This is my first try at displaying anything more complicated than a cube.
    GLfloat normals[4*3];
    GLfloat vertices[4*3];
    glShadeModel(GL_SMOOTH);
    // Face 0
    normals[0] = 0.923856f;
    normals[1] = 0.382672f;
    normals[2] = 0.000000f;
    vertices[0] = 0.923880f;
    vertices[1] = 0.382683f;
    vertices[2] = 0.000000f;
    normals[3] = 0.707083f;
    normals[4] = -0.707083f;
    normals[5] = 0.000000f;
    vertices[3] = 0.707107f;
    vertices[4] = 0.707107f;
    vertices[5] = 0.000000f;
    normals[6] = 0.707083f;
    normals[7] = -0.707083f;
    normals[8] = 0.000000f;
    vertices[6] = 0.707107f;
    vertices[7] = 0.707107f;
    vertices[8] = 5.000000f;
    normals[9] = 0.919797f;
    normals[10] = 0.380993f;
    normals[11] = 0.093539f;
    vertices[9] = 0.923880f;
    vertices[10] = 0.382683f;
    vertices[11] = 5.000000f;
    glNormalPointer(GL_FLOAT, 0, normals);
    glVertexPointer(3, GL_FLOAT, 0, vertices);
    glEnableClientState(GL_VERTEX_ARRAY);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    // Face 1
    ...

Share this post


Link to post
Share on other sites
Advertisement
It looks to me like some missing polygons rather than an artifact. A larger, closer screenshot might help.

Also it's not a wise idea to use one vertex array PER face, I'd guess that would be almost as slow as immediate mode.

Cram ALL of your vertices, normals and faces into three buffers and use glDrawElements.

Share this post


Link to post
Share on other sites

I'll be cramming that all into one or two vertex dumps later, once I get this working.

Here's a better view:



What does that look like to you? Also what do you mean by "faces"? I've only got normals and vertexes.

Share this post


Link to post
Share on other sites
Quote:
Original post by zhyla
What does that look like to you? Also what do you mean by "faces"? I've only got normals and vertexes.


The order in which you're rendering those vertices make up the faces. Rendering all the vertices in one line probably isn't the way to go - some faces may share vertices.

Care to post the raw data exported with Blender?

Share this post


Link to post
Share on other sites
Here are the blender model and exported C code. If there's some other format you'd like it dumped to let me know.

Is there a rule for the order that vertices are supplied? CW? CCW? What happens if I zig-zag the vertices, will they get drawn funny like this? I inspected one of the faces in the code output and it looks like it's being drawn clockwise.

Share this post


Link to post
Share on other sites
Have you tried rendering with just TRIANGLES and not TRIANGLE_STRIP. The way a triangle strip winds is different and the problem you have looks like missing tri's at regular intervals.

Have you looked inside the mesh to see if the "missing" tri's are actually being drawn but facing the wrong way? you could try disabling culling this would let you know for sure that the missing faces aren't being rendered at all.

Another thing you could try, although it doesn't look like the case here, but when i export my mesh from 3ds MAX if it isn't water tight then i see breaks between polygons, not as extreme as your case but noticeable breaks non the less. Ensure all the vertices in you mesh are welded together where they need to be.

Share this post


Link to post
Share on other sites
When I switched from TRIANGLE_STRIP to TRIANGLES it looked like only half the quad was drawn (one triangle drawn, the other black). This is a good clue I'm doing something wrong. But I went back to blender and converted the quads to triangles and it looks fine now. I suspect I had the vertex order wrong for TRIANGLE_STRIP. I'll probably stick with triangles for now.

So what is the ideal way to dump triangles? All in one call? Break it up into chunks?

Share this post


Link to post
Share on other sites
In my engine, i use triangle strip for terrain and other certain meshes where you have distinct shared vertices that i can loop through. For meshes loaded from 3ds Max in my case I use triangles because i need different normals and tangents (for normal mapping) per face and not to be shared.

I simply have a big bunch of vertices for the whole model in a VBO which is like a vertex array stored in video RAM. I bind the VBO and call

glDrawArrays(GL_TRIANGLES, 0, number_of_vertices);

so do them all in one go. it may be important to note that my models are split into sub meshes based on textures. So all polygons using texture_1 are considered as another model I draw all these in one go and then move to the next texture_2 and so on. This is the reason I don't use triangle strips because all the polygons using the same texture may not be connected to one another and hence the use of TRIANGLE_STRIP is no good.

EDIT
forgot to add that just because triangles aren't connected doesn't mean you can't use triangle strips, you can eliminate the joining triangles by using degenerate triangles (a triangle that has 2 vertices that are the same, which is discarded by the gpu and not rendered) but in my case it was too difficult to work work out where to use degenerates for an arbitrary mesh.

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!