Added dislay list support for 3D models
This commit is contained in:
parent
6209e91c28
commit
c4a0218d62
3 changed files with 31 additions and 0 deletions
|
@ -112,6 +112,7 @@ int main(int argc, char** argv)
|
||||||
raptor.assign_texture(raptor_texture);
|
raptor.assign_texture(raptor_texture);
|
||||||
raptor.set_scaling(0.01,0.01,0.01);
|
raptor.set_scaling(0.01,0.01,0.01);
|
||||||
raptor.set_rotation(-90,1,0,0);
|
raptor.set_rotation(-90,1,0,0);
|
||||||
|
raptor.prepare_displaylist();
|
||||||
|
|
||||||
|
|
||||||
glutTimerFunc(50,update_angle,0);
|
glutTimerFunc(50,update_angle,0);
|
||||||
|
|
|
@ -30,10 +30,23 @@ Model3D::~Model3D()
|
||||||
delete(face_textures);
|
delete(face_textures);
|
||||||
delete(normals);
|
delete(normals);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (has_displaylist)
|
||||||
|
{
|
||||||
|
glDeleteLists(display_list_index,1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model3D::draw_model()
|
void Model3D::draw_model()
|
||||||
{
|
{
|
||||||
|
if (has_displaylist)
|
||||||
|
{
|
||||||
|
glCallList(display_list_index);
|
||||||
|
return; // Executing the regular draw calls is unnecessary
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there is no display list available, draw each triangles and texture them if necessary.
|
||||||
|
|
||||||
if (is_textured)
|
if (is_textured)
|
||||||
{
|
{
|
||||||
glEnable(GL_ALPHA_TEST);
|
glEnable(GL_ALPHA_TEST);
|
||||||
|
@ -84,6 +97,17 @@ void Model3D::draw_model()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Model3D::prepare_displaylist()
|
||||||
|
{
|
||||||
|
display_list_index = glGenLists(1);
|
||||||
|
|
||||||
|
glNewList(display_list_index,GL_COMPILE);
|
||||||
|
draw_model();
|
||||||
|
glEndList();
|
||||||
|
|
||||||
|
has_displaylist = true;
|
||||||
|
}
|
||||||
|
|
||||||
bool Model3D::load_ascii_off_file(const std::string& file_name)
|
bool Model3D::load_ascii_off_file(const std::string& file_name)
|
||||||
{
|
{
|
||||||
std::fstream file_stream(file_name, std::ios_base::in);
|
std::fstream file_stream(file_name, std::ios_base::in);
|
||||||
|
|
|
@ -26,9 +26,13 @@ public:
|
||||||
void set_scaling(float x_scale, float y_scale, float z_scale);
|
void set_scaling(float x_scale, float y_scale, float z_scale);
|
||||||
void set_rotation(float angle, float x, float y, float z);
|
void set_rotation(float angle, float x, float y, float z);
|
||||||
|
|
||||||
|
/// Draws the model, using a display list if available.
|
||||||
void draw_model();
|
void draw_model();
|
||||||
|
/// Sets up an OpenGL display list for the model
|
||||||
|
void prepare_displaylist();
|
||||||
|
|
||||||
bool is_textured;
|
bool is_textured;
|
||||||
|
bool has_displaylist = false;
|
||||||
private:
|
private:
|
||||||
uint32_t vertex_count;
|
uint32_t vertex_count;
|
||||||
uint32_t face_count;
|
uint32_t face_count;
|
||||||
|
@ -51,6 +55,8 @@ private:
|
||||||
Vec3f scaling{};
|
Vec3f scaling{};
|
||||||
Vec3f rotation_axis{};
|
Vec3f rotation_axis{};
|
||||||
float rotation_angle{};
|
float rotation_angle{};
|
||||||
|
|
||||||
|
GLuint display_list_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue