From d8a69e6abeea2034c17d84ef74009b137faa06cc Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Wed, 30 Mar 2011 22:30:35 +0200 Subject: Initial commit. --- video.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 video.cpp (limited to 'video.cpp') 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 +#include + +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(); +} -- cgit v1.2.3