Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-11-11 19:11:57 +0000
committerStijn Buys <ingar@osirion.org>2008-11-11 19:11:57 +0000
commit773c1bafe0f1d8b706e0f72e235f8466e7a9ccf5 (patch)
treeab4b3058f436a4e4c54618f132a9179ee40e330c /src/render/state.cc
parent3082cb197fb6af7d069f9ad211ff6ea5657d924a (diff)
cleanups
Diffstat (limited to 'src/render/state.cc')
-rw-r--r--src/render/state.cc91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/render/state.cc b/src/render/state.cc
new file mode 100644
index 0000000..41ef158
--- /dev/null
+++ b/src/render/state.cc
@@ -0,0 +1,91 @@
+/*
+ render/state.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#include "render/state.h"
+#include "render/gl.h"
+
+namespace render {
+
+int State::render_width;
+int State::render_height;
+float State::render_aspect;
+
+void State::init(int width, int height)
+{
+ resize(width, height);
+}
+
+void State::shutdown()
+{
+}
+
+void State::resize(int width, int height)
+{
+ render_width = width;
+ render_height = height;
+
+ render_aspect = (float) width / (float) height;
+
+ clear();
+}
+
+void State::clear()
+{
+ // set viewport
+ gl::viewport(0, 0, render_width, render_height);
+
+ // set clear color
+ gl::clearcolor(0.0f, 0.0f, 0.0f, 1.0f);
+
+ // load identity matrices
+ gl::matrixmode(GL_MODELVIEW);
+ gl::loadidentity();
+
+ gl::matrixmode(GL_MODELVIEW);
+ gl::loadidentity();
+
+ // shading model: Gouraud (smooth, the default)
+ gl::shademodel(GL_SMOOTH);
+ //gl::shademodel(GL_FLAT);
+
+ // lighting settings for the default light GL_LIGHT0
+ GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0 };
+ GLfloat ambient_light[] = { 0.01f, 0.01f, 0.01f, 1.0f };
+ GLfloat diffuse_light[] = { 0.2f, 0.2f, 0.2f, 1.0f };
+ GLfloat specular_light[] = { 0.2f, 0.2f, 0.2f, 1.0f };
+
+ glLightfv(GL_LIGHT0, GL_POSITION, light_position);
+ glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_light);
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light);
+ glLightfv(GL_LIGHT0, GL_SPECULAR, specular_light);
+
+ // GL_LIGHT0 is always enabled
+ gl::enable(GL_LIGHT0);
+
+ // color tracking
+ glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
+
+ // material settings
+ GLfloat specular_reflectance[] = { 0.2f, 0.2f, 0.2f, 1.0f };
+ glMaterialfv(GL_FRONT, GL_SPECULAR, specular_reflectance);
+ glMateriali(GL_FRONT, GL_SHININESS, 128); // shininess 1-128
+
+ // alpha blending function
+ gl::blendfunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ gl::disable(GL_LIGHTING);
+ gl::disable(GL_COLOR_MATERIAL);
+
+ gl::cullface(GL_BACK);
+ gl::frontface(GL_CCW);
+ gl::disable(GL_CULL_FACE);
+ gl::disable(GL_DEPTH_TEST);
+ gl::disable(GL_BLEND);
+
+ gl::disable(GL_TEXTURE_2D);
+}
+
+} // namespace render