diff options
Diffstat (limited to 'mogltk')
-rwxr-xr-x | mogltk/Makefile | 16 | ||||
-rw-r--r-- | mogltk/engine.cpp | 24 | ||||
-rw-r--r-- | mogltk/glbase.cpp | 125 | ||||
-rw-r--r-- | mogltk/glfont.cpp | 110 | ||||
-rw-r--r-- | mogltk/gltexture.cpp | 85 |
5 files changed, 0 insertions, 360 deletions
diff --git a/mogltk/Makefile b/mogltk/Makefile deleted file mode 100755 index 4e99e89..0000000 --- a/mogltk/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/make -f - -CPPFLAGS=-Wall -g -O3 -mcpu=i686 -Werror -I../includes -DHAVE_ZLIB `sdl-config --cflags` -CXX=g++ - -OBJECTS = glbase.o engine.o gltexture.o glfont.o -TARGET = mogltk.a - -all: ${TARGET} - -mogltk.a: ${OBJECTS} - ar -r mogltk.a ${OBJECTS} - ranlib mogltk.a - -clean: - rm -f *.o ${TARGET} compil.c diff --git a/mogltk/engine.cpp b/mogltk/engine.cpp deleted file mode 100644 index ff40514..0000000 --- a/mogltk/engine.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include <SDL.h> -#include "engine.h" -#include "generic.h" - -int mogltk::engine::inited = 0; - -int mogltk::engine::setup() throw(GeneralException) { - if (inited) { - printm(M_WARNING, "mogltk::engine::startup() called twice, ignoring second call.\n"); - return -1; - } - if (SDL_Init(0) < 0) { - throw GeneralException("Unable to start SDL base system"); - } - atexit(SDL_Quit); - - inited = 1; - - return 0; -} - -int mogltk::engine::GetInited() { - return inited; -} 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; -} diff --git a/mogltk/glfont.cpp b/mogltk/glfont.cpp deleted file mode 100644 index 82058c8..0000000 --- a/mogltk/glfont.cpp +++ /dev/null @@ -1,110 +0,0 @@ -#include "glbase.h" -#include "glfont.h" -#include "Input.h" - -Uint8 prescale2[4] = { 0, 85, 170, 255 }, prescale3[8] = { 0, 36, 72, 109, 145, 182, 218, 255 }; - -mogltk::font::font(const String & file) { - Input ffont(file); - int i; - -#ifdef HAVE_ZLIB - ffont.SetZ(); -#endif - - ffont.read(&nbentries, 2); - ffont.read(&flags, 1); - ffont.read(&maxX, 1); - ffont.read(&maxY, 1); - - nbcU = 256 / maxX; - nbcV = 256 / maxY; - - nbcT = nbcU * nbcV; - - nbT = nbentries / nbcT; - - if (nbentries % nbcT) { - nbT++; - } - - fonttex = (texture **) malloc(nbT * sizeof(texture *)); - - for (i = 0; i < nbT; i++) { - fonttex[i] = new texture(256, 256, true); - } - - sizes = (Uint8 *) malloc(nbentries * sizeof(Uint8)); - - Uint8 * curtex = (Uint8 *) fonttex[0]->GetSurface()->pixels; - Uint8 curU = 0, curV = 0, curT = 0; - for (int i = 0; i < nbentries; i++) { - ffont.read(&sizes[i], 1); - for (int v = 0; v < maxY; v++) { - for (int u = 0; u < maxX; u++) { - Uint8 f; - ffont.read(&f, 1); - if (flags) { - Uint8 r, g, b, a; - r = f & 3; - g = (f >> 2) & 7; - b = (f >> 5) & 3; - a = (f >> 7) & 1; - curtex[(curU + u + (curV + v) * 256) * 4 + 0] = prescale2[r]; - curtex[(curU + u + (curV + v) * 256) * 4 + 1] = prescale3[g]; - curtex[(curU + u + (curV + v) * 256) * 4 + 2] = prescale2[b]; - curtex[(curU + u + (curV + v) * 256) * 4 + 3] = a ? 255 : 0; - } else { - curtex[(curU + u + (curV + v) * 256) * 4 + 0] = 255; - curtex[(curU + u + (curV + v) * 256) * 4 + 1] = 255; - curtex[(curU + u + (curV + v) * 256) * 4 + 2] = 255; - curtex[(curU + u + (curV + v) * 256) * 4 + 3] = f; - } - } - } - curU += maxX; - if (curU >= 256) { - curU = 0; - curV += maxY; - if (curV >= 256) { - curV = 0; - curT++; - curtex = (Uint8 *) fonttex[curT]->GetSurface()->pixels; - } - } - } - - for (int i = 0; i < nbT; i++) { - fonttex[i]->Generate(); - } - - corresp = (Uint16 *) malloc(nbentries * 2 * sizeof(Uint16)); - - ffont.read(corresp, 2 * sizeof(Uint16) * nbentries); -} - -mogltk::font::~font() { - int i; - for (i = 0; i < nbT; i++) { - delete fonttex[i]; - } - - free((void *) fonttex); - free(sizes); -} - -void mogltk::font::drawentry(Uint16 entry, Color c, int x, int y) { - bool was2D; - - was2D = mogltk::glbase::is2D(); - - if (!was2D) { - mogltk::glbase::Enter2DMode(); - } - - - - if (!was2D) { - mogltk::glbase::Leave2DMode(); - } -} diff --git a/mogltk/gltexture.cpp b/mogltk/gltexture.cpp deleted file mode 100644 index 7949cb9..0000000 --- a/mogltk/gltexture.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include <GL/gl.h> -#include <GL/glu.h> -#include "gltexture.h" -#include "General.h" - -mogltk::texture::texture(int w, int h, bool plane) throw (GeneralException) : width(w), height(h), planar(plane) { - if ((BITCOUNT(w) != 1) || (BITCOUNT(h) != 1)) - throw GeneralException("Size of the texture not a power of 2!"); - - if (!(surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - 0xff000000, - 0x00ff0000, - 0x0000ff00, - 0x000000ff -#else - 0x000000ff, - 0x0000ff00, - 0x00ff0000, - 0xff000000 -#endif - ))) { - throw GeneralException("Can't create RGB Surface"); - } -} - -mogltk::texture::~texture() { - if (surface) { - SDL_FreeSurface(surface); - } else { - glDeleteTextures(1, &tex); - } -} - -SDL_Surface * mogltk::texture::GetSurface() throw (GeneralException) { - if (!surface) - throw GeneralException("Texture already generated"); - return surface; -} - -void mogltk::texture::Generate() throw (GeneralException) { - if (!surface) - throw GeneralException("Texture already generated"); - - if (planar) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels); - } else { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, width, height, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels); -// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels); - } - - SDL_FreeSurface(surface); - surface = 0; -} - -void mogltk::texture::Bind(bool expand) throw (GeneralException) { - if (surface) - throw GeneralException("Texture is not yet generated"); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, tex); - if (expand) { - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glScaled(1 / (double) width, 1 / (double) height, 1); - glMatrixMode(GL_MODELVIEW); - } -} - -GLuint mogltk::texture::GetWidth() { - return width; -} - -GLuint mogltk::texture::GetHeight() { - return height; -} - -void mogltk::texture::Unbind(void) { - glDisable(GL_TEXTURE_2D); -} |