[FIXED]Open simple obj file -> nothing

Started by
15 comments, last by rXpSwiss 9 years, 6 months ago

Can you share the code where you create the array? How are you using the faces data from the file?

This. You are sending the 8 vertices of a cube to GL, but drawing triangles that's not going to work (cube has 6 faces that are quads = 12 total triangles). You need to make a GL_ELEMENT_ARRAY buffer out of the faces section of the obj file data.

If you haven't already seen this online book, stop now and read: http://arcsynthesis.org/gltut/

New C/C++ Build Tool 'Stir' (doesn't just generate Makefiles, it does the build): https://github.com/space222/stir

Advertisement

scratch all of that. Just realize something... I feel stupide

I everyone, after reviewing my code and your advice I finally have a semi-working thing :)

Why do I say semi ? Because the model is loaded and I see something but there is an issue : ALL polygon seem to me drawn from the origin point.

2vs3lsh.png

It is supposed to be Suzanne (Blender monkey head).

What could do that ?

Draw code :


void draw(){

	//matrix uniform

	//pass it to shader
	GLuint mID = glGetUniformLocation(programHandle, "m");
	glUniformMatrix4fv(mID, 1, GL_FALSE, &model[0][0]);

	GLuint vID = glGetUniformLocation(programHandle, "v");
	glUniformMatrix4fv(vID, 1, GL_FALSE, &view[0][0]);

	GLuint pID = glGetUniformLocation(programHandle, "p");
	glUniformMatrix4fv(pID, 1, GL_FALSE, &projection[0][0]);

	GLuint itID = glGetUniformLocation(programHandle, "invTransp");
	glUniformMatrix4fv(itID, 1, GL_FALSE, &glm::transpose(glm::inverse(model))[0][0]);


	glClear(GL_COLOR_BUFFER_BIT);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,vboIndex);
	std::vector<GLuint>* order = new std::vector<GLuint>;
	obj.getVertexOrder(order);
	//glDisable(GL_CULL_FACE);
	//glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	//glDisable(GL_LIGHTING);
	//glDisable(GL_TEXTURE_2D);
	
	glDrawElements(GL_POLYGON, order->size(), GL_UNSIGNED_INT, 0);
	glFlush();
}

Thank you for your help :) I very new to opengl and it is not easy to search when that happens if I don't know how this is called xD

GL_POLYGON draws a *single* polygon. Try hitting 'triangulate' in blender before exporting to obj and rendering GL_TRIANGLES.

New C/C++ Build Tool 'Stir' (doesn't just generate Makefiles, it does the build): https://github.com/space222/stir

I did just what you said it helped a bit. I can see the face now but it is not hole/it is like the faces subtract each other.

2dacbpd.png

What else should I try ?

Have you set up the depth buffer?

Needs to be enabled, cleared each frame, and the most common clear value is 1.0.

Here's a wiki page about is: http://www.opengl.org/wiki/Depth_Buffer

edit: also obj indices start at 1, need to adjust to 0 for gl elements if you haven't already.

New C/C++ Build Tool 'Stir' (doesn't just generate Makefiles, it does the build): https://github.com/space222/stir

You were right it was the depth buffer. Thank you, I thought it was enable by default. :)

This topic is closed to new replies.

Advertisement