Implement drawing bitmapped objects.
This commit is contained in:
parent
1db7c464cf
commit
3d67f2bbbf
12 changed files with 66 additions and 25 deletions
2
Makefile
2
Makefile
|
@ -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 \
|
||||
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 \
|
||||
mixer/mixer.o mixer/rate.o mixer/audiostream.o
|
||||
objectstate.o mixer/mixer.o mixer/rate.o mixer/audiostream.o
|
||||
|
||||
DEPS = $(OBJS:.o=.d)
|
||||
|
||||
|
|
2
TODO
2
TODO
|
@ -2,7 +2,7 @@ Residual TODO list (in rough order of priority):
|
|||
------------------------------------------------
|
||||
Assigned tasks:
|
||||
* Add LAF font and text drawing support (aquadran)
|
||||
* Implement drawing 2D objects (ender)
|
||||
* Implement drawing 2D objects (frob)
|
||||
|
||||
Unassigned (help wanted):
|
||||
* Add OpenGL lighting (ender, possibly)
|
||||
|
|
|
@ -110,7 +110,7 @@ Resource(filename) {
|
|||
}
|
||||
}
|
||||
|
||||
void Bitmap::prepareDraw() {
|
||||
void Bitmap::draw() const {
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0, 640, 480, 0, 0, 1);
|
||||
|
@ -122,9 +122,6 @@ void Bitmap::prepareDraw() {
|
|||
// For now, just keep this here :-)
|
||||
glDisable(GL_LIGHTING);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void Bitmap::draw() const {
|
||||
if (format_ == 1) { // Normal image
|
||||
if (curr_image_ != 0) {
|
||||
warning("Animation not handled yet in GL texture path !\n");
|
||||
|
@ -132,13 +129,13 @@ void Bitmap::draw() const {
|
|||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glScissor(x_, 480 - (y_ + height_), width_, height_);
|
||||
int cur_tex_idx = 0;
|
||||
for (int y = y_; y < (y_ + height_); y += 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 height = (y + BITMAP_TEXTURE_SIZE >= (y_ + height_)) ? ((y_ + 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);
|
||||
|
|
2
bitmap.h
2
bitmap.h
|
@ -27,8 +27,6 @@ public:
|
|||
// Construct a bitmap from the given data.
|
||||
Bitmap(const char *filename, const char *data, int len);
|
||||
|
||||
// Set up Driver for drawing bitmaps
|
||||
static void prepareDraw();
|
||||
void draw() const;
|
||||
|
||||
// Set which image in an animated bitmap to use
|
||||
|
|
12
costume.cpp
12
costume.cpp
|
@ -87,14 +87,12 @@ class BitmapComponent : public Costume::Component {
|
|||
public:
|
||||
BitmapComponent(Costume::Component *parent, int parentID, const char *filename);
|
||||
|
||||
void update();
|
||||
void draw();
|
||||
void setKey(int val);
|
||||
|
||||
private:
|
||||
std::string filename_;
|
||||
std::string zbuf_filename_;
|
||||
ResPtr<Bitmap> bitmap_;
|
||||
ResPtr<Bitmap> zbuffer_;
|
||||
};
|
||||
|
||||
class ModelComponent : public Costume::Component {
|
||||
|
@ -158,13 +156,11 @@ BitmapComponent::BitmapComponent(Costume::Component *parent, int parentID,
|
|||
Costume::Component(parent, parentID), filename_(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::update() {
|
||||
void BitmapComponent::setKey(int val) {
|
||||
// bitmap_->setNumber(val);
|
||||
}
|
||||
|
||||
ModelComponent::ModelComponent(Costume::Component *parent, int parentID,
|
||||
|
|
|
@ -112,9 +112,11 @@ void Engine::mainLoop() {
|
|||
if (SCREENBLOCKS_GLOBAL == 1)
|
||||
screenBlocksBlitDirtyBlocks();
|
||||
|
||||
Bitmap::prepareDraw();
|
||||
if (currScene_ != NULL)
|
||||
if (currScene_ != NULL) {
|
||||
currScene_->drawBackground();
|
||||
currScene_->drawBitmaps(ObjectState::OBJSTATE_UNDERLAY);
|
||||
currScene_->drawBitmaps(ObjectState::OBJSTATE_STATE);
|
||||
}
|
||||
|
||||
if (g_smush->isPlaying()) {
|
||||
movieTime_ = g_smush->getMovieTime();
|
||||
|
@ -148,6 +150,8 @@ void Engine::mainLoop() {
|
|||
(*i)->draw();
|
||||
}
|
||||
|
||||
currScene_->drawBitmaps(ObjectState::OBJSTATE_OVERLAY);
|
||||
|
||||
g_driver->flipBuffer();
|
||||
}
|
||||
|
||||
|
|
11
lua.cpp
11
lua.cpp
|
@ -1087,8 +1087,8 @@ static void NewObjectState() {
|
|||
ObjectState::Position pos = check_objstate_pos(2); // When to draw
|
||||
char *bitmap = luaL_check_string(3); // Bitmap
|
||||
char *zbitmap = NULL; // Zbuffer Bitmap
|
||||
bool unk2 = getbool(5); // ?
|
||||
bool unk3 = getbool(6);
|
||||
bool unk1 = getbool(5); // ?
|
||||
bool unk2 = getbool(6);
|
||||
|
||||
if (!lua_isnil(lua_getparam(4)))
|
||||
zbitmap = luaL_check_string(4);
|
||||
|
@ -1096,8 +1096,11 @@ static void NewObjectState() {
|
|||
#ifndef OSX
|
||||
warning("Stub: newObjectState(%d, %d, %s, %s)", setupID, pos, bitmap, zbitmap);
|
||||
#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() {
|
||||
|
|
1
main.cpp
1
main.cpp
|
@ -98,7 +98,6 @@ int main(int argc, char *argv[]) {
|
|||
#endif
|
||||
g_driver->clearScreen();
|
||||
|
||||
Bitmap::prepareDraw();
|
||||
splash_bm->draw();
|
||||
|
||||
g_driver->flipBuffer();
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "vector3d.h"
|
||||
#include "resource.h"
|
||||
#include "bitmap.h"
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
|
@ -14,6 +15,26 @@ class ObjectState {
|
|||
OBJSTATE_OVERLAY = 2,
|
||||
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_;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -57,8 +57,11 @@ public:
|
|||
ResPtr(const ResPtr &p) { ptr_ = p.ptr_; if (ptr_ != NULL) ptr_->ref(); }
|
||||
ResPtr(T* ptr) { ptr_ = ptr; if (ptr_ != NULL) ptr_->ref(); }
|
||||
operator T*() { return ptr_; }
|
||||
operator const T*() const { return ptr_; }
|
||||
T& operator *() { return *ptr_; }
|
||||
const T& operator *() const { return *ptr_; }
|
||||
T* operator ->() { return ptr_; }
|
||||
const T* operator ->() const { return ptr_; }
|
||||
ResPtr& operator =(T* ptr) {
|
||||
if (ptr_ == ptr) return *this;
|
||||
if (ptr_ != NULL) ptr_->deref();
|
||||
|
|
11
scene.cpp
11
scene.cpp
|
@ -92,6 +92,9 @@ Scene::~Scene() {
|
|||
delete [] lights_;
|
||||
if (sectors_)
|
||||
delete [] sectors_;
|
||||
for (StateList::iterator i = states_.begin();
|
||||
i != states_.end(); i++)
|
||||
delete (*i);
|
||||
}
|
||||
|
||||
void Scene::Setup::load(TextSplitter &ts) {
|
||||
|
@ -158,3 +161,11 @@ void Scene::setSetup(int num) {
|
|||
else
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
9
scene.h
9
scene.h
|
@ -23,6 +23,7 @@
|
|||
#include "color.h"
|
||||
#include "debug.h"
|
||||
#include "walkplane.h"
|
||||
#include "objectstate.h"
|
||||
#include <SDL.h>
|
||||
#include <SDL_opengl.h>
|
||||
#include <string>
|
||||
|
@ -47,6 +48,7 @@ public:
|
|||
}
|
||||
currSetup_->bkgnd_bm_->draw();
|
||||
}
|
||||
void drawBitmaps(ObjectState::Position stage);
|
||||
void setupCamera() {
|
||||
currSetup_->setupCamera();
|
||||
}
|
||||
|
@ -65,6 +67,10 @@ public:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void addObjectState(ObjectState *s) {
|
||||
states_.push_back(s);
|
||||
}
|
||||
|
||||
private:
|
||||
struct Setup { // Camera setup data
|
||||
void load(TextSplitter &ts);
|
||||
|
@ -92,6 +98,9 @@ private:
|
|||
Light *lights_;
|
||||
Setup *setups_;
|
||||
Setup *currSetup_;
|
||||
|
||||
typedef std::list<ObjectState*> StateList;
|
||||
StateList states_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue