diff options
Diffstat (limited to 'mogltk')
-rw-r--r-- | mogltk/glbase.cpp | 67 |
1 files changed, 65 insertions, 2 deletions
diff --git a/mogltk/glbase.cpp b/mogltk/glbase.cpp index 71fcaa0..b2512ca 100644 --- a/mogltk/glbase.cpp +++ b/mogltk/glbase.cpp @@ -4,7 +4,7 @@ #include <SDL.h> #include <SDL_opengl.h> -int mogltk::glbase::width, mogltk::glbase::height, mogltk::glbase::inited = 0; +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) { @@ -25,7 +25,10 @@ int mogltk::glbase::setup(int w, int h, int flags) throw(GeneralException) { throw GeneralException(String("Couldn't set GL mode: ") + SDL_GetError()); } - printm(M_INFO, "Video resolution: %dx%dx%d\n", surface->w, surface->h, surface->format->BitsPerPixel); + 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"); @@ -35,6 +38,27 @@ int mogltk::glbase::setup(int w, int h, int flags) throw(GeneralException) { 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(); + return 0; } @@ -49,3 +73,42 @@ int mogltk::glbase::GetHeight(void) { 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_TEXTURE_2D); + 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(); + + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + + twoD = 1; +} + +void mogltk::glbase::Leave2DMode(void) { + if (!twoD) + return; + + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + + glPopAttrib(); + + twoD = 0; +} |