summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpixel <pixel>2002-11-15 23:58:57 +0000
committerpixel <pixel>2002-11-15 23:58:57 +0000
commitd99f7dd959709b7a9e8cba23b88a216a6970209c (patch)
tree9e74abdec626b44ceb845239f8ed93f239946445
parent028c7dcfa9f1920d5fa2e573790bef40c4076275 (diff)
Bleh
-rwxr-xr-xMakefile2
-rw-r--r--gltest.cpp65
-rw-r--r--includes/Handle.h2
-rw-r--r--includes/Image.h7
-rw-r--r--includes/glbase.h2
-rw-r--r--includes/gltexture.h11
-rw-r--r--mogltk/glbase.cpp8
-rw-r--r--mogltk/gltexture.cpp24
8 files changed, 98 insertions, 23 deletions
diff --git a/Makefile b/Makefile
index 5876b04..c46bd9c 100755
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
#!/usr/bin/make -f
CPPFLAGS=-Wall -g -O3 -mcpu=i686 -Werror -Iincludes `sdl-config --cflags` -DHAVE_ZLIB
-LDFLAGS=-lz `sdl-config --libs` -lGL -lGLU -L/usr/X11/lib
+LDFLAGS=-lz `sdl-config --libs` -lGL -lGLU -L/usr/X11/lib -lefence
CXX=g++
SUBDIRS = psxdev generic lib Xenogears VP MegamanX5 mogltk
diff --git a/gltest.cpp b/gltest.cpp
index ab0aa51..9991ba9 100644
--- a/gltest.cpp
+++ b/gltest.cpp
@@ -2,12 +2,75 @@
#include "generic.h"
#include "Main.h"
#include "glbase.h"
+#include "gltexture.h"
CODE_BEGINS
virtual int startup() throw (GeneralException) {
+ Uint8 * texture;
verbosity = M_INFO;
mogltk::glbase::setup();
- sleep(5);
+
+ mogltk::texture * mytex = new mogltk::texture(256, 256);
+
+ texture = (Uint8 *) mytex->GetSurface()->pixels;
+
+ for (int y = 0; y < 256; y++) {
+ for (int x = 0; x < 256; x++) {
+ int r = random() % 256;
+ 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 = SDL_LoadBMP("pattern6.bmp");
+ 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] = 255;
+ texture[(x + y * 256) * 4 + 1] = 255;
+ texture[(x + y * 256) * 4 + 2] = 255;
+ texture[(x + y * 256) * 4 + 3] = 255;
+ }
+ }
+*/
+ mytex->Generate();
+
+ mogltk::glbase::Enter2DMode();
+
+ mytex->Bind();
+ glBegin(GL_TRIANGLE_STRIP);
+ glTexCoord2i(0, 0);
+ glVertex2f(50, 50);
+ glTexCoord2i(511, 0);
+ glVertex2f(561, 50);
+ glTexCoord2i(0, 511);
+ glVertex2f(50, 561);
+ glTexCoord2i(511, 511);
+ glVertex2f(561, 561);
+ glEnd();
+
+ glBegin(GL_TRIANGLE_STRIP);
+ glTexCoord2i(0, 0);
+ glVertex2i(400, 100);
+ glTexCoord2i(256, 0);
+ glVertex2i(450, 100);
+ glTexCoord2i(0, 256);
+ glVertex2i(400, 150);
+ glTexCoord2i(256, 256);
+ glVertex2i(450, 150);
+ glEnd();
+ mogltk::glbase::Leave2DMode();
+
+ mogltk::glbase::Flip();
+
+// sleep(15);
+ getchar();
+
+ delete mytex;
+
return 0;
}
CODE_ENDS
diff --git a/includes/Handle.h b/includes/Handle.h
index a82aa52..b7eed41 100644
--- a/includes/Handle.h
+++ b/includes/Handle.h
@@ -35,7 +35,7 @@ class Handle : public Base {
virtual bool CanWatch() const;
virtual void Dup(const Handle &);
#ifdef HAVE_ZLIB
- virtual void SetZ(int) throw (GeneralException);
+ virtual void SetZ(int = 9) throw (GeneralException);
#endif
protected:
Handle(int h);
diff --git a/includes/Image.h b/includes/Image.h
index 9bef556..87a8ddd 100644
--- a/includes/Image.h
+++ b/includes/Image.h
@@ -4,17 +4,12 @@
#include <Buffer.h>
#include <generic.h>
+#include <Color.h>
enum {
FORMAT_TGA_BASIC
};
-struct Color {
- Color(unsigned char aR, unsigned char aG, unsigned char aB, unsigned char aA = 255) :
- R(aR), G(aG), B(aB), A(aA) { }
- unsigned char R, G, B, A;
-};
-
class Image : public Buffer {
public:
Image(unsigned int, unsigned int);
diff --git a/includes/glbase.h b/includes/glbase.h
index 78272eb..f8f0ae6 100644
--- a/includes/glbase.h
+++ b/includes/glbase.h
@@ -13,6 +13,8 @@ namespace mogltk {
static int GetInited(void);
static void Enter2DMode(void);
static void Leave2DMode(void);
+ static void Flip(void);
+ static bool is2D(void);
private:
static int width, height, inited, twoD;
static SDL_Surface * surface;
diff --git a/includes/gltexture.h b/includes/gltexture.h
index 5ac80ad..84edaa8 100644
--- a/includes/gltexture.h
+++ b/includes/gltexture.h
@@ -1,21 +1,22 @@
#ifndef __GLTEXTURE_H__
#define __GLTEXTURE_H__
+#include <GL/gl.h>
#include <SDL.h>
#include "Exceptions.h"
namespace mogltk {
- class gltexture : public Base {
+ class texture : public Base {
public:
- gltexture(int = 256, int = 256, bool = true) throw (GeneralException);
- virtual ~gltexture();
+ texture(int = 256, int = 256, bool = false) throw (GeneralException);
+ virtual ~texture();
SDL_Surface * GetSurface() throw (GeneralException);
void Generate() throw (GeneralException);
- void Bind() throw (GeneralException);
+ void Bind(bool = true) throw (GeneralException);
GLuint GetWidth();
GLuint GetHeight();
private:
- GLuint width, height, texture;
+ GLuint width, height, tex;
SDL_Surface * surface;
bool planar;
};
diff --git a/mogltk/glbase.cpp b/mogltk/glbase.cpp
index 0993b43..dabf28a 100644
--- a/mogltk/glbase.cpp
+++ b/mogltk/glbase.cpp
@@ -112,3 +112,11 @@ void mogltk::glbase::Leave2DMode(void) {
twoD = 0;
}
+
+void mogltk::glbase::Flip() {
+ SDL_GL_SwapBuffers();
+}
+
+bool mogltk::glbase::is2D() {
+ return twoD;
+}
diff --git a/mogltk/gltexture.cpp b/mogltk/gltexture.cpp
index 0878d04..0549ee3 100644
--- a/mogltk/gltexture.cpp
+++ b/mogltk/gltexture.cpp
@@ -3,7 +3,7 @@
#include "gltexture.h"
#include "General.h"
-mogltk::gltexture::gltexture(int w, int h, bool plane) throw (GeneralException) : width(w), height(h), planar(plane) {
+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!");
@@ -24,21 +24,21 @@ mogltk::gltexture::gltexture(int w, int h, bool plane) throw (GeneralException)
}
}
-mogltk::gltexture::~gltexture() {
+mogltk::texture::~texture() {
if (surface) {
SDL_FreeSurface(surface);
} else {
- glDeleteTextures(1, &texture);
+ glDeleteTextures(1, &tex);
}
}
-SDL_Surface * mogltk::gltexture::GetSurface() throw (GeneralException) {
+SDL_Surface * mogltk::texture::GetSurface() throw (GeneralException) {
if (!surface)
throw GeneralException("Texture already generated");
return surface;
}
-void mogltk::gltexture::Generate() throw (GeneralException) {
+void mogltk::texture::Generate() throw (GeneralException) {
if (!surface)
throw GeneralException("Texture already generated");
@@ -59,16 +59,22 @@ void mogltk::gltexture::Generate() throw (GeneralException) {
surface = 0;
}
-void mogltk::gltexture::Bind() throw (GeneralException) {
+void mogltk::texture::Bind(bool expand) throw (GeneralException) {
if (surface)
throw GeneralException("Texture is not yet generated");
- glBindTexture(GL_TEXTURE_2D, texture);
+ glBindTexture(GL_TEXTURE_2D, tex);
+ if (expand) {
+ glMatrixMode(GL_TEXTURE);
+ glLoadIdentity();
+ glScaled(1 / (double) width, 1 / (double) height, 1);
+ glMatrixMode(GL_MODELVIEW);
+ }
}
-GLuint mogltk::gltexture::GetWidth() {
+GLuint mogltk::texture::GetWidth() {
return width;
}
-GLuint mogltk::gltexture::GetHeight() {
+GLuint mogltk::texture::GetHeight() {
return height;
}