Log in or register to post comments

how to convert .obj to .h

May 23, 2012 - 2:03am #1

i try "https://github.com/HBehrens/obj2opengl/blob/master/obj2opengl.pl" to convert .obj to .h but i don't know how to use
have a detail steps to know how to convert .obj to .h?

Re: how to convert .obj to .h

May 30, 2012 - 2:33am #2

Just in case you're sing Blender to create your models, try using the exporter here

http://ksolek.fm.interia.pl/Blender/

I've used it to change the ImageTragets sample's teapot for another object and so far I've got away with it quite well. I still have to figure out how to apply textures though.

In order to use the data provided by the .h file I had to include it (of course) and then replace the code

[CODE" />
glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,(const GLvoid*) &teapotVertices[0" />);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,(const GLvoid*) &teapotNormals[0" />);
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,(const GLvoid*) &teapotTexCoords[0" />);
[/CODE" />

for

[CODE" />
glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, sizeof(vertex_struct), (const GLfloat*) &vertices[0" />.x);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, sizeof(vertex_struct), (const GLfloat*) &vertices[0" />.nx);
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, sizeof(vertex_struct), (const GLfloat*) &vertices[0" />.u);[/CODE" />

and then replace

[CODE" />
glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*) &teapotIndices[0" />);
[/CODE" />

for

[CODE" />
glDrawElements(GL_TRIANGLES, (faces_count[0" /> * 3), GL_UNSIGNED_SHORT,(const GLvoid*) &indexes[0" />);[/CODE" />

The model I sed needed some basic transformations (scaling, rotating and translating) but for a start it looked good enough :). Next step should be applying textures but for now, I can't help you with it.

I hope it helps.

Log in or register to post comments