Start of attempt to abstract OpenGL from Residual

This commit is contained in:
James Brown 2004-01-23 11:10:59 +00:00
parent 8f2f5cd2a3
commit 508d66a1e5
12 changed files with 316 additions and 230 deletions

View File

@ -1,12 +1,12 @@
CXX = g++
CXXFLAGS = -g -W -Wall -Ilua/include `sdl-config --cflags` -DUNIX # -O2
LDFLAGS = -g -W -Wall # -O2
LIBS = -lGL -lGLU -Llua/lib -llua -llualib `sdl-config --libs` \
-Lmixer -lmixer
LIBS = -Llua/lib -llua -llualib `sdl-config --libs` \
-Lmixer -lmixer -lGL -lGLU
OBJS = main.o lab.o bitmap.o model.o resource.o material.o debug.o \
textsplit.o lua.o registry.o localize.o scene.o engine.o actor.o \
sound.o timer.o keyframe.o costume.o walkplane.o textobject.o \
matrix3.o matrix4.o screen.o blocky16.o smush.o vima.o
matrix3.o matrix4.o screen.o blocky16.o smush.o vima.o driver_gl.o
DEPS = $(OBJS:.o=.d)

View File

@ -22,8 +22,7 @@
#include "sound.h"
#include <cmath>
#include <cstring>
#include <SDL.h>
#include <SDL_opengl.h>
#include "driver_gl.h"
Actor::Actor(const char *name) :
name_(name), talkColor_(255, 255, 255), pos_(0, 0, 0),
@ -239,13 +238,8 @@ void Actor::update() {
void Actor::draw() {
if (! costumeStack_.empty()) {
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(pos_.x(), pos_.y(), pos_.z());
glRotatef(yaw_, 0, 0, 1);
glRotatef(pitch_, 1, 0, 0);
glRotatef(roll_, 0, 1, 0);
g_driver->startActorDraw(pos_, yaw_, pitch_, roll_);
costumeStack_.back()->draw();
glPopMatrix();
g_driver->finishActorDraw();
}
}

View File

@ -18,12 +18,12 @@
#include "stdafx.h"
#include <cstdlib>
#include <cstring>
#include <SDL.h>
#include <SDL_opengl.h>
#include "bitmap.h"
#include "bits.h"
#include "debug.h"
#include "driver_gl.h"
#define BITMAP_TEXTURE_SIZE 256
static void decompress_codec3(const char *compressed, char *result);
@ -105,7 +105,7 @@ Bitmap::Bitmap(const char *filename, const char *data, int len) :
}
}
void Bitmap::prepareGL() {
void Bitmap::prepareDraw() {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 640, 480, 0, 0, 1);
@ -156,23 +156,7 @@ void Bitmap::draw() const {
if ((ZBUFFER_GLOBAL == 0) || (SCREENBLOCKS_GLOBAL == 1))
return;
if (curr_image_ != 0) {
warning("Animation not handled yet in GL texture path !\n");
}
glRasterPos2i(x_, y_);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_ALWAYS);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glDepthMask(GL_TRUE);
/* This loop here is to prevent using PixelZoom that may be unoptimized for the 1.0 / -1.0 case
in some drivers...
*/
for (int row = 0; row < height_; row++) {
glRasterPos2i(x_, y_ + row + 1);
// glDrawPixels(width_, 1, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, data_[curr_image_] + (2 * row * width_));
}
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthFunc(GL_LESS);
g_driver->drawDepthBitmap(curr_image_, x_, y_, width_, height_, data_);
}
}

View File

@ -27,8 +27,8 @@ public:
// Construct a bitmap from the given data.
Bitmap(const char *filename, const char *data, int len);
// Set up GL for drawing bitmaps
static void prepareGL();
// Set up Driver for drawing bitmaps
static void prepareDraw();
void draw() const;
// Set which image in an animated bitmap to use

243
driver_gl.cpp Normal file
View File

@ -0,0 +1,243 @@
#include "driver_gl.h" // Driver interface
#include "debug.h" // error(), warning(), etc
Driver *g_driver;
// Hacky includes for temporary font rendering
#ifndef WIN32
#include <GL/glx.h>
#include <X11/Xlib.h>
#else
#include <SDL_syswm.h>
#include <windows.h>
#endif
// Constructor. Should create the driver and open screens, etc.
Driver::Driver(int screenW, int screenH, int screenBPP) {
char GLDriver[1024];
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
if (SDL_SetVideoMode(screenW, screenH, screenBPP, SDL_OPENGL) == 0)
error("Could not initialize video");
sprintf(GLDriver, "Residual: %s/%s", glGetString(GL_VENDOR), glGetString(GL_RENDERER));
SDL_WM_SetCaption(GLDriver, "Residual");
// FIXME: Hacky temporary font renderer code
hackFont = glGenLists(256);
#ifdef WIN32
{
HDC hDC;
HFONT font;
SDL_SysWMinfo wmi;
SDL_VERSION(&wmi.version);
SDL_GetWMInfo(&wmi);
hDC = GetDC(wmi.window);
font = CreateFont(0, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, 0 ,
FF_DONTCARE|DEFAULT_PITCH, "Courier New");
SelectObject(hDC, font);
wglUseFontBitmaps(hDC, 0, 256, hackFont);
}
#else
{
// Display *dpy = XOpenDisplay(NULL);
// XFontStruct *XFont = XLoadQueryFont(dpy, "-misc-fixed-medium-r-*-*-20-*-*-*-*-*-*-*" );
// glXUseXFont(XFont->fid, 0, 256, hackFont);
// XFreeFont(dpy, XFont);
// XCloseDisplay(dpy);
}
#endif
}
void Driver::setupCamera(float fov, float fclip, float nclip) {
// Set perspective transformation
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// gluPerspective(std::atan(std::tan(fov_ / 2 * (M_PI/180)) * 0.75) * 2 * (180/M_PI), 4.0f / 3, nclip_, fclip_);
float right = nclip * std::tan(fov / 2 * (M_PI/180));
glFrustum(-right, right, -right * 0.75, right * 0.75, nclip, fclip);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void Driver::positionCamera(float roll, Vector3d pos, Vector3d interest) {
Vector3d up_vec(0, 0, 1);
glRotatef(roll, 0, 0, -1);
if (pos.x() == interest.x() && pos.y() == interest.y())
up_vec = Vector3d(0, 1, 0);
gluLookAt(pos.x(), pos.y(), pos.z(),
interest.x(), interest.y(), interest.z(),
up_vec.x(), up_vec.y(), up_vec.z());
}
void Driver::clearScreen() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void Driver::flipBuffer() {
SDL_GL_SwapBuffers();
}
void Driver::startActorDraw(Vector3d pos, float yaw, float pitch, float roll) {
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(pos.x(), pos.y(), pos.z());
glRotatef(yaw, 0, 0, 1);
glRotatef(pitch, 1, 0, 0);
glRotatef(roll, 0, 1, 0);
}
void Driver::finishActorDraw() {
glPopMatrix();
}
void Driver::drawDepthBitmap(int num, int x, int y, int w, int h, char **data) {
if (num != 0) {
warning("Animation not handled yet in GL texture path !\n");
}
glRasterPos2i(x, y);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_ALWAYS);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glDepthMask(GL_TRUE);
/* This loop here is to prevent using PixelZoom that may be unoptimized for the 1.0 / -1.0 case
in some drivers...
*/
for (int row = 0; row < h; row++) {
glRasterPos2i(x, y + row + 1);
glDrawPixels(w, 1, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, data[num] + (2 * row * w));
}
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthFunc(GL_LESS);
}
void Driver::drawHackFont(int x, int y, const char *text, Color &fgColor) {
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, 640, 480, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glColor3f(fgColor.red(), fgColor.green(), fgColor.blue());
glRasterPos2i(x, y);
glListBase(hackFont);
glCallLists(strlen(strrchr(text, '/')) - 1, GL_UNSIGNED_BYTE, strrchr(text, '/') + 1);
glMatrixMode( GL_PROJECTION );
glPopMatrix();
}
// drawSMUSHframe, used for quickly pushing full-screen images from cutscenes
void Driver::drawSMUSHframe(int _width, int _height, uint8 *_dst) {
int num_tex_;
GLuint *tex_ids_;
// create texture
num_tex_ = ((_width + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE) *
((_height + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE);
tex_ids_ = new GLuint[num_tex_];
glGenTextures(num_tex_, tex_ids_);
for (int i = 0; i < num_tex_; i++) {
glBindTexture(GL_TEXTURE_2D, tex_ids_[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
BITMAP_TEXTURE_SIZE, BITMAP_TEXTURE_SIZE, 0,
GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL);
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
glPixelStorei(GL_UNPACK_ROW_LENGTH, _width);
glPixelStorei(GL_UNPACK_ROW_LENGTH, _width);
int cur_tex_idx = 0;
for (int y = 0; y < _height; y += BITMAP_TEXTURE_SIZE) {
for (int x = 0; x < _width; x += BITMAP_TEXTURE_SIZE) {
int width = (x + BITMAP_TEXTURE_SIZE >= _width) ? (_width - x) : BITMAP_TEXTURE_SIZE;
int height = (y + BITMAP_TEXTURE_SIZE >= _height) ? (_height - y) : BITMAP_TEXTURE_SIZE;
glBindTexture(GL_TEXTURE_2D, tex_ids_[cur_tex_idx]);
glTexSubImage2D(GL_TEXTURE_2D,
0,
0, 0,
width, height,
GL_RGB,
GL_UNSIGNED_SHORT_5_6_5,
_dst + (y * 2 * _width) + (2 * x));
cur_tex_idx++;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// prepare view
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 640, 480, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
// A lot more may need to be put there : disabling Alpha test, blending, ...
// For now, just keep this here :-)
glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
// draw
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glEnable(GL_SCISSOR_TEST);
cur_tex_idx = 0;
for (int y = 0; y < _height; y += BITMAP_TEXTURE_SIZE) {
for (int x = 0; x < _width; x += BITMAP_TEXTURE_SIZE) {
int width = (x + BITMAP_TEXTURE_SIZE >= _width) ? (_width - x) : BITMAP_TEXTURE_SIZE;
int height = (y + BITMAP_TEXTURE_SIZE >= _height) ? (_height - y) : BITMAP_TEXTURE_SIZE;
glBindTexture(GL_TEXTURE_2D, tex_ids_[cur_tex_idx]);
glScissor(x, 480 - (y + height), x + width, 480 - y);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex2i(x, y);
glTexCoord2f(1.0, 0.0);
glVertex2i(x + BITMAP_TEXTURE_SIZE, y);
glTexCoord2f(1.0, 1.0);
glVertex2i(x + BITMAP_TEXTURE_SIZE, y + BITMAP_TEXTURE_SIZE);
glTexCoord2f(0.0, 1.0);
glVertex2i(x, y + BITMAP_TEXTURE_SIZE);
glEnd();
cur_tex_idx++;
}
}
glDisable(GL_SCISSOR_TEST);
glDisable(GL_TEXTURE_2D);
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
SDL_GL_SwapBuffers();
// remove
glDeleteTextures(num_tex_, tex_ids_);
delete[] tex_ids_;
}

37
driver_gl.h Normal file
View File

@ -0,0 +1,37 @@
// Driver:
#include <SDL.h>
#include <SDL_opengl.h>
// Residual:
#include "bits.h"
#include "vector3d.h"
#include "color.h"
#define BITMAP_TEXTURE_SIZE 256
class Driver {
public:
Driver(int screenW, int screenH, int screenBPP);
void setupCamera(float fov, float nclip, float fclip);
void positionCamera(float roll, Vector3d pos, Vector3d interest);
void clearScreen();
void flipBuffer();
void startActorDraw(Vector3d pos, float yaw, float pitch, float roll);
void finishActorDraw();
void drawDepthBitmap(int num, int x, int y, int w, int h, char **data);
void drawBitmap();
void drawHackFont(int x, int y, const char *text, Color &fgColor);
void drawSMUSHframe(int _width, int _height, uint8 *_dst);
private:
GLuint hackFont; // FIXME: Temporary font drawing hack
};
extern Driver *g_driver;

View File

@ -23,10 +23,10 @@
#include "actor.h"
#include "textobject.h"
#include <SDL.h>
#include <SDL_opengl.h>
#include <SDL_timer.h>
#include <assert.h>
#include "screen.h"
#include "driver_gl.h"
Engine *Engine::instance_ = NULL;
@ -88,9 +88,9 @@ void Engine::mainLoop() {
screenBlocksReset();
// Draw the screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
g_driver->clearScreen();
Bitmap::prepareGL();
Bitmap::prepareDraw();
if (currScene_ != NULL)
currScene_->drawBackground();
@ -98,7 +98,7 @@ void Engine::mainLoop() {
if (currScene_ != NULL)
currScene_->setupCamera();
glMatrixMode(GL_MODELVIEW);
glMatrixMode(GL_MODELVIEW);
// Update actor costumes
for (actor_list_type::iterator i = actors_.begin();
i != actors_.end(); i++) {
@ -122,7 +122,7 @@ void Engine::mainLoop() {
if (SCREENBLOCKS_GLOBAL == 1)
screenBlocksBlitDirtyBlocks();
Bitmap::prepareGL();
Bitmap::prepareDraw();
if (currScene_ != NULL)
currScene_->drawBackground();
@ -149,7 +149,7 @@ void Engine::mainLoop() {
(*i)->draw();
}
SDL_GL_SwapBuffers();
g_driver->flipBuffer();
// Update timing information
unsigned newStart = SDL_GetTicks();

View File

@ -80,8 +80,6 @@ enum {
class Engine {
public:
GLuint font; // FIXME: Temporary font drawing hack
static Engine *instance() {
if (instance_ == NULL)
instance_ = new Engine;

View File

@ -18,7 +18,6 @@
#include "stdafx.h"
#include <SDL.h>
#include <SDL_video.h>
#include <SDL_opengl.h>
#include "bitmap.h"
#include "resource.h"
#include "debug.h"
@ -28,19 +27,12 @@
#include "sound.h"
#include "timer.h"
#include "mixer/mixer.h"
#include "driver_gl.h"
#ifndef _MSC_VER
#include <unistd.h>
#endif
// Hacky includes for temporary font rendering
#ifndef WIN32
#include <GL/glx.h>
#include <X11/Xlib.h>
#else
#include <SDL_syswm.h>
#include <windows.h>
#endif
// Hacky global toggles for experimental/debug code
int ZBUFFER_GLOBAL, SCREENBLOCKS_GLOBAL;
@ -58,7 +50,6 @@ extern SoundMixer *g_mixer;
extern Timer *g_timer;
int main(int argc, char *argv[]) {
char GLDriver[1024];
int i;
// Parse command line
@ -81,29 +72,23 @@ int main(int argc, char *argv[]) {
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
return 1;
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
if (SDL_SetVideoMode(640, 480, 24, SDL_OPENGL) == 0)
error("Could not initialize video");
g_driver = new Driver(640, 480, 24);
atexit(SDL_Quit);
atexit(saveRegistry);
sprintf(GLDriver, "Residual: %s/%s", glGetString(GL_VENDOR), glGetString(GL_RENDERER));
SDL_WM_SetCaption(GLDriver, "Residual");
Bitmap *splash_bm = ResourceLoader::instance()->loadBitmap("splash.bm");
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_VIDEOEXPOSE) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Bitmap::prepareGL();
g_driver->clearScreen();
Bitmap::prepareDraw();
splash_bm->draw();
SDL_GL_SwapBuffers();
g_driver->flipBuffer();
}
}
@ -133,32 +118,6 @@ int main(int argc, char *argv[]) {
lua_call("BOOT");
lua_endblock();
// FIXME: Hacky temporary font renderer code
Engine::instance()->font = glGenLists(256);
#ifdef WIN32
{
HDC hDC;
HFONT font;
SDL_SysWMinfo wmi;
SDL_VERSION(&wmi.version);
SDL_GetWMInfo(&wmi);
hDC = GetDC(wmi.window);
font = CreateFont(0, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, 0 ,
FF_DONTCARE|DEFAULT_PITCH, "Courier New");
SelectObject(hDC, font);
wglUseFontBitmaps(hDC, 0, 256, Engine::instance()->font);
}
#else
{
Display *dpy = XOpenDisplay(NULL);
XFontStruct *XFont = XLoadQueryFont(dpy, "-misc-fixed-medium-r-*-*-20-*-*-*-*-*-*-*" );
glXUseXFont(XFont->fid, 0, 256, Engine::instance()->font);
XFreeFont(dpy, XFont);
XCloseDisplay(dpy);
}
#endif
Engine::instance()->mainLoop();
delete g_timer;

View File

@ -24,9 +24,9 @@
#include "colormap.h"
#include "vector3d.h"
#include <SDL.h>
#include <SDL_opengl.h>
#include <cmath>
#include "screen.h"
#include "driver_gl.h"
Scene::Scene(const char *name, const char *buf, int len) :
name_(name) {
@ -144,26 +144,8 @@ void Scene::Light::load(TextSplitter &ts) {
}
void Scene::Setup::setupCamera() const {
// Set perspective transformation
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// gluPerspective(std::atan(std::tan(fov_ / 2 * (M_PI/180)) * 0.75) * 2 * (180/M_PI), 4.0f / 3, nclip_, fclip_);
float right = nclip_ * std::tan(fov_ / 2 * (M_PI/180));
glFrustum(-right, right, -right * 0.75, right * 0.75, nclip_, fclip_);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Apply camera roll
glRotatef(roll_, 0, 0, -1);
// Set camera position and direction
Vector3d up_vec(0, 0, 1);
if (pos_.x() == interest_.x() && pos_.y() == interest_.y())
up_vec = Vector3d(0, 1, 0);
gluLookAt(pos_.x(), pos_.y(), pos_.z(),
interest_.x(), interest_.y(), interest_.z(),
up_vec.x(), up_vec.y(), up_vec.z());
g_driver->setupCamera(fov_, nclip_, fclip_);
g_driver->positionCamera(roll_, pos_, interest_);
}
void Scene::setSetup(int num)

103
smush.cpp
View File

@ -22,8 +22,7 @@
#include "smush.h"
#include "timer.h"
#include "mixer/mixer.h"
#include <SDL.h>
#include <SDL_opengl.h>
#include "driver_gl.h"
Smush *smush;
@ -90,101 +89,6 @@ void Smush::handleWave(const byte *src, uint32 size) {
g_mixer->appendStream(_soundHandle, (byte *)dst, size * _channels * 2);
}
#define BITMAP_TEXTURE_SIZE 256
void Smush::updateGLScreen() {
int num_tex_;
GLuint *tex_ids_;
// create texture
num_tex_ = ((_width + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE) *
((_height + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE);
tex_ids_ = new GLuint[num_tex_];
glGenTextures(num_tex_, tex_ids_);
for (int i = 0; i < num_tex_; i++) {
glBindTexture(GL_TEXTURE_2D, tex_ids_[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
BITMAP_TEXTURE_SIZE, BITMAP_TEXTURE_SIZE, 0,
GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL);
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
glPixelStorei(GL_UNPACK_ROW_LENGTH, _width);
int cur_tex_idx = 0;
for (int y = 0; y < _height; y += BITMAP_TEXTURE_SIZE) {
for (int x = 0; x < _width; x += BITMAP_TEXTURE_SIZE) {
int width = (x + BITMAP_TEXTURE_SIZE >= _width) ? (_width - x) : BITMAP_TEXTURE_SIZE;
int height = (y + BITMAP_TEXTURE_SIZE >= _height) ? (_height - y) : BITMAP_TEXTURE_SIZE;
glBindTexture(GL_TEXTURE_2D, tex_ids_[cur_tex_idx]);
glTexSubImage2D(GL_TEXTURE_2D,
0,
0, 0,
width, height,
GL_RGB,
GL_UNSIGNED_SHORT_5_6_5,
_dst + (y * 2 * _width) + (2 * x));
cur_tex_idx++;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// prepare view
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 640, 480, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
// A lot more may need to be put there : disabling Alpha test, blending, ...
// For now, just keep this here :-)
glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
// draw
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glEnable(GL_SCISSOR_TEST);
cur_tex_idx = 0;
for (int y = 0; y < _height; y += BITMAP_TEXTURE_SIZE) {
for (int x = 0; x < _width; x += BITMAP_TEXTURE_SIZE) {
int width = (x + BITMAP_TEXTURE_SIZE >= _width) ? (_width - x) : BITMAP_TEXTURE_SIZE;
int height = (y + BITMAP_TEXTURE_SIZE >= _height) ? (_height - y) : BITMAP_TEXTURE_SIZE;
glBindTexture(GL_TEXTURE_2D, tex_ids_[cur_tex_idx]);
glScissor(x, 480 - (y + height), x + width, 480 - y);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex2i(x, y);
glTexCoord2f(1.0, 0.0);
glVertex2i(x + BITMAP_TEXTURE_SIZE, y);
glTexCoord2f(1.0, 1.0);
glVertex2i(x + BITMAP_TEXTURE_SIZE, y + BITMAP_TEXTURE_SIZE);
glTexCoord2f(0.0, 1.0);
glVertex2i(x, y + BITMAP_TEXTURE_SIZE);
glEnd();
cur_tex_idx++;
}
}
glDisable(GL_SCISSOR_TEST);
glDisable(GL_TEXTURE_2D);
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
SDL_GL_SwapBuffers();
// remove
glDeleteTextures(num_tex_, tex_ids_);
delete[] tex_ids_;
}
void Smush::handleFrame() {
uint32 tag;
int32 size;
@ -216,7 +120,8 @@ void Smush::handleFrame() {
if (_frame == _nbframes) {
_videoFinished = true;
}
updateGLScreen();
g_driver->drawSMUSHframe(_width, _height, _dst);
}
void Smush::handleFramesHeader() {
@ -538,4 +443,4 @@ uint32 File::readUint32BE() {
uint32 b = readUint16BE();
uint32 a = readUint16BE();
return (b << 16) | a;
}
}

View File

@ -19,6 +19,7 @@
#include "textobject.h"
#include "engine.h"
#include "localize.h"
#include "driver_gl.h"
TextObject::TextObject(const char *text, const int x, const int y, const Color& fgColor) :
fgColor_(fgColor), x_(x), y_(y) {
@ -32,25 +33,8 @@ void TextObject::setColor(Color *newcolor) {fgColor_ = newcolor;}
void TextObject::draw() {
const char *localString = Localizer::instance()->localize(textID_).c_str();
//warning("Drawing text object %s at (%d,%d): %s", textID_, x_, y_, localString);
glMatrixMode( GL_PROJECTION );
glPushMatrix();
glLoadIdentity();
glOrtho(0, 640, 480, 0, 0, 1);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glColor3f(fgColor_.red(), fgColor_.green(), fgColor_.blue());
glRasterPos2i(x_, y_);
glListBase(Engine::instance()->font);
glCallLists(
strlen(strrchr(localString, '/')) - 1,
GL_UNSIGNED_BYTE,
strrchr(localString, '/') + 1
);
glMatrixMode( GL_PROJECTION );
glPopMatrix();
g_driver->drawHackFont(x_, y_, localString, fgColor_);
}