summaryrefslogtreecommitdiff
path: root/mogltk/glbase.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mogltk/glbase.cpp')
-rw-r--r--mogltk/glbase.cpp125
1 files changed, 0 insertions, 125 deletions
diff --git a/mogltk/glbase.cpp b/mogltk/glbase.cpp
deleted file mode 100644
index 5e63e86..0000000
--- a/mogltk/glbase.cpp
+++ /dev/null
@@ -1,125 +0,0 @@
-#include "glbase.h"
-#include "engine.h"
-#include "generic.h"
-#include <SDL.h>
-#include <SDL_opengl.h>
-
-int mogltk::glbase::width, mogltk::glbase::height, mogltk::glbase::inited = 0, mogltk::glbase::twoD = 0;
-SDL_Surface * mogltk::glbase::surface = 0;
-
-int mogltk::glbase::setup(int w, int h, int flags) throw(GeneralException) {
- if (inited) {
- printm(M_WARNING, "mogltk::glbase::setup called twice, ignoring second call...\n");
- return -1;
- }
-
- width = w;
- height = h;
-
- mogltk::engine::setup();
- if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
- throw GeneralException(String("Couldn't initialise Video SubSystem: ") + SDL_GetError());
- }
-
- if (!(surface = SDL_SetVideoMode(width, height, 0, flags | SDL_OPENGL))) {
- throw GeneralException(String("Couldn't set GL mode: ") + SDL_GetError());
- }
-
- float ratio = surface->w;
- ratio /= surface->h;
-
- printm(M_INFO, "Video resolution: %dx%dx%d (ratio = %3.2f)\n", surface->w, surface->h, surface->format->BitsPerPixel, ratio);
- printm(M_INFO, "\n");
- printm(M_INFO, "OpenGL infos\n");
- printm(M_INFO, "------------\n");
- printm(M_INFO, String("Vendor : ") + (char *) glGetString(GL_VENDOR) + "\n");
- printm(M_INFO, String("Renderer : ") + (char *) glGetString(GL_RENDERER) + "\n");
- printm(M_INFO, String("Version : ") + (char *) glGetString(GL_VERSION) + "\n");
- printm(M_INFO, String("Extensions: ") + (char *) glGetString(GL_EXTENSIONS) + "\n");
-
- inited = 1;
-
- glViewport(0, 0, surface->w, surface->h);
-
- glCullFace(GL_BACK);
- glFrontFace(GL_CCW);
- glEnable(GL_CULL_FACE);
-
- glClearColor(0, 0, 0, 0);
- glShadeModel(GL_SMOOTH);
-
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_LEQUAL);
- glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(60.0, ratio, 1.0, 1024.0);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- Flip();
-
- return 0;
-}
-
-int mogltk::glbase::GetWidth(void) {
- return width;
-}
-
-int mogltk::glbase::GetHeight(void) {
- return height;
-}
-
-int mogltk::glbase::GetInited(void) {
- return inited;
-}
-
-void mogltk::glbase::Enter2DMode(void) {
- if (twoD)
- return;
-
- glPushAttrib(GL_ENABLE_BIT);
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_CULL_FACE);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- glOrtho(0.0, width, height, 0.0, 0.0, 1.0);
-
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
-
- twoD = 1;
-}
-
-void mogltk::glbase::Leave2DMode(void) {
- if (!twoD)
- return;
-
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
-
- glPopAttrib();
-
- twoD = 0;
-}
-
-void mogltk::glbase::Flip() {
- SDL_GL_SwapBuffers();
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-}
-
-bool mogltk::glbase::is2D() {
- return twoD;
-}