Use openGL lightings — still kind of bad for now
This commit is contained in:
parent
36bc8e1b5c
commit
56d8e22f21
2 changed files with 50 additions and 23 deletions
|
@ -21,21 +21,45 @@ GlutRender::GlutRender() {
|
|||
void GlutRender::init(int* argc, char** argv,
|
||||
int wid, int hei, const char* win_name)
|
||||
{
|
||||
glutInit(argc, argv);
|
||||
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
|
||||
glutInitWindowSize(wid, hei);
|
||||
glutCreateWindow(win_name);
|
||||
glutInit(argc, argv);
|
||||
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
|
||||
glutInitWindowSize(wid, hei);
|
||||
glutCreateWindow(win_name);
|
||||
|
||||
glutDisplayFunc(display_handle);
|
||||
glutReshapeFunc(reshape_handle);
|
||||
// ==== Callbacks ====
|
||||
glutDisplayFunc(display_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);
|
||||
// ==== Lighting ====
|
||||
GLfloat light0_pos[] = {2., 10., 2.};
|
||||
GLfloat light0_ambient[] = {0., 0., 0., 1.};
|
||||
GLfloat light0_diffuse[] = {1., 1., 1., 1.};
|
||||
GLfloat light0_specular[] = {1., 1., 1., 1.};
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light0_pos);
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular);
|
||||
|
||||
GLfloat light_ambient[] = {.2, .2, .2, 1.};
|
||||
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, light_ambient);
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glShadeModel(GL_SMOOTH); // Enable smooth shading
|
||||
|
||||
GLfloat material_specular[] = {1., 1., 1., 1.};
|
||||
GLfloat material_emission[] = {0., 0., 0., 1.};
|
||||
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material_specular);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, material_emission);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
|
||||
// ==== Misc ====
|
||||
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);
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||
}
|
||||
|
||||
void GlutRender::cleanup() {
|
||||
|
|
|
@ -24,17 +24,6 @@ class GlutRender {
|
|||
|
||||
void set_idle_func(void (*func)(void));
|
||||
|
||||
private: //meth
|
||||
GlutRender();
|
||||
|
||||
void display_mesh(const Mesh& mesh) const;
|
||||
|
||||
protected:
|
||||
void reshape(int wid, int hei);
|
||||
void display();
|
||||
|
||||
static void reshape_handle(int wid, int hei);
|
||||
static void display_handle();
|
||||
private:
|
||||
struct SurfaceDetails {
|
||||
SurfaceDetails(ImplicitSurface* surf, const Cuboid& box):
|
||||
|
@ -48,6 +37,20 @@ class GlutRender {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
private: //meth
|
||||
GlutRender();
|
||||
|
||||
void display_mesh(Mesh& mesh) const;
|
||||
|
||||
protected:
|
||||
void reshape(int wid, int hei);
|
||||
void display();
|
||||
|
||||
static void reshape_handle(int wid, int hei);
|
||||
static void display_handle();
|
||||
|
||||
private: //attr
|
||||
std::function<double()> rand_color;
|
||||
|
||||
std::set<Mesh*> meshes;
|
||||
|
|
Loading…
Reference in a new issue