diff options
author | pixel <pixel> | 2002-11-11 20:07:41 +0000 |
---|---|---|
committer | pixel <pixel> | 2002-11-11 20:07:41 +0000 |
commit | 028c7dcfa9f1920d5fa2e573790bef40c4076275 (patch) | |
tree | 3c5f2bd9e90b7d57bae84111a200ee608c9d9bc3 | |
parent | 9cde21d59d7c1f9b385d334cd60ae241ce9cf49b (diff) |
Still working ;-)
-rwxr-xr-x | Makefile | 8 | ||||
-rw-r--r-- | includes/General.h | 5 | ||||
-rw-r--r-- | includes/glfont.h | 18 | ||||
-rw-r--r-- | includes/gltexture.h | 24 | ||||
-rwxr-xr-x | mogltk/Makefile | 2 | ||||
-rw-r--r-- | mogltk/glbase.cpp | 6 | ||||
-rw-r--r-- | mogltk/glfont.cpp | 2 | ||||
-rw-r--r-- | mogltk/gltexture.cpp | 74 |
8 files changed, 131 insertions, 8 deletions
@@ -1,11 +1,11 @@ #!/usr/bin/make -f CPPFLAGS=-Wall -g -O3 -mcpu=i686 -Werror -Iincludes `sdl-config --cflags` -DHAVE_ZLIB -LDFLAGS=-lz `sdl-config --libs` -lGL -lGLU +LDFLAGS=-lz `sdl-config --libs` -lGL -lGLU -L/usr/X11/lib CXX=g++ SUBDIRS = psxdev generic lib Xenogears VP MegamanX5 mogltk -TARGET = lzss dlzss cd-tool str-player crypto-search bgrep dte-tool ffx-convert gltest +TARGET = lzss dlzss cd-tool str-player crypto-search bgrep dte-tool tile-convert gltest all: subdirs ${TARGET} @@ -36,8 +36,8 @@ crypto-search: crypto-search.o includes/generic.h lib/lib.a generic/generic.a Ma bgrep: bgrep.o includes/generic.h generic/generic.a Makefile ${CXX} bgrep.o generic/generic.a -o bgrep ${LDFLAGS} -ffx-convert: ffx-convert.o generic/generic.a Makefile - ${CXX} ffx-convert.o generic/generic.a -o ffx-convert ${LDFLAGS} +tile-convert: tile-convert.o generic/generic.a Makefile + ${CXX} tile-convert.o generic/generic.a -o ffx-convert ${LDFLAGS} gltest: gltest.o mogltk/mogltk.a generic/generic.a Makefile ${CXX} gltest.o mogltk/mogltk.a generic/generic.a -o gltest ${LDFLAGS} diff --git a/includes/General.h b/includes/General.h index 6f423ed..2b645c9 100644 --- a/includes/General.h +++ b/includes/General.h @@ -4,4 +4,9 @@ #define MAX(__a,__b) ((__a)<(__b)?(__b):(__a)) #define MIN(__a,__b) ((__a)>(__b)?(__b):(__a)) +#define BITCOUNT(x) (((BX_(x)+(BX_(x)>>4)) & 0x0F0F0F0F) % 255) +#define BX_(x) ((x) - (((x)>>1)&0x77777777) \ + - (((x)>>2)&0x33333333) \ + - (((x)>>3)&0x11111111)) + #endif diff --git a/includes/glfont.h b/includes/glfont.h new file mode 100644 index 0000000..502ff49 --- /dev/null +++ b/includes/glfont.h @@ -0,0 +1,18 @@ +#ifndef __GLFONT_H__ +#define __GLFONT_H__ + +#include "Exceptions.h" +#include "gltexture.h" + +namespace mogltk { + class glfont : public Base { + public: + glfont(); + virtual ~glfont(); + void Load(const String &) throw (GeneralException); + private: + gltexture * fonttex; + }; +}; + +#endif diff --git a/includes/gltexture.h b/includes/gltexture.h new file mode 100644 index 0000000..5ac80ad --- /dev/null +++ b/includes/gltexture.h @@ -0,0 +1,24 @@ +#ifndef __GLTEXTURE_H__ +#define __GLTEXTURE_H__ + +#include <SDL.h> +#include "Exceptions.h" + +namespace mogltk { + class gltexture : public Base { + public: + gltexture(int = 256, int = 256, bool = true) throw (GeneralException); + virtual ~gltexture(); + SDL_Surface * GetSurface() throw (GeneralException); + void Generate() throw (GeneralException); + void Bind() throw (GeneralException); + GLuint GetWidth(); + GLuint GetHeight(); + private: + GLuint width, height, texture; + SDL_Surface * surface; + bool planar; + }; +}; + +#endif diff --git a/mogltk/Makefile b/mogltk/Makefile index 510baa6..4e99e89 100755 --- a/mogltk/Makefile +++ b/mogltk/Makefile @@ -3,7 +3,7 @@ CPPFLAGS=-Wall -g -O3 -mcpu=i686 -Werror -I../includes -DHAVE_ZLIB `sdl-config --cflags` CXX=g++ -OBJECTS = glbase.o engine.o +OBJECTS = glbase.o engine.o gltexture.o glfont.o TARGET = mogltk.a all: ${TARGET} diff --git a/mogltk/glbase.cpp b/mogltk/glbase.cpp index b2512ca..0993b43 100644 --- a/mogltk/glbase.cpp +++ b/mogltk/glbase.cpp @@ -59,6 +59,9 @@ int mogltk::glbase::setup(int w, int h, int flags) throw(GeneralException) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); + glEnable(GL_TEXTURE_2D); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + return 0; } @@ -81,7 +84,6 @@ void mogltk::glbase::Enter2DMode(void) { 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); @@ -94,8 +96,6 @@ void mogltk::glbase::Enter2DMode(void) { glPushMatrix(); glLoadIdentity(); - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); - twoD = 1; } diff --git a/mogltk/glfont.cpp b/mogltk/glfont.cpp new file mode 100644 index 0000000..e98a64d --- /dev/null +++ b/mogltk/glfont.cpp @@ -0,0 +1,2 @@ +#include <GL/gl.h> +#include "glfont.h" diff --git a/mogltk/gltexture.cpp b/mogltk/gltexture.cpp new file mode 100644 index 0000000..0878d04 --- /dev/null +++ b/mogltk/gltexture.cpp @@ -0,0 +1,74 @@ +#include <GL/gl.h> +#include <GL/glu.h> +#include "gltexture.h" +#include "General.h" + +mogltk::gltexture::gltexture(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::gltexture::~gltexture() { + if (surface) { + SDL_FreeSurface(surface); + } else { + glDeleteTextures(1, &texture); + } +} + +SDL_Surface * mogltk::gltexture::GetSurface() throw (GeneralException) { + if (!surface) + throw GeneralException("Texture already generated"); + return surface; +} + +void mogltk::gltexture::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::gltexture::Bind() throw (GeneralException) { + if (surface) + throw GeneralException("Texture is not yet generated"); + glBindTexture(GL_TEXTURE_2D, texture); +} + +GLuint mogltk::gltexture::GetWidth() { + return width; +} + +GLuint mogltk::gltexture::GetHeight() { + return height; +} |