diff --git a/Engine.cc b/Engine.cc index b1a6051..a48b913 100644 --- a/Engine.cc +++ b/Engine.cc @@ -623,7 +623,7 @@ Engine::Object::Object(bool is_static, OdeWorld & world, m_is_visible = true; m_scale = 1.0f; m_is_scaled = false; - m_display_list = -1; + m_display_list = 0; m_display_list_refcnt = NULL; m_ode_object = world.createObject( geom_type == OdeWorld::PLANE ? false : is_static, @@ -713,6 +713,8 @@ void Engine::Object::render() } if (!valid) return; + if (m_display_list > 0) + glDeleteLists(m_display_list, 1); m_display_list = glGenLists(1); glNewList(m_display_list, GL_COMPILE); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, m_color); @@ -720,7 +722,39 @@ void Engine::Object::render() /* TODO: finish */ switch (m_geom_type) { - case OdeWorld::CUBE: + case OdeWorld::CUBE: { + struct { float norm[3]; float verts[4][3]; } sides[] = { + { {1, 0, 0}, /* right */ + { {1, -1, -1}, {1, 1, -1}, {1, 1, 1}, {1, -1, 1} } }, + { {-1, 0, 0}, /* left */ + { {-1, 1, -1}, {-1, -1, -1}, {-1, -1, 1}, {-1, 1, 1} } }, + { {0, 1, 0}, /* back */ + { {1, 1, -1}, {-1, 1, -1}, {-1, 1, 1}, {1, 1, 1} } }, + { {0, -1, 0}, /* front */ + { {-1, -1, -1}, {1, -1, -1}, {1, -1, 1}, {-1, -1, 1} } }, + { {0, 0, 1}, /* top */ + { {-1, -1, 1}, {1, -1, 1}, {1, 1, 1}, {-1, 1, 1} } }, + { {0, 0, -1}, /* bottom */ + { {1, -1, -1}, {-1, -1, -1}, {-1, 1, -1}, {1, 1, -1} } } + }; + glBegin(GL_QUADS); + float width = (*m_args)[0]; + float depth = (*m_args)[1]; + float height = (*m_args)[2]; + for (unsigned int s = 0; + s < (sizeof(sides)/sizeof(sides[0])); + s++) + { + glNormal3fv(sides[s].norm); + for (int v = 0; v < 4; v++) + { + glVertex3f(sides[s].verts[v][0] * width / 2.0, + sides[s].verts[v][1] * depth / 2.0, + sides[s].verts[v][2] * height / 2.0); + } + } + glEnd(); + } break; case OdeWorld::SPHERE: gluSphere(quad, (*m_args)[0], 16, 8);