4

I most recently had great progress in getting Vertex buffer objects to work. So I moved on to Element arrays and I figured with such implemented I could then load vertices and face data from an obj.

I'm not too good at reading files in c++ so I wrote a python doc to parse the obj and write 2 separate txts to give me a vertex array and face indices and pasted them directly in my code. Which is like 6000 lines but it works (without compiling errors). And Here's what it looks like

.

I think they're wrong. I'm not sure. The order of the vertices and faces aren't changed just extracted from the obj because I don't have normals or textures working for buffer objects yet. I kinda do if you look at the cube but not really.

Heres the render code

void Mesh_handle::DrawTri(){
    glBindBuffer(GL_ARRAY_BUFFER,vertexbufferid);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,elementbufferid);
    int index1=glGetAttribLocation(bound_program,"inputvertex");
    int index2=glGetAttribLocation(bound_program,"inputcolor");
    int index3=glGetAttribLocation(bound_program,"inputtexcoord");

    glEnableVertexAttribArray(index1);
    glVertexAttribPointer(index1,3,GL_FLOAT,GL_FALSE,9*sizeof(float),0);

    glEnableVertexAttribArray(index2);
    glVertexAttribPointer(index2,4,GL_FLOAT,GL_FALSE,9*sizeof(float),(void*)(3*sizeof(float)));

    glEnableVertexAttribArray(index3);
    glVertexAttribPointer(index3,2,GL_FLOAT,GL_FALSE,9*sizeof(float),(void*)(7*sizeof(float)));

    glDrawArrays(GL_TRIANGLE_STRIP,0,elementcount);
    //glDrawElements(GL_TRIANGLE_STRIP,elementcount,GL_UNSIGNED_INT,0);
}

My python parser which just writes the info into a file: source

The object is Ezreal from League of Legends

I'm not sure if I'm reading the faces wrong or if their not even what I thought they were. Am I suppose to use GL_TRIANGLE_STRIP or something else. Any hints or request more info.

2
  • 2
    +1 for Modern Art. The top of this...thing... actually looks like Ezrael's hairstyle, if you use your imagination xD Commented Aug 28, 2012 at 10:02
  • Since your problem is almost certainly in your .obj code, rather than your rendering code, why don't you show us where your actual problem is? Commented Aug 28, 2012 at 10:22

3 Answers 3

4

Indices in obj-files are 1 based, so you have to subtract 1 from all indices in order to use them with OpenGL.

Sign up to request clarification or add additional context in comments.

2 Comments

Nope, Unless you want a new pick it looks pretty much the same. Am I using the correct primitive?
I took one from all of them. I went searching and I found 1's but I can't find any 0's. Idk.
2

First, as Andreas stated, .obj files use 1-based indices, so you need to convert them to 0-based indices.

Second:

glDrawArrays(GL_TRIANGLE_STRIP,0,elementcount);
//glDrawElements(GL_TRIANGLE_STRIP,elementcount,GL_UNSIGNED_INT,0);

Unless you did some special work to turn the face list you were given in your .obj file into a triangle strip, you don't have triangle strips. You should be rendering GL_TRIANGLES, not strips.

13 Comments

OK so objs work in triangles I wasn't sure. Thanks a lot. I forgot that once I had the faces changed I needed to drawelements. I don't know what I was thinking with drawarrays it doesn't even use the indexes XD. minus one from faces, use triangles and draw elements. YAY! its so kaleidoscope O.o
@Kaliber64: actually, objs can have any kind of polygons, in general you have to triangulate the data first.
Ya I've figured a bunch out now. I found one for Quads but what is it if there are only 2 numbers per face? lines?
I rendered it as lines and it worked.Turns out I can't get blender to output objs with triangles or quads. Just wireframes. Max nor Maya will load the obj. says nothing to load :S.
Just compared the exported .obj with Blender indices turned on, and it doesn't match
|
0

From the image for sure your verticies are messed up. It looks like you specified a stride of 9*sizeof(float) in your glGetAttribLocation but from what I can tell from your code your array is tightly packed.

glEnableVertexAttribArray(index1);
glVertexAttribPointer(index1,3,GL_FLOAT,GL_FALSE,0,0);

Also remove stride from color/texture coords.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.