summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac10
-rw-r--r--include/glfont.h5
-rw-r--r--include/gltexture.h1
-rw-r--r--lib/engine.cc18
-rw-r--r--lib/glbase.cc6
-rw-r--r--lib/glfont.cc42
-rw-r--r--lib/gltexture.cc93
-rw-r--r--src/test.cc2
8 files changed, 131 insertions, 46 deletions
diff --git a/configure.ac b/configure.ac
index 8e5f43e..30f7436 100644
--- a/configure.ac
+++ b/configure.ac
@@ -39,8 +39,6 @@ AC_SEARCH_LIBS(gluPerspective, GLU, , [
AC_SEARCH_LIBS(gluPerspective, GLU, , AC_MSG_ERROR([can't find GLU]))
])
-AC_SEARCH_LIBS(EF_Print, efence)
-
# Checks for header files.
AC_FUNC_ALLOCA
AC_HEADER_STDC
@@ -63,9 +61,17 @@ AC_FUNC_REALLOC
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([__argz_count __argz_next __argz_stringify getcwd mempcpy munmap nl_langinfo setlocale stpcpy strcasecmp strchr strcspn strdup strstr strtoul atexit])
+AC_ARG_ENABLE([debug],
+ [ --enable-debug enable verbose debugging],
+ AC_DEFINE(DEBUG, 1, [Enable verbose debugging]))
+
+AC_ARG_ENABLE([efence],
+ [ --enable-efence enable compiling with electic-fence],
+ AC_SEARCH_LIBS(EF_Print, efence))
AC_PATH_PROG(gmakepath, gmake)
AC_PATH_PROG(unamepath, uname)
+
if test "x$unamepath" = x; then
system="unknown"
else
diff --git a/include/glfont.h b/include/glfont.h
index 072826a..464cd47 100644
--- a/include/glfont.h
+++ b/include/glfont.h
@@ -2,6 +2,7 @@
#define __GLFONT_H__
#include <SDL.h>
+#include <stdarg.h>
#include <BString.h>
#include <Color.h>
#include <Handle.h>
@@ -17,7 +18,9 @@ namespace mogltk {
void putentry(Uint16, Color = Color(255, 255, 255, 255));
void putchar(char, Color = Color(255, 255, 255, 255));
void newline(void);
- int printf(const String &, ...);
+ int printf(const ugly_string &, ...);
+ int printf(const char *, ...);
+ int printf(const ugly_string &, va_list);
void setcolor(Color);
void setshadow(int);
int getchar(char) const;
diff --git a/include/gltexture.h b/include/gltexture.h
index bcfed2d..06f2e8a 100644
--- a/include/gltexture.h
+++ b/include/gltexture.h
@@ -16,6 +16,7 @@ namespace mogltk {
texture(Handle *, bool = false, texture_type = RAW_RGBA) throw (GeneralException);
virtual ~texture();
SDL_Surface * GetSurface();
+ static SDL_Surface * LoadNTEX(Handle * h) throw (GeneralException) ;
void Generate();
void Bind(bool = true);
GLuint GetWidth();
diff --git a/lib/engine.cc b/lib/engine.cc
index 741deee..e012468 100644
--- a/lib/engine.cc
+++ b/lib/engine.cc
@@ -115,15 +115,6 @@ void mogltk::engine::pollevents() {
return;
SDL_WaitEvent(&event);
switch(event.type) {
- case SDL_VIDEOEXPOSE:
- printm(M_INFO, "Needs to redraw\n");
- hastoreturn = true;
- break;
- case SDL_MOUSEMOTION:
- printm(M_INFO, "Mouse slept over the screen - (%i, %i)\n", event.motion.x, event.motion.y);
- if (cursorvisible)
- hastoreturn = true;
- break;
case SDL_ACTIVEEVENT:
switch (event.active.state) {
case SDL_APPMOUSEFOCUS:
@@ -142,10 +133,19 @@ void mogltk::engine::pollevents() {
printm(M_INFO, String("Key ") + event.key.keysym.scancode + " on keyboard " + event.key.which + (event.key.state == SDL_PRESSED ? " pressed" : " released") + "\n");
printm(M_INFO, "SDL keysym: %i - Unicode: %04x - modifiers: %04x\n", event.key.keysym.sym, event.key.keysym.unicode, event.key.keysym.mod);
break;
+ case SDL_MOUSEMOTION:
+ printm(M_INFO, "Mouse slept over the screen - (%i, %i)\n", event.motion.x, event.motion.y);
+ if (cursorvisible)
+ hastoreturn = true;
+ break;
case SDL_QUIT:
printm(M_INFO, "Quit requested\n");
hastoreturn = quitrequest = true;
break;
+ case SDL_VIDEOEXPOSE:
+ printm(M_INFO, "Needs to redraw\n");
+ hastoreturn = true;
+ break;
default:
printm(M_INFO, "Unknow event: %i\n", event.type);
break;
diff --git a/lib/glbase.cc b/lib/glbase.cc
index 5e9a74e..67b1b9c 100644
--- a/lib/glbase.cc
+++ b/lib/glbase.cc
@@ -1,10 +1,12 @@
+#include <stdio.h>
#include <SDL.h>
#include <SDL_opengl.h>
#include "glbase.h"
#include "engine.h"
#include "generic.h"
-
-#define DEBUG 1
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
int mogltk::glbase::width, mogltk::glbase::height, mogltk::glbase::inited = 0, mogltk::glbase::twoD = 0;
SDL_Surface * mogltk::glbase::surface = 0;
diff --git a/lib/glfont.cc b/lib/glfont.cc
index b00f470..02b9a45 100644
--- a/lib/glfont.cc
+++ b/lib/glfont.cc
@@ -2,10 +2,12 @@
#include "glbase.h"
#include "glfont.h"
#include "Input.h"
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
Uint8 prescale2[4] = { 0, 85, 170, 255 }, prescale3[8] = { 0, 36, 72, 109, 145, 182, 218, 255 };
-#define DEBUG 1
#define STRBUFSIZ 512
/*
@@ -245,19 +247,16 @@ void mogltk::font::newline(void) {
cy += inter;
}
-int mogltk::font::printf(const String & m, ...) {
- static char buffer[STRBUFSIZ + 1];
- va_list ap;
+int mogltk::font::printf(const ugly_string & m, va_list ap) {
char * p;
+ static char buffer[STRBUFSIZ + 1];
int r;
-
- va_start(ap, m);
+
#ifdef HAVE_VSNPRINTF
- r = vsnprintf(buffer, STRBUFSIZ, m.to_charp(), ap);
+ r = vsnprintf(buffer, STRBUFSIZ, m.p, ap);
#else
- r = vsprintf(buffer, m.to_charp(), ap);
+ r = vsprintf(buffer, m.p, ap);
#endif
- va_end(ap);
for (p = buffer; *p; p++) {
if (*p == '\n') {
@@ -270,6 +269,31 @@ int mogltk::font::printf(const String & m, ...) {
return r;
}
+int mogltk::font::printf(const ugly_string & m, ...) {
+ va_list ap;
+ int r;
+
+ va_start(ap, m);
+ r = printf(m, ap);
+ va_end(ap);
+
+ return r;
+}
+
+int mogltk::font::printf(const char * p, ...) {
+ ugly_string m;
+ va_list ap;
+ int r;
+
+ m.p = p;
+
+ va_start(ap, m);
+ r = printf(m, ap);
+ va_end(ap);
+
+ return r;
+}
+
void mogltk::font::setcolor(Color c) {
textcolor = c;
}
diff --git a/lib/gltexture.cc b/lib/gltexture.cc
index 601d24f..accdb3a 100644
--- a/lib/gltexture.cc
+++ b/lib/gltexture.cc
@@ -6,7 +6,9 @@
#include "engine.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
-#else
+#endif
+#include "gettext.h"
+#ifndef _
#define _(x) x
#endif
@@ -58,41 +60,54 @@ mogltk::texture::texture(Handle * h, bool plane, texture_type ttype) throw (Gene
SDL_Surface * temp;
-#if USE_SDLIMAGE
- if (!(temp = IMG_Load_RW(engine::RWFromHandle(h), 1)))
- throw GeneralException(_("Can't load image from Handle ") + h->GetName());
-#else
- if (!(temp = LoadNTEX(h)))
- throw GeneralException(_("Can't load texture from Handle ") + h->GetName());
-#endif
+ temp = LoadNTEX(h);
width = temp->w;
height = temp->h;
+#ifdef DEBUG
+ printm(M_INFO, "Creating texture from file: size %ix%i\n", height, width);
+#endif
+
if ((!ISPOT(width)) || (!ISPOT(height))) {
SDL_FreeSurface(temp);
throw GeneralException(_("Size of the texture not a power of 2!"));
}
- if (!(surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,
+ SDL_PixelFormat f;
+
+ f.palette = 0;
+ f.BitsPerPixel = 32;
+ f.BytesPerPixel = 4;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- 0xff000000,
- 0x00ff0000,
- 0x0000ff00,
- 0x000000ff
+ f.Amask = 0x000000ff;
+ f.Bmask = 0x0000ff00;
+ f.Gmask = 0x00ff0000;
+ f.Rmask = 0xff000000;
+ f.Ashift = 0;
+ f.Bshift = 8;
+ f.Gshift = 16;
+ f.Rshift = 24;
#else
- 0x000000ff,
- 0x0000ff00,
- 0x00ff0000,
- 0xff000000
+ f.Rmask = 0x000000ff;
+ f.Gmask = 0x0000ff00;
+ f.Bmask = 0x00ff0000;
+ f.Amask = 0xff000000;
+ f.Rshift = 0;
+ f.Gshift = 8;
+ f.Bshift = 16;
+ f.Ashift = 24;
#endif
- ))) {
- SDL_FreeSurface(temp);
- throw GeneralException(_("Can't create RGB Surface"));
+ f.Rloss = 0;
+ f.Gloss = 0;
+ f.Bloss = 0;
+ f.Aloss = 0;
+
+ if (!(surface = SDL_ConvertSurface(temp, &f, 0))) {
+ throw GeneralException("Could not convert texture to OpenGL format");
}
- SDL_BlitSurface(temp, 0, surface, 0);
SDL_FreeSurface(temp);
-
+
#ifdef TRACE_TEXTURES
next = 0;
prev = footer;
@@ -222,6 +237,7 @@ GLuint mogltk::texture::GetHeight() {
}
void mogltk::texture::Unbind(void) {
+ glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
active = 0;
#ifdef DEBUG
@@ -232,3 +248,36 @@ void mogltk::texture::Unbind(void) {
void mogltk::texture::Taint(void) {
tainted = true;
}
+
+#ifdef WORDS_BIGENDIAN
+#define NTEX_SIGNATURE 0x4e544558
+#else
+#define NTEX_SIGNATURE 0x5845544e
+#endif
+
+SDL_Surface * mogltk::texture::LoadNTEX(Handle * h) throw (GeneralException) {
+ SDL_Surface * r;
+ char buffer[4];
+ Uint16 height, width;
+
+ h->read(buffer, 4);
+ buffer[4] = 0;
+ if (*((Uint32 *) buffer) != NTEX_SIGNATURE)
+ throw GeneralException("Texture file " + h->GetName() + " corrupted");
+
+ height = h->readU16();
+ width = h->readU16();
+
+ if (!(r = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,
+ 0x000000ff,
+ 0x0000ff00,
+ 0x00ff0000,
+ 0xff000000
+ ))) {
+ throw GeneralException(_("Can't create RGB Surface for LoadNTEX"));
+ }
+
+ h->read(r->pixels, height * width * 4);
+
+ return r;
+}
diff --git a/src/test.cc b/src/test.cc
index 0bb2fde..0efe319 100644
--- a/src/test.cc
+++ b/src/test.cc
@@ -19,7 +19,7 @@ virtual int startup() throw (GeneralException) {
verbosity = M_INFO;
- Input * pattern = new Input("pattern6.rgba");
+ Input * pattern = new Input("pattern6.tex");
mogltk::texture * mytex = new mogltk::texture(pattern, true);
delete pattern;