added some part of primitives code
This commit is contained in:
parent
443bb6bdf2
commit
39e3aed426
12 changed files with 227 additions and 5 deletions
|
@ -76,6 +76,7 @@ OBJS =\
|
||||||
matrix4.o \
|
matrix4.o \
|
||||||
model.o \
|
model.o \
|
||||||
objectstate.o \
|
objectstate.o \
|
||||||
|
primitive.o \
|
||||||
registry.o \
|
registry.o \
|
||||||
resource.o \
|
resource.o \
|
||||||
scene.o \
|
scene.o \
|
||||||
|
|
|
@ -780,6 +780,14 @@
|
||||||
RelativePath="..\..\objectstate.h"
|
RelativePath="..\..\objectstate.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\primitives.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\primitives.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\registry.cpp"
|
RelativePath="..\..\registry.cpp"
|
||||||
>
|
>
|
||||||
|
|
3
driver.h
3
driver.h
|
@ -25,6 +25,7 @@
|
||||||
#include "scene.h"
|
#include "scene.h"
|
||||||
#include "colormap.h"
|
#include "colormap.h"
|
||||||
#include "font.h"
|
#include "font.h"
|
||||||
|
#include "primitives.h"
|
||||||
|
|
||||||
class Material;
|
class Material;
|
||||||
class Bitmap;
|
class Bitmap;
|
||||||
|
@ -88,6 +89,8 @@ public:
|
||||||
virtual void drawTextBitmap(int x, int y, TextObjectHandle *handle) = 0;
|
virtual void drawTextBitmap(int x, int y, TextObjectHandle *handle) = 0;
|
||||||
virtual void destroyTextBitmap(TextObjectHandle *handle) = 0;
|
virtual void destroyTextBitmap(TextObjectHandle *handle) = 0;
|
||||||
|
|
||||||
|
virtual void drawRectangle(PrimitiveObject *primitive) = 0;
|
||||||
|
|
||||||
virtual void prepareSmushFrame(int width, int height, byte *bitmap) = 0;
|
virtual void prepareSmushFrame(int width, int height, byte *bitmap) = 0;
|
||||||
virtual void drawSmushFrame(int offsetX, int offsetY) = 0;
|
virtual void drawSmushFrame(int offsetX, int offsetY) = 0;
|
||||||
|
|
||||||
|
|
|
@ -686,3 +686,43 @@ void DriverGL::getSnapshot(int x, int y, int w, int h, char **data, int flags) {
|
||||||
|
|
||||||
void DriverGL::drawDim() {
|
void DriverGL::drawDim() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DriverGL::drawRectangle(PrimitiveObject *primitive) {
|
||||||
|
int x1 = primitive->getX1();
|
||||||
|
int x2 = primitive->getX2();
|
||||||
|
int y1 = primitive->getY1();
|
||||||
|
int y2 = primitive->getY2();
|
||||||
|
|
||||||
|
Color color = primitive->getColor();
|
||||||
|
uint32 c = (color.red() << 24) | (color.green() << 16) | (color.blue() << 8) | 255;
|
||||||
|
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glLoadIdentity();
|
||||||
|
glOrtho(0, 640, 480, 0, 0, 1);
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glLoadIdentity();
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
glDepthMask(GL_FALSE);
|
||||||
|
|
||||||
|
if (primitive->isFilled()) {
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
} else {
|
||||||
|
glBegin(GL_LINES);
|
||||||
|
}
|
||||||
|
|
||||||
|
glColor3i(color.red(), color.green(), color.blue());
|
||||||
|
|
||||||
|
glVertex2i(x1, 480 - y1);
|
||||||
|
glVertex2i(x2, 480 - y1);
|
||||||
|
glVertex2i(x2, 480 - y2);
|
||||||
|
glVertex2i(x1, 480 - y2);
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
glDepthMask(GL_TRUE);
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glEnable(GL_LIGHTING);
|
||||||
|
}
|
||||||
|
|
|
@ -73,6 +73,8 @@ public:
|
||||||
void drawTextBitmap(int x, int y, TextObjectHandle *handle);
|
void drawTextBitmap(int x, int y, TextObjectHandle *handle);
|
||||||
void destroyTextBitmap(TextObjectHandle *handle);
|
void destroyTextBitmap(TextObjectHandle *handle);
|
||||||
|
|
||||||
|
void drawRectangle(PrimitiveObject *primitive);
|
||||||
|
|
||||||
void prepareSmushFrame(int width, int height, byte *bitmap);
|
void prepareSmushFrame(int width, int height, byte *bitmap);
|
||||||
void drawSmushFrame(int offsetX, int offsetY);
|
void drawSmushFrame(int offsetX, int offsetY);
|
||||||
|
|
||||||
|
|
|
@ -124,14 +124,14 @@ DriverTinyGL::~DriverTinyGL() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DriverTinyGL::toggleFullscreenMode() {
|
void DriverTinyGL::toggleFullscreenMode() {
|
||||||
Uint32 flags = SDL_HWSURFACE;
|
uint32 flags = SDL_HWSURFACE;
|
||||||
|
|
||||||
if (! _isFullscreen)
|
if (!_isFullscreen)
|
||||||
flags |= SDL_FULLSCREEN;
|
flags |= SDL_FULLSCREEN;
|
||||||
if (SDL_SetVideoMode(_screenWidth, _screenHeight, _screenBPP, flags) == 0)
|
if (SDL_SetVideoMode(_screenWidth, _screenHeight, _screenBPP, flags) == 0)
|
||||||
warning("Could not change fullscreen mode");
|
warning("Could not change fullscreen mode");
|
||||||
else
|
else
|
||||||
_isFullscreen = ! _isFullscreen;
|
_isFullscreen = !_isFullscreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DriverTinyGL::setupCamera(float fov, float nclip, float fclip, float roll) {
|
void DriverTinyGL::setupCamera(float fov, float nclip, float fclip, float roll) {
|
||||||
|
@ -474,3 +474,35 @@ void DriverTinyGL::getSnapshot(int x, int y, int w, int h, char **data, int flag
|
||||||
|
|
||||||
void DriverTinyGL::drawDim() {
|
void DriverTinyGL::drawDim() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DriverTinyGL::drawRectangle(PrimitiveObject *primitive) {
|
||||||
|
uint16 *dst = (uint16 *)_screen->pixels;
|
||||||
|
int x1 = primitive->getX1();
|
||||||
|
int x2 = primitive->getX2();
|
||||||
|
int y1 = primitive->getY1();
|
||||||
|
int y2 = primitive->getY2();
|
||||||
|
|
||||||
|
Color color = primitive->getColor();
|
||||||
|
uint16 c = ((color.red() & 0xF8) << 8) | ((color.green() & 0xFC) << 3) | (color.blue() >> 3);
|
||||||
|
|
||||||
|
if (primitive->isFilled()) {
|
||||||
|
for (; y1 < y2; y1++) {
|
||||||
|
for (int x = x1; x < x2; x++) {
|
||||||
|
WRITE_LE_UINT16(dst + 640 * y1 + x, c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (int x = x1; x < x2; x++) {
|
||||||
|
WRITE_LE_UINT16(dst + 640 * y1 + x, c);
|
||||||
|
}
|
||||||
|
for (int x = x1; x < x2; x++) {
|
||||||
|
WRITE_LE_UINT16(dst + 640 * y2 + x, c);
|
||||||
|
}
|
||||||
|
for (int y = y1; y1 < y2; y++) {
|
||||||
|
WRITE_LE_UINT16(dst + 640 * y + x1, c);
|
||||||
|
}
|
||||||
|
for (int y = y1; y1 < y2; y++) {
|
||||||
|
WRITE_LE_UINT16(dst + 640 * y + x2, c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -75,6 +75,8 @@ public:
|
||||||
void drawTextBitmap(int x, int y, TextObjectHandle *handle);
|
void drawTextBitmap(int x, int y, TextObjectHandle *handle);
|
||||||
void destroyTextBitmap(TextObjectHandle *handle);
|
void destroyTextBitmap(TextObjectHandle *handle);
|
||||||
|
|
||||||
|
void drawRectangle(PrimitiveObject *primitive);
|
||||||
|
|
||||||
void prepareSmushFrame(int width, int height, byte *bitmap);
|
void prepareSmushFrame(int width, int height, byte *bitmap);
|
||||||
void drawSmushFrame(int offsetX, int offsetY);
|
void drawSmushFrame(int offsetX, int offsetY);
|
||||||
|
|
||||||
|
|
|
@ -230,6 +230,11 @@ void Engine::mainLoop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw Primitives
|
||||||
|
for (PrimitiveListType::iterator i = _primitiveObjects.begin(); i != _primitiveObjects.end(); i++) {
|
||||||
|
(*i)->draw();
|
||||||
|
}
|
||||||
|
|
||||||
// Draw text
|
// Draw text
|
||||||
for (TextListType::iterator i = _textObjects.begin(); i != _textObjects.end(); i++) {
|
for (TextListType::iterator i = _textObjects.begin(); i != _textObjects.end(); i++) {
|
||||||
(*i)->draw();
|
(*i)->draw();
|
||||||
|
|
24
engine.h
24
engine.h
|
@ -21,6 +21,7 @@
|
||||||
#include "bits.h"
|
#include "bits.h"
|
||||||
#include "scene.h"
|
#include "scene.h"
|
||||||
#include "textobject.h"
|
#include "textobject.h"
|
||||||
|
#include "primitives.h"
|
||||||
#include "font.h"
|
#include "font.h"
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
|
|
||||||
|
@ -87,7 +88,7 @@ enum {
|
||||||
SDLK_AXIS_MOUSE_Y,
|
SDLK_AXIS_MOUSE_Y,
|
||||||
SDLK_AXIS_MOUSE_Z,
|
SDLK_AXIS_MOUSE_Z,
|
||||||
SDLK_EXTRA_LAST
|
SDLK_EXTRA_LAST
|
||||||
};
|
};
|
||||||
|
|
||||||
class Engine {
|
class Engine {
|
||||||
public:
|
public:
|
||||||
|
@ -144,6 +145,26 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Primitives Object Registration
|
||||||
|
typedef std::list<PrimitiveObject *> PrimitiveListType;
|
||||||
|
PrimitiveListType::const_iterator primitivesBegin() const {
|
||||||
|
return _primitiveObjects.begin();
|
||||||
|
}
|
||||||
|
PrimitiveListType::const_iterator primitivesEnd() const {
|
||||||
|
return _primitiveObjects.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void registerPrimitiveObject(PrimitiveObject *a) { _primitiveObjects.push_back(a); }
|
||||||
|
void killPrimitiveObject(PrimitiveObject *a) {
|
||||||
|
_primitiveObjects.remove(a);
|
||||||
|
}
|
||||||
|
void killPrimitiveObjects() {
|
||||||
|
while (!_primitiveObjects.empty()) {
|
||||||
|
delete _primitiveObjects.back();
|
||||||
|
_primitiveObjects.pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void savegameSave();
|
void savegameSave();
|
||||||
void savegameRestore();
|
void savegameRestore();
|
||||||
static void savegameGzread(void *data, int size);
|
static void savegameGzread(void *data, int size);
|
||||||
|
@ -173,6 +194,7 @@ private:
|
||||||
ActorListType _actors;
|
ActorListType _actors;
|
||||||
Actor *_selectedActor;
|
Actor *_selectedActor;
|
||||||
TextListType _textObjects;
|
TextListType _textObjects;
|
||||||
|
PrimitiveListType _primitiveObjects;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Engine *g_engine;
|
extern Engine *g_engine;
|
||||||
|
|
2
lua.cpp
2
lua.cpp
|
@ -1563,7 +1563,7 @@ static void BlastRect() {
|
||||||
lua_pushobject(tableObj);
|
lua_pushobject(tableObj);
|
||||||
lua_pushstring("filled");
|
lua_pushstring("filled");
|
||||||
lua_Object objFilled = lua_gettable();
|
lua_Object objFilled = lua_gettable();
|
||||||
if (!lua_isnil(objFilled))
|
if (!lua_isnil(objFilled))
|
||||||
filled = true;
|
filled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
57
primitives.cpp
Normal file
57
primitives.cpp
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
// Residual - Virtual machine to run LucasArts' 3D adventure games
|
||||||
|
// Copyright (C) 2003-2005 The ScummVM-Residual Team (www.scummvm.org)
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
#include "debug.h"
|
||||||
|
#include "font.h"
|
||||||
|
#include "color.h"
|
||||||
|
#include "driver.h"
|
||||||
|
#include "primitives.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
PrimitiveObject::PrimitiveObject() {
|
||||||
|
_x1 = 0;
|
||||||
|
_y1 = 0;
|
||||||
|
_x2 = 0;
|
||||||
|
_y2 = 0;
|
||||||
|
_color._vals[0] = 0;
|
||||||
|
_color._vals[1] = 0;
|
||||||
|
_color._vals[2] = 0;
|
||||||
|
_filled = false;
|
||||||
|
_type = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrimitiveObject::~PrimitiveObject() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrimitiveObject::createRectangle(int x1, int y1, int x2, int y2, Color color, bool filled) {
|
||||||
|
_x1 = x1;
|
||||||
|
_y1 = y1;
|
||||||
|
_x2 = x2;
|
||||||
|
_y2 = y2;
|
||||||
|
_color = color;
|
||||||
|
_filled = filled;
|
||||||
|
_type = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrimitiveObject::draw() {
|
||||||
|
assert(_type);
|
||||||
|
|
||||||
|
if (_type == 1)
|
||||||
|
g_driver->drawRectangle(this);
|
||||||
|
}
|
50
primitives.h
Normal file
50
primitives.h
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
// Residual - Virtual machine to run LucasArts' 3D adventure games
|
||||||
|
// Copyright (C) 2003-2005 The ScummVM-Residual Team (www.scummvm.org)
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; either
|
||||||
|
// version 2.1 of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
#ifndef PRIMITIVESOBJECT_H
|
||||||
|
#define PRIMITIVESOBJECT_H
|
||||||
|
|
||||||
|
#include "debug.h"
|
||||||
|
#include "font.h"
|
||||||
|
#include "color.h"
|
||||||
|
#include "driver.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
class PrimitiveObject {
|
||||||
|
public:
|
||||||
|
PrimitiveObject();
|
||||||
|
~PrimitiveObject();
|
||||||
|
|
||||||
|
void createRectangle(int x1, int y1, int x2, int y2, Color color, bool filled);
|
||||||
|
int getX1() { return _x1; }
|
||||||
|
int getX2() { return _x2; }
|
||||||
|
int getY1() { return _y1; }
|
||||||
|
int getY2() { return _y2; }
|
||||||
|
Color getColor() { return _color; }
|
||||||
|
bool isFilled() { return _filled; }
|
||||||
|
void draw();
|
||||||
|
|
||||||
|
private:
|
||||||
|
int _x1, _x2, _y1, _y2;
|
||||||
|
Color _color;
|
||||||
|
bool _filled;
|
||||||
|
int _type;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue