Interpreting a Wavefront Obj...

just skimming over the thread it seems a lot of ground has been covered. Could you sorta recap your current dilemma for us?

“glDrawElements is still getting the vertices data from array tho (using glVertexPointer) ?”

Third last post …

:frowning: :frowning: :frowning:

I tried what k_szczech said, but to no avail :frowning:

Here’s the code, can anyone see where I’ve gone wrong ?

void DrawFlippinSquare()
{
float triangle1[] = {
-0.5f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.5f, 0.5f, 0.0f,
-0.5f, 0.5f, 0.0f
};

float indexArray[6] = {0, 1, 2, 2, 3, 0};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glColor4f(0.0f, 0.0f, 1.0f, 1.0f);		
glVertexPointer(3, GL_FLOAT, 0, triangle1);
	
glDrawElements(GL_TRIANGLES, 6, GL_FLOAT, indexArray);

}

Works perfectly with glDrawArrays(GL_TRIANGLE_STRIP, 0, 6);

but not glDrawElements :frowning:

void DrawFlippinSquare(){

float verts[] = {
-0.5f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.5f, 0.5f, 0.0f,
};

float indexArray[6] = {0, 1, 2, 2, 3, 0};
glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
glVertexPointer(3, GL_FLOAT, verts);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawElements(GL_TRIANGLES, 6, GL_FLOAT, indexArray);
}

You had a vertex duplicated, which lead to a degenerate triangle. Remember that each vertex should be unique when using elements. You create a unique set of vertices, then just index them for your primitives, whatever they may be :slight_smile: .

And the index array should be one of

GL_UNSIGNED_BYTE,
GL_UNSIGNED_SHORT,
GL_UNSIGNED_INT.

Almost slipped past me, but it’s is in the docs.

You should read the docs carefully, and double-check your code, before you post :wink:

Yeah, I changed it too “GL_UNSIGNED_BYTE” and it works now :smiley:

“You had a vertex duplicated” … Which ? they were all unique ?

Anyhow, it’s all good now…

Before I leave, must say a big thanks to everyone who helped… :slight_smile:

Thanks all!!! :lol: