Use openGL lightings — still kind of bad for now

This commit is contained in:
Théophile Bastian 2018-02-13 14:47:51 +01:00
parent 36bc8e1b5c
commit 56d8e22f21
2 changed files with 50 additions and 23 deletions

View file

@ -26,16 +26,40 @@ void GlutRender::init(int* argc, char** argv,
glutInitWindowSize(wid, hei); glutInitWindowSize(wid, hei);
glutCreateWindow(win_name); glutCreateWindow(win_name);
// ==== Callbacks ====
glutDisplayFunc(display_handle); glutDisplayFunc(display_handle);
glutReshapeFunc(reshape_handle); glutReshapeFunc(reshape_handle);
// ==== 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 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Background color
glClearDepth(1.0f); // Set background depth to farthest glClearDepth(1.0f); // Set background depth to farthest
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
glShadeModel(GL_SMOOTH); // Enable smooth shading
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
} }
void GlutRender::cleanup() { void GlutRender::cleanup() {

View file

@ -24,17 +24,6 @@ class GlutRender {
void set_idle_func(void (*func)(void)); 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: private:
struct SurfaceDetails { struct SurfaceDetails {
SurfaceDetails(ImplicitSurface* surf, const Cuboid& box): 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::function<double()> rand_color;
std::set<Mesh*> meshes; std::set<Mesh*> meshes;