Implement drawing bitmapped objects.

This commit is contained in:
Daniel Schepler 2004-03-22 11:23:37 +00:00
parent 1db7c464cf
commit 3d67f2bbbf
12 changed files with 66 additions and 25 deletions

View file

@ -16,7 +16,7 @@ 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 \ 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 \ sound.o timer.o keyframe.o costume.o walkplane.o textobject.o \
matrix3.o matrix4.o screen.o blocky16.o smush.o vima.o driver_gl.o \ matrix3.o matrix4.o screen.o blocky16.o smush.o vima.o driver_gl.o \
mixer/mixer.o mixer/rate.o mixer/audiostream.o objectstate.o mixer/mixer.o mixer/rate.o mixer/audiostream.o
DEPS = $(OBJS:.o=.d) DEPS = $(OBJS:.o=.d)

2
TODO
View file

@ -2,7 +2,7 @@ Residual TODO list (in rough order of priority):
------------------------------------------------ ------------------------------------------------
Assigned tasks: Assigned tasks:
* Add LAF font and text drawing support (aquadran) * Add LAF font and text drawing support (aquadran)
* Implement drawing 2D objects (ender) * Implement drawing 2D objects (frob)
Unassigned (help wanted): Unassigned (help wanted):
* Add OpenGL lighting (ender, possibly) * Add OpenGL lighting (ender, possibly)

View file

@ -110,7 +110,7 @@ Resource(filename) {
} }
} }
void Bitmap::prepareDraw() { void Bitmap::draw() const {
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
glOrtho(0, 640, 480, 0, 0, 1); glOrtho(0, 640, 480, 0, 0, 1);
@ -122,9 +122,6 @@ void Bitmap::prepareDraw() {
// For now, just keep this here :-) // For now, just keep this here :-)
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
}
void Bitmap::draw() const {
if (format_ == 1) { // Normal image if (format_ == 1) { // Normal image
if (curr_image_ != 0) { if (curr_image_ != 0) {
warning("Animation not handled yet in GL texture path !\n"); warning("Animation not handled yet in GL texture path !\n");
@ -132,13 +129,13 @@ void Bitmap::draw() const {
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE); glDepthMask(GL_FALSE);
glEnable(GL_SCISSOR_TEST); glEnable(GL_SCISSOR_TEST);
glScissor(x_, 480 - (y_ + height_), width_, height_);
int cur_tex_idx = 0; int cur_tex_idx = 0;
for (int y = y_; y < (y_ + height_); y += BITMAP_TEXTURE_SIZE) { for (int y = y_; y < (y_ + height_); y += BITMAP_TEXTURE_SIZE) {
for (int x = x_; x < (x_ + width_); x += BITMAP_TEXTURE_SIZE) { for (int x = x_; x < (x_ + width_); x += BITMAP_TEXTURE_SIZE) {
int width = (x + BITMAP_TEXTURE_SIZE >= (x_ + width_)) ? ((x_ + width_) - x) : BITMAP_TEXTURE_SIZE; int width = (x + BITMAP_TEXTURE_SIZE >= (x_ + width_)) ? ((x_ + width_) - x) : BITMAP_TEXTURE_SIZE;
int height = (y + BITMAP_TEXTURE_SIZE >= (y_ + height_)) ? ((y_ + height_) - y) : BITMAP_TEXTURE_SIZE; int height = (y + BITMAP_TEXTURE_SIZE >= (y_ + height_)) ? ((y_ + height_) - y) : BITMAP_TEXTURE_SIZE;
glBindTexture(GL_TEXTURE_2D, tex_ids_[cur_tex_idx]); glBindTexture(GL_TEXTURE_2D, tex_ids_[cur_tex_idx]);
glScissor(x, 480 - (y + height), x + width, 480 - y);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glTexCoord2f(0.0, 0.0);
glVertex2i(x, y); glVertex2i(x, y);

View file

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

View file

@ -87,14 +87,12 @@ class BitmapComponent : public Costume::Component {
public: public:
BitmapComponent(Costume::Component *parent, int parentID, const char *filename); BitmapComponent(Costume::Component *parent, int parentID, const char *filename);
void update(); void setKey(int val);
void draw();
private: private:
std::string filename_; std::string filename_;
std::string zbuf_filename_; std::string zbuf_filename_;
ResPtr<Bitmap> bitmap_; ResPtr<Bitmap> bitmap_;
ResPtr<Bitmap> zbuffer_;
}; };
class ModelComponent : public Costume::Component { class ModelComponent : public Costume::Component {
@ -158,13 +156,11 @@ BitmapComponent::BitmapComponent(Costume::Component *parent, int parentID,
Costume::Component(parent, parentID), filename_(filename) { Costume::Component(parent, parentID), filename_(filename) {
bitmap_ = ResourceLoader::instance()->loadBitmap(filename); bitmap_ = ResourceLoader::instance()->loadBitmap(filename);
warning("Instanced BitmapComponenet from Costume renderer: NOT IMPLEMENTED YET"); warning("Instanced BitmapComponenet from Costume renderer with filename %s: NOT IMPLEMENTED YET", filename);
} }
void BitmapComponent::draw() { void BitmapComponent::setKey(int val) {
} // bitmap_->setNumber(val);
void BitmapComponent::update() {
} }
ModelComponent::ModelComponent(Costume::Component *parent, int parentID, ModelComponent::ModelComponent(Costume::Component *parent, int parentID,

View file

@ -112,9 +112,11 @@ void Engine::mainLoop() {
if (SCREENBLOCKS_GLOBAL == 1) if (SCREENBLOCKS_GLOBAL == 1)
screenBlocksBlitDirtyBlocks(); screenBlocksBlitDirtyBlocks();
Bitmap::prepareDraw(); if (currScene_ != NULL) {
if (currScene_ != NULL)
currScene_->drawBackground(); currScene_->drawBackground();
currScene_->drawBitmaps(ObjectState::OBJSTATE_UNDERLAY);
currScene_->drawBitmaps(ObjectState::OBJSTATE_STATE);
}
if (g_smush->isPlaying()) { if (g_smush->isPlaying()) {
movieTime_ = g_smush->getMovieTime(); movieTime_ = g_smush->getMovieTime();
@ -148,6 +150,8 @@ void Engine::mainLoop() {
(*i)->draw(); (*i)->draw();
} }
currScene_->drawBitmaps(ObjectState::OBJSTATE_OVERLAY);
g_driver->flipBuffer(); g_driver->flipBuffer();
} }

11
lua.cpp
View file

@ -1087,8 +1087,8 @@ static void NewObjectState() {
ObjectState::Position pos = check_objstate_pos(2); // When to draw ObjectState::Position pos = check_objstate_pos(2); // When to draw
char *bitmap = luaL_check_string(3); // Bitmap char *bitmap = luaL_check_string(3); // Bitmap
char *zbitmap = NULL; // Zbuffer Bitmap char *zbitmap = NULL; // Zbuffer Bitmap
bool unk2 = getbool(5); // ? bool unk1 = getbool(5); // ?
bool unk3 = getbool(6); bool unk2 = getbool(6);
if (!lua_isnil(lua_getparam(4))) if (!lua_isnil(lua_getparam(4)))
zbitmap = luaL_check_string(4); zbitmap = luaL_check_string(4);
@ -1096,8 +1096,11 @@ static void NewObjectState() {
#ifndef OSX #ifndef OSX
warning("Stub: newObjectState(%d, %d, %s, %s)", setupID, pos, bitmap, zbitmap); warning("Stub: newObjectState(%d, %d, %s, %s)", setupID, pos, bitmap, zbitmap);
#endif #endif
// object = scene.addObjectState;
// lua_pushusertag(object, object_tag); object = new ObjectState(setupID, pos, bitmap, zbitmap,
unk1, unk2);
Engine::instance()->currScene()->addObjectState(object);
lua_pushusertag(object, object_tag);
} }
static void FreeObjectState() { static void FreeObjectState() {

View file

@ -98,7 +98,6 @@ int main(int argc, char *argv[]) {
#endif #endif
g_driver->clearScreen(); g_driver->clearScreen();
Bitmap::prepareDraw();
splash_bm->draw(); splash_bm->draw();
g_driver->flipBuffer(); g_driver->flipBuffer();

View file

@ -3,6 +3,7 @@
#include "vector3d.h" #include "vector3d.h"
#include "resource.h" #include "resource.h"
#include "bitmap.h"
#include <string> #include <string>
#include <list> #include <list>
@ -14,6 +15,26 @@ class ObjectState {
OBJSTATE_OVERLAY = 2, OBJSTATE_OVERLAY = 2,
OBJSTATE_STATE = 3 OBJSTATE_STATE = 3
}; };
ObjectState(int setupID, ObjectState::Position pos,
const char *bitmap, const char *zbitmap,
bool unk1, bool unk2);
int setupID() const { return setupID_; }
Position pos() const { return pos_; }
const char *bitmapFilename() const {
return bitmap_->filename();
}
void draw() {
bitmap_->draw();
}
private:
int setupID_;
Position pos_;
ResPtr<Bitmap> bitmap_, zbitmap_;
bool unk1_, unk2_;
}; };

View file

@ -57,8 +57,11 @@ public:
ResPtr(const ResPtr &p) { ptr_ = p.ptr_; if (ptr_ != NULL) ptr_->ref(); } ResPtr(const ResPtr &p) { ptr_ = p.ptr_; if (ptr_ != NULL) ptr_->ref(); }
ResPtr(T* ptr) { ptr_ = ptr; if (ptr_ != NULL) ptr_->ref(); } ResPtr(T* ptr) { ptr_ = ptr; if (ptr_ != NULL) ptr_->ref(); }
operator T*() { return ptr_; } operator T*() { return ptr_; }
operator const T*() const { return ptr_; }
T& operator *() { return *ptr_; } T& operator *() { return *ptr_; }
const T& operator *() const { return *ptr_; }
T* operator ->() { return ptr_; } T* operator ->() { return ptr_; }
const T* operator ->() const { return ptr_; }
ResPtr& operator =(T* ptr) { ResPtr& operator =(T* ptr) {
if (ptr_ == ptr) return *this; if (ptr_ == ptr) return *this;
if (ptr_ != NULL) ptr_->deref(); if (ptr_ != NULL) ptr_->deref();

View file

@ -92,6 +92,9 @@ Scene::~Scene() {
delete [] lights_; delete [] lights_;
if (sectors_) if (sectors_)
delete [] sectors_; delete [] sectors_;
for (StateList::iterator i = states_.begin();
i != states_.end(); i++)
delete (*i);
} }
void Scene::Setup::load(TextSplitter &ts) { void Scene::Setup::load(TextSplitter &ts) {
@ -158,3 +161,11 @@ void Scene::setSetup(int num) {
else else
screenBlocksInitEmpty(); screenBlocksInitEmpty();
} }
void Scene::drawBitmaps(ObjectState::Position stage) {
for (StateList::iterator i = states_.begin(); i != states_.end();
i++) {
if ((*i)->pos() == stage && currSetup_ == setups_ + (*i)->setupID())
(*i)->draw();
}
}

View file

@ -23,6 +23,7 @@
#include "color.h" #include "color.h"
#include "debug.h" #include "debug.h"
#include "walkplane.h" #include "walkplane.h"
#include "objectstate.h"
#include <SDL.h> #include <SDL.h>
#include <SDL_opengl.h> #include <SDL_opengl.h>
#include <string> #include <string>
@ -47,6 +48,7 @@ public:
} }
currSetup_->bkgnd_bm_->draw(); currSetup_->bkgnd_bm_->draw();
} }
void drawBitmaps(ObjectState::Position stage);
void setupCamera() { void setupCamera() {
currSetup_->setupCamera(); currSetup_->setupCamera();
} }
@ -65,6 +67,10 @@ public:
return NULL; return NULL;
} }
void addObjectState(ObjectState *s) {
states_.push_back(s);
}
private: private:
struct Setup { // Camera setup data struct Setup { // Camera setup data
void load(TextSplitter &ts); void load(TextSplitter &ts);
@ -92,6 +98,9 @@ private:
Light *lights_; Light *lights_;
Setup *setups_; Setup *setups_;
Setup *currSetup_; Setup *currSetup_;
typedef std::list<ObjectState*> StateList;
StateList states_;
}; };
#endif #endif