summaryrefslogtreecommitdiff
path: root/video.cpp
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-03-30 22:30:35 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-03-30 22:30:35 +0200
commitd8a69e6abeea2034c17d84ef74009b137faa06cc (patch)
tree7ed3fbd07adc8328aba71cfb26ffc3eb5ff5ebf7 /video.cpp
Initial commit.
Diffstat (limited to 'video.cpp')
-rw-r--r--video.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/video.cpp b/video.cpp
new file mode 100644
index 0000000..6ebe170
--- /dev/null
+++ b/video.cpp
@@ -0,0 +1,65 @@
+#include "video.h"
+
+#include <GL/gl.h>
+#include <GL/glu.h>
+
+SDL_Surface *video::surface = NULL;
+int video::width = 800;
+int video::height = 600;
+
+void video::init() {
+ SDL_Init(SDL_INIT_VIDEO);
+
+ surface = SDL_SetVideoMode(width, height, 32, SDL_OPENGL);
+
+ glClearColor(0, 0, 0, 0);
+ glClearDepth(1);
+ glDepthFunc(GL_LESS);
+ glEnable(GL_DEPTH_TEST);
+
+ glShadeModel(GL_SMOOTH);
+ glEnable(GL_POINT_SMOOTH);
+
+ glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHT0);
+ //glEnable(GL_COLOR_MATERIAL);
+
+ const float light_ambient[4] = {.2, .2, .2, 1};
+ const float light_diffuse[4] = {1, 1, 1, 1};
+ const float light_specular[4] = {1, 1, 1, 1};
+ glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
+ glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
+
+ //glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
+ //glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0);
+ //glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
+
+ glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
+
+ persp();
+}
+
+void video::free() {
+ SDL_Quit();
+}
+
+void video::persp() {
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+
+ gluPerspective(45, (float)width/(float)height, .1, 1000);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+}
+
+void video::ortho() {
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+
+ glOrtho(0, width, 0, height, 0, 1);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+}