Make basic glut renderer work
This commit is contained in:
parent
739d1da36f
commit
c179b1049f
1 changed files with 36 additions and 14 deletions
|
@ -15,15 +15,20 @@ void GlutRender::init(int* argc, char** argv,
|
||||||
int wid, int hei, const char* win_name)
|
int wid, int hei, const char* win_name)
|
||||||
{
|
{
|
||||||
glutInit(argc, argv);
|
glutInit(argc, argv);
|
||||||
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
|
glutInitDisplayMode(GLUT_DOUBLE);
|
||||||
glutInitWindowSize(wid, hei);
|
glutInitWindowSize(wid, hei);
|
||||||
glutCreateWindow(win_name);
|
glutCreateWindow(win_name);
|
||||||
|
|
||||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
|
||||||
glShadeModel(GL_FLAT);
|
|
||||||
|
|
||||||
glutDisplayFunc(display_handle);
|
glutDisplayFunc(display_handle);
|
||||||
glutReshapeFunc(reshape_handle);
|
glutReshapeFunc(reshape_handle);
|
||||||
|
|
||||||
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Background color
|
||||||
|
glClearDepth(1.0f); // Set background depth to farthest
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glDepthFunc(GL_LEQUAL);
|
||||||
|
glShadeModel(GL_SMOOTH); // Enable smooth shading
|
||||||
|
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlutRender::cleanup() {
|
void GlutRender::cleanup() {
|
||||||
|
@ -38,29 +43,46 @@ void GlutRender::remove_mesh(const Mesh* mesh) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlutRender::run() {
|
void GlutRender::run() {
|
||||||
|
glutMainLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlutRender::reshape(int wid, int hei) {
|
void GlutRender::reshape(int wid, int hei) {
|
||||||
glViewport(0, 0, (GLsizei) wid, (GLsizei) hei);
|
if (hei == 0)
|
||||||
glMatrixMode(GL_PROJECTION);
|
hei = 1;
|
||||||
glLoadIdentity();
|
GLfloat aspect = (GLfloat)wid / (GLfloat)hei;
|
||||||
gluOrtho2D(0.0, (GLdouble) wid, 0.0, (GLdouble) hei);
|
|
||||||
|
glViewport(0, 0, wid, hei);
|
||||||
|
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glLoadIdentity();
|
||||||
|
// Enable perspective projection with fovy, aspect, zNear and zFar
|
||||||
|
gluPerspective(45.0f, aspect, 0.1f, 100.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlutRender::display() {
|
void GlutRender::display() {
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
|
||||||
for(const Mesh* mesh: meshes) {
|
for(const Mesh* mesh: meshes) {
|
||||||
|
glLoadIdentity();
|
||||||
|
glTranslatef(.0f, .0f, -6.0f);
|
||||||
|
|
||||||
const std::vector<Point>& points = mesh->get_vertices();
|
const std::vector<Point>& points = mesh->get_vertices();
|
||||||
|
|
||||||
|
glBegin(GL_TRIANGLES);
|
||||||
for(const Face& face: mesh->get_faces()) {
|
for(const Face& face: mesh->get_faces()) {
|
||||||
const Point& p0 = face.pt(0, points),
|
const Point& p0 = face.pt(0, points),
|
||||||
p1 = face.pt(2, points),
|
p1 = face.pt(1, points),
|
||||||
p2 = face.pt(2, points);
|
p2 = face.pt(2, points);
|
||||||
glBegin(GL_TRIANGLES);
|
glColor3f(1.0f, 1.0f, 0.0f);
|
||||||
glVertex3d(p0[0], p0[1], p0[2]);
|
glVertex3f(p0[0], p0[1], p0[2]);
|
||||||
glVertex3d(p1[0], p1[1], p1[2]);
|
glVertex3f(p1[0], p1[1], p1[2]);
|
||||||
glVertex3d(p2[0], p2[1], p2[2]);
|
glVertex3f(p2[0], p2[1], p2[2]);
|
||||||
glEnd();
|
|
||||||
}
|
}
|
||||||
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glutSwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlutRender::reshape_handle(int wid, int hei) {
|
void GlutRender::reshape_handle(int wid, int hei) {
|
||||||
|
|
Loading…
Reference in a new issue