I'm having a problem with displaying my wavefront obj file using VBO's My fps counter slows down like there is something being drawn but I cannot see anything. Is it a problem with my loader? Or maybe just a simple bug in my VBO rendering code?

I have checked that I am actually loading the data but maybe it's in the wrong order. I used OpenGL profiler and found nothing specious the texture and the VBO and IBO are in the GPU. I did try two different obj files, one of mine and a random one I found on NASA's site both rendered at the same speed(about 60 fps) with nothing on the screen. If you want any output from OpenGL profiler ask me.

BlockRender.cpp http://pastebin.com/3KuuWX9H

Renderer.cpp http://pastebin.com/gDCvi3t7

Relevant snippets of code http://pastebin.com/rTqRzYXL

Sample wavefront obj file http://pastebin.com/qVJ55gwn

  • \$\begingroup\$ Try reversing the triangle winding order, maybe you are not seeing anything because of backface culling \$\endgroup\$ – user13213 May 28 '12 at 21:46
  • \$\begingroup\$ I disabled backface culling with no success. I'll also try to change my winding order but that shouldn't make a difference with backface culling off. \$\endgroup\$ – ceriosNerd May 28 '12 at 22:25

Some observations:

  • First, there's no error checking in the code.

  • The obj loading seems incorrect.

    The vertices are copied into mesh.vertices (l. 212-214 in BlockRenderer). Using the DefaultCube, mesh.vertices contains 12*3 vertices, and the index buffer 36 ints.

    Problem seems that the indices reference into the original verts array and not into mesh.vertices. BlockRenderer.cpp l.216ff should IMO read like

    mesh.indices.push_back(3*i+0); // not faces[i].v[0]
    mesh.indices.push_back(3*i+1); // not faces[i].v[1]
    mesh.indices.push_back(3*i+2); // not faces[i].v[2]
  • However, when using indices, I'd expect the original vertices to stay untouched, and the faces defined by the indices. Then, the vertex buffer must contain 24 floats defining 8 vertices that define the cube's corners. For building the vertex buffer, the code needs to iterate over verts and just push the vertices into mesh.vertices; the corresponding index buffer then is built using the original code.

  • You're sure the mesh is a triangle strip?

  • Why not using an asset loading library?

  • \$\begingroup\$ Thanks for taking the time to respond, I have taken time to add some more OpenGL error checking since I have posted the question. Now on the subject of the obj loading I have implmented your sugestions I think with nothing still loading on the screen. And on the subject of the third part library, I decided to roll my own for the learning experience. Here is my new post process code: pastebin.com/rnmNFhHW \$\endgroup\$ – ceriosNerd May 29 '12 at 13:19
  • \$\begingroup\$ Be sure to understand what the code does. Now the indices are such that they would be correct using your original code, but mesh.vertices now contains the first vertex of each face. This doesn't look like making much sense, huh? Check an introduction to the topic. \$\endgroup\$ – Stefan Hanke May 29 '12 at 14:41
  • \$\begingroup\$ Oh ok I understand now, But another question if you don't mind. Don't you need 24 vertices for proper normals to work? Or am i completely wrong there also? Also wouldn't I at least see some garbage displayed if my vertices ore wrong? I'm reading over that introduction now. I'll mark this as the answer when I get done reading. \$\endgroup\$ – ceriosNerd May 29 '12 at 14:49
  • \$\begingroup\$ Another tidbit of info, I tried using draw arrays instead with my original code and nothing showed either, wouldn't of that for sure displayed something? \$\endgroup\$ – ceriosNerd May 29 '12 at 15:06
  • \$\begingroup\$ Sorry to spam your StackExchange but even immediate mode doesn't draw anything. pastebin.com/AH6QEVus \$\endgroup\$ – ceriosNerd May 29 '12 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.