1
0
Fork 0
blockofighter/src/glapi.cpp

65 lines
1.5 KiB
C++
Raw Normal View History

2014-02-16 14:32:28 +00:00
#include "main.h"
#include "glapi.h"
2015-06-03 12:29:34 +00:00
void setupOpengl(int width, int height) {
// float ratio = (float)width/height;
float ratio = 4.0 / 3.0;
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
glShadeModel(GL_SMOOTH);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
glCullFace(GL_BACK);
glFrontFace(GL_CCW);
glEnable(GL_CULL_FACE);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glClearDepth(1.0);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
glClearColor(0, 0, 0, 0);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
glEnable(GL_COLOR_MATERIAL);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
// Enables lighting with zero initial lights. Lights are created with
// Light-class
glEnable(GL_LIGHTING);
glDisable(GL_LIGHT0);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
float ambient[4] = {0.1, 0.1, 0.1, 1};
2014-02-16 14:32:28 +00:00
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
GLfloat zero[4] = {0, 0, 0, 1};
2015-06-03 12:29:34 +00:00
GLfloat one[4] = {1, 1, 1, 1};
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
// Default frontface lighting
2014-02-16 14:32:28 +00:00
glMaterialfv(GL_FRONT, GL_AMBIENT, one);
glMaterialfv(GL_FRONT, GL_DIFFUSE, one);
2015-06-03 12:29:34 +00:00
GLfloat specular[4] = {2, 2, 2, 1};
2014-02-16 14:32:28 +00:00
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialf(GL_FRONT, GL_SHININESS, 120);
2015-06-03 12:29:34 +00:00
// Never any backface lighting, except ambient
2014-02-16 14:32:28 +00:00
glMaterialfv(GL_BACK, GL_AMBIENT, one);
glMaterialfv(GL_BACK, GL_DIFFUSE, zero);
glMaterialfv(GL_BACK, GL_SPECULAR, zero);
2015-06-03 12:29:34 +00:00
glViewport(0, 0, width, height);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
glDepthFunc(GL_LEQUAL);
2014-02-16 14:32:28 +00:00
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
2015-06-03 12:29:34 +00:00
glEnable(GL_NORMALIZE);
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
2014-02-16 14:32:28 +00:00
2015-06-03 12:29:34 +00:00
gluPerspective(60.0, ratio, 1.0, 1024.0);
2014-02-16 14:32:28 +00:00
glColorMask(true, true, true, true);
2015-06-03 12:29:34 +00:00
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
2014-02-16 14:32:28 +00:00
}