Original Post
Hello. I've been through some nehe tutorials, but I still consider myself really new to OpenGL. I'm loading a 3d model/mesh and rendering it in OpenGL. I'm using the .obj loader I found by justinrwalsh in this thread: justinrwalsh's source code from that thread The cube mesh is also from that thread(in the zip). The penguin is a mesh I created, and exported to .obj format. 1) I'm not sure how I should be rendering the mesh. I think I just use a list of vertices (multiples of 3) using GL_TRIANGLES, but it's not working. So far only the point rendering mode is appearing right. All of my attempts to use GL_TRIANGLES, or anything besides points all render incorrectly. I think I'm using the wrong vertices order, but how do I figure out the right order? I think if it did render 'correct' , it would be the silloute of the mesh in white based on my current settings. ModeTriangles_Group *appears* to be rendering the cube correctly, it has a sillouete of the cube. But with the penguin mesh, this renders nothing in this mode! ModeTriangles_Broke is used in the screenshot. It looks as if it's not using vertices that make a face, but almost random vertices. ModePoints Correct, but it should be since it doesn't matter what order the vertices are in for this mode? If the below images don't work, here's another url: mesh problems penguin. (I tested regular and triangulate )
justinwalsh's cube:
This is my rendering code: 2) A strange thing when running this program, if I click on other windows I loose all my icons on windows, System tray's window list has no icons, window titlebars have strange colors. The title bars even became partly transparent, then stopped updating. (Meaning the titlebars have artifacts on them ) Note: this only happened when I used glBegin( GL_TRIANGLES ); and not glBegin( GL_POLYGON ); I found out I can 'fix' the icons/etc. if I run the program again, don't change model, and quit. The problem only happens if change the model, while using GL_TRIANGLES. ( ModeTriangles_Broke ) Does that mean there's some pointer clean up issue in the code? Looking at the code, I think it cleans up correctly if LoadObj() is called repeatedly? Even with a pointer problem, I thought that would cause a crash, and not be able to mess with the OS's icons and drawing on objects that I had no control over. Here's what I'm using to switch models: -- thanks
justinwalsh's cube:
This is my rendering code:
void renderGL(void)
{
//clear the screen and the depth buffer
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
//reset the view
glLoadIdentity();
//translate world
glTranslatef( 0.0f, 0.0f, world_z ); //default: -12ish
//rotate y-axis
glRotatef(world_rotate_y, 0.0f, 1.0f, 0.0f);//rotate on y-axis
//rotate x-axis
glRotatef(world_rotate_x, 1.0f, 0.0f, 0.0f);//rotate on x-axis
if(render_mode == ModeTriangles_Broke)
{
//render mesh using triangles but it's not right
//both wrong, must need to draw GL_TRIANGLES using every 3 verts ?
glBegin( GL_TRIANGLES );
//glBegin( GL_POLYGON ); or GL_TRIANGLES?
for( int i = 0; i < Modeldata.NumVertex; i++ )
{
glVertex3f(
Modeldata.VertexArray.X,
Modeldata.VertexArray.Y,
Modeldata.VertexArray.Z );
}
glEnd();
}else if ( render_mode == ModeTriangles_Group)
{
glBegin( GL_TRIANGLES );
//render mesh using triangles, or faces
for(int i = 0; i < Modeldata.NumTriangle; i++)
{
/*
glVertex3f(
Modeldata.TriangleArray.Vertex[0],
Modeldata.TriangleArray.Vertex[1],
Modeldata.TriangleArray.Vertex[2] ); */
glVertex3f(
Modeldata.VertexArray[Modeldata.TriangleArray.Vertex[0]].X,
Modeldata.VertexArray[Modeldata.TriangleArray.Vertex[0]].Y,
Modeldata.VertexArray[Modeldata.TriangleArray.Vertex[0]].Z );
glVertex3f(
Modeldata.VertexArray[Modeldata.TriangleArray.Vertex[1]].X,
Modeldata.VertexArray[Modeldata.TriangleArray.Vertex[1]].Y,
Modeldata.VertexArray[Modeldata.TriangleArray.Vertex[1]].Z );
glVertex3f(
Modeldata.VertexArray[Modeldata.TriangleArray.Vertex[2]].X,
Modeldata.VertexArray[Modeldata.TriangleArray.Vertex[2]].Y,
Modeldata.VertexArray[Modeldata.TriangleArray.Vertex[2]].Z );
}
glEnd();
} else if (render_mode == ModePoints)
{
//render mesh using points
glBegin( GL_POINTS );
for( int i = 0; i < Modeldata.NumVertex; i++ )
{
glVertex3f(
Modeldata.VertexArray.X,
Modeldata.VertexArray.Y,
Modeldata.VertexArray.Z );
}
glEnd();
}
SDL_GL_SwapBuffers();
}
//load: his cube
case SDLK_1:
//load model:
ModelLoader.LoadObj("ObjLoader/customCube.obj");
Modeldata = ModelLoader.ReturnObj();
break;
//load: my penguin
case SDLK_2:
ModelLoader.LoadObj("jake/penguin.obj");
Modeldata = ModelLoader.ReturnObj();
break;