summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac3
-rw-r--r--include/glbase.h2
-rw-r--r--include/gltexture.h4
-rw-r--r--lib/engine.cc8
-rw-r--r--lib/glbase.cc4
-rw-r--r--lib/gltexture.cc70
-rw-r--r--src/test.cc33
7 files changed, 73 insertions, 51 deletions
diff --git a/configure.ac b/configure.ac
index 5983291..ab76acb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3,10 +3,12 @@
AC_PREREQ(2.56)
AC_INIT([mogltk], [0.0.1], [pixel@nobis-crew.org])
+AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE(mogltk, 0.0.1)
AC_CONFIG_SRCDIR([intl/bindtextdom.c])
AM_CONFIG_HEADER(config.h)
+
AM_MAINTAINER_MODE
# Checks for programs.
@@ -36,6 +38,7 @@ AC_SEARCH_LIBS(gluPerspective, GLU, , [
LDFLAGS="-L/usr/X11R6/lib $LDFLAGS"
AC_SEARCH_LIBS(gluPerspective, GLU, , AC_MSG_ERROR([can't find GLU]))
])
+AC_SEARCH_LIBS(IMG_Load_RW, SDL_image, , [AC_MSG_ERROR([can't find SDL_image])])
# Checks for header files.
AC_FUNC_ALLOCA
diff --git a/include/glbase.h b/include/glbase.h
index 27c4f75..b83f044 100644
--- a/include/glbase.h
+++ b/include/glbase.h
@@ -1,8 +1,8 @@
#ifndef __GLBASE_H__
#define __GLBASE_H__
-#include <GL/gl.h>
#include <SDL.h>
+#include <SDL_opengl.h>
#include <Exceptions.h>
namespace mogltk {
diff --git a/include/gltexture.h b/include/gltexture.h
index 9cbfe54..2a5ab0b 100644
--- a/include/gltexture.h
+++ b/include/gltexture.h
@@ -1,14 +1,16 @@
#ifndef __GLTEXTURE_H__
#define __GLTEXTURE_H__
-#include <GL/gl.h>
#include <SDL.h>
+#include <SDL_opengl.h>
+#include <Handle.h>
#include <Exceptions.h>
namespace mogltk {
class texture : public Base {
public:
texture(int = 256, int = 256, bool = false) throw (GeneralException);
+ texture(Handle *, bool = false) throw (GeneralException);
virtual ~texture();
SDL_Surface * GetSurface();
void Generate();
diff --git a/lib/engine.cc b/lib/engine.cc
index bcf5dc0..84014c7 100644
--- a/lib/engine.cc
+++ b/lib/engine.cc
@@ -26,7 +26,6 @@ int mogltk::engine::GetInited() {
class embedRWops : public Base {
public:
embedRWops(Handle *);
- ~embedRWops();
int seek(int, int);
int read(void *, int, int);
int write(const void *, int, int);
@@ -34,11 +33,7 @@ class embedRWops : public Base {
Handle * h;
};
-embedRWops::embedRWops(Handle * ah) : h(new Handle(*ah)) {}
-
-embedRWops::~embedRWops() {
- delete h;
-}
+embedRWops::embedRWops(Handle * ah) : h(ah) {}
int embedRWops::seek(int offset, int whence) {
return h->seek(offset, whence);
@@ -73,6 +68,7 @@ static int embedRWwrite(SDL_RWops * context, const void * ptr, int size, int num
static int embedRWclose(SDL_RWops * context) {
if (context->hidden.unknown.data1) {
delete ((embedRWops *)(context->hidden.unknown.data1));
+ context->hidden.unknown.data1 = 0;
return 0;
}
return -1;
diff --git a/lib/glbase.cc b/lib/glbase.cc
index aa98d30..0db56db 100644
--- a/lib/glbase.cc
+++ b/lib/glbase.cc
@@ -1,8 +1,8 @@
+#include <SDL.h>
+#include <SDL_opengl.h>
#include "glbase.h"
#include "engine.h"
#include "generic.h"
-#include <SDL.h>
-#include <SDL_opengl.h>
#define DEBUG 1
diff --git a/lib/gltexture.cc b/lib/gltexture.cc
index 3b1ee78..49a5157 100644
--- a/lib/gltexture.cc
+++ b/lib/gltexture.cc
@@ -1,9 +1,12 @@
#include <sys/types.h>
-#include <GL/gl.h>
-#include <GL/glu.h>
#include <SDL.h>
+#include <SDL_image.h>
+#include <SDL_opengl.h>
#include <generic.h>
#include "gltexture.h"
+#include "engine.h"
+
+#define _(x) x
#define DEBUG 1
@@ -17,7 +20,7 @@ mogltk::texture * mogltk::texture::active = 0;
mogltk::texture::texture(int w, int h, bool plane) throw (GeneralException) : width(w), height(h),
texture_allocated(false), planar(plane), tainted(true) {
if ((BITCOUNT(w) != 1) || (BITCOUNT(h) != 1))
- throw GeneralException("Size of the texture not a power of 2!");
+ 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
@@ -32,8 +35,57 @@ mogltk::texture::texture(int w, int h, bool plane) throw (GeneralException) : wi
0xff000000
#endif
))) {
- throw GeneralException("Can't create RGB Surface");
+ throw GeneralException(_("Can't create RGB Surface"));
+ }
+
+#ifdef TRACE_TEXTURES
+ next = 0;
+ prev = footer;
+ footer = this;
+ if (!header) {
+ header = this;
}
+ if (prev) {
+ prev->next = this;
+ }
+#endif
+}
+
+mogltk::texture::texture(Handle * h, bool plane) throw (GeneralException) :
+ texture_allocated(false), planar(plane), tainted(true) {
+
+ SDL_Surface * temp;
+
+ if (!(temp = IMG_Load_RW(engine::RWFromHandle(h), 1)))
+ throw GeneralException(_("Can't load image from Handle ") + h->GetName());
+
+ width = temp->w;
+ height = temp->h;
+
+ if ((BITCOUNT(width) != 1) || (BITCOUNT(height) != 1)) {
+ SDL_FreeSurface(temp);
+ 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
+ ))) {
+ SDL_FreeSurface(temp);
+ throw GeneralException(_("Can't create RGB Surface"));
+ }
+
+ SDL_BlitSurface(temp, 0, surface, 0);
+ SDL_FreeSurface(temp);
#ifdef TRACE_TEXTURES
next = 0;
@@ -87,21 +139,21 @@ void mogltk::texture::Generate() {
glGenTextures(1, &tex);
#ifdef DEBUG
- printm(M_INFO, "Generated texture index: %i\n", tex);
+ printm(M_INFO, _("Generated texture index: %i\n"), tex);
#endif
glBindTexture(GL_TEXTURE_2D, tex);
if (planar) {
#ifdef DEBUG
- printm(M_INFO, "Generating planar texture: %i\n", tex);
+ printm(M_INFO, _("Generating planar texture: %i\n"), tex);
#endif
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 {
#ifdef DEBUG
- printm(M_INFO, "Generating 3D texture: %i\n", tex);
+ printm(M_INFO, _("Generating 3D texture: %i\n"), tex);
#endif
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -122,7 +174,7 @@ void mogltk::texture::Bind(bool expand) {
if (active == this)
return;
#ifdef DEBUG
- printm(M_INFO, "Binding texture index %i.\n", tex);
+ printm(M_INFO, _("Binding texture index %i.\n"), tex);
#endif
glBindTexture(GL_TEXTURE_2D, tex);
if (expand) {
@@ -167,7 +219,7 @@ void mogltk::texture::Unbind(void) {
glDisable(GL_TEXTURE_2D);
active = 0;
#ifdef DEBUG
- printm(M_INFO, "Unbinding texture.\n");
+ printm(M_INFO, _("Unbinding texture.\n"));
#endif
}
diff --git a/src/test.cc b/src/test.cc
index cf8ef8f..011feb4 100644
--- a/src/test.cc
+++ b/src/test.cc
@@ -17,39 +17,8 @@ virtual int startup() throw (GeneralException) {
verbosity = M_INFO;
- mogltk::texture * mytex = new mogltk::texture(256, 256, true);
+ mogltk::texture * mytex = new mogltk::texture(&Input("pattern6.bmp"), true);
- texture = (Uint8 *) mytex->GetSurface()->pixels;
-
- for (int y = 0; y < 256; y++) {
- for (int x = 0; x < 256; x++) {
- //int r = random() % 256;
- int r = 255;
- texture[(x + y * 256) * 4 + 0] = r;
- texture[(x + y * 256) * 4 + 1] = r;
- texture[(x + y * 256) * 4 + 2] = r;
- texture[(x + y * 256) * 4 + 3] = 255;
- }
- }
-
- SDL_Surface * s;
-
- if (!(s = SDL_LoadBMP("pattern6.bmp"))) {
- throw GeneralException("Error: could not load texture.");
- }
- SDL_BlitSurface(s, NULL, mytex->GetSurface(), NULL);
-
-/*
- for (int y = 0; y < 256; y += 2) {
- for (int x = 0; x < 256; x += 2) {
- texture[(x + y * 256) * 4 + 0] = 0;
- texture[(x + y * 256) * 4 + 1] = 0;
- texture[(x + y * 256) * 4 + 2] = 255;
- texture[(x + y * 256) * 4 + 3] = 0;
- }
- }
-*/
-
mogltk::glbase::Enter2DMode();
mytex->Bind();