xxx
This commit is contained in:
parent
7acd3fe1a3
commit
439b1822a6
Binary file not shown.
BIN
media/pawn.3ds
BIN
media/pawn.3ds
Binary file not shown.
BIN
media/pawn.blend
BIN
media/pawn.blend
Binary file not shown.
@ -77,6 +77,9 @@ namespace toruschess {
|
||||
void Field3D::paintGL() {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// m_lib->paint_pawn();
|
||||
// return;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, m_textureID);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
{
|
||||
|
@ -12,5 +12,6 @@
|
||||
<file alias="chess_10.svg">../media/Chess_rdt45.svg</file>
|
||||
<file alias="chess_11.svg">../media/Chess_qdt45.svg</file>
|
||||
<file alias="chess_12.svg">../media/Chess_kdt45.svg</file>
|
||||
<file alias="pawn.3ds">../media/pawn.3ds</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -20,15 +20,125 @@
|
||||
#include "piecelibrary.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QResource>
|
||||
|
||||
#include <lib3ds/io.h>
|
||||
#include <lib3ds/mesh.h>
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
namespace toruschess {
|
||||
typedef Lib3dsBool (*Lib3dsIoErrorFunc)(void *self);
|
||||
typedef long (*Lib3dsIoSeekFunc)(void *self, long offset, Lib3dsIoSeek origin);
|
||||
typedef long (*Lib3dsIoTellFunc)(void *self);
|
||||
typedef size_t (*Lib3dsIoReadFunc)(void *self, void *buffer, size_t size);
|
||||
typedef size_t (*Lib3dsIoWriteFunc)(void *self, const void *buffer, size_t size);
|
||||
|
||||
Lib3dsBool io3ds_error(void *self);
|
||||
long io3ds_seek(void *self, long offset, Lib3dsIoSeek origin);
|
||||
long io3ds_tell(void *self);
|
||||
size_t io3ds_read(void *self, void *buffer, size_t size);
|
||||
size_t io3ds_write(void *self, const void *buffer, size_t size);
|
||||
|
||||
class IO3ds {
|
||||
public:
|
||||
IO3ds(const QByteArray &data) : m_data(data), m_offset(0) {
|
||||
m_io = lib3ds_io_new(this, io3ds_error, io3ds_seek, io3ds_tell, io3ds_read, io3ds_write);
|
||||
}
|
||||
~IO3ds() {
|
||||
lib3ds_io_free(m_io);
|
||||
}
|
||||
|
||||
long seek(long offset, Lib3dsIoSeek origin) {
|
||||
switch (origin) {
|
||||
case LIB3DS_SEEK_SET:
|
||||
m_offset = offset;
|
||||
break;
|
||||
case LIB3DS_SEEK_CUR:
|
||||
m_offset += offset;
|
||||
break;
|
||||
case LIB3DS_SEEK_END:
|
||||
m_offset = m_data.length() + offset;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
long tell() { return m_offset; }
|
||||
size_t read(void *buffer, size_t size) {
|
||||
qDebug("read (size %i): data-len = %i, offset = %i", (int) size, m_data.length(), (int) m_offset);
|
||||
if (m_offset >= m_data.length()) return 0;
|
||||
size_t r = qMin(size, (size_t) m_data.length() - m_offset);
|
||||
memcpy(buffer, m_data.constData() + m_offset, r);
|
||||
m_offset += r;
|
||||
qDebug("read: done with %i", (int) r);
|
||||
return r;
|
||||
}
|
||||
size_t write(const void *, size_t ) {
|
||||
return 0;
|
||||
}
|
||||
Lib3dsBool error() {
|
||||
qDebug("3ds error");
|
||||
return true;
|
||||
}
|
||||
|
||||
Lib3dsIo* io() { return m_io; }
|
||||
|
||||
private:
|
||||
Lib3dsIo *m_io;
|
||||
QByteArray m_data;
|
||||
long m_offset;
|
||||
};
|
||||
|
||||
Lib3dsBool io3ds_error(void *self) {
|
||||
IO3ds *s = (IO3ds*) self;
|
||||
return s->error();
|
||||
}
|
||||
long io3ds_seek(void *self, long offset, Lib3dsIoSeek origin) {
|
||||
IO3ds *s = (IO3ds*) self;
|
||||
return s->seek(offset, origin);
|
||||
}
|
||||
long io3ds_tell(void *self) {
|
||||
IO3ds *s = (IO3ds*) self;
|
||||
return s->tell();
|
||||
}
|
||||
size_t io3ds_read(void *self, void *buffer, size_t size) {
|
||||
IO3ds *s = (IO3ds*) self;
|
||||
return s->read(buffer, size);
|
||||
}
|
||||
size_t io3ds_write(void *self, const void *buffer, size_t size) {
|
||||
IO3ds *s = (IO3ds*) self;
|
||||
return s->write(buffer, size);
|
||||
}
|
||||
|
||||
|
||||
Lib3dsFile *read_3ds(const QByteArray &data) {
|
||||
return lib3ds_file_load("media/pawn.3ds");
|
||||
IO3ds io(data);
|
||||
Lib3dsFile *f = lib3ds_file_new();
|
||||
if (!lib3ds_file_read(f, io.io())) {
|
||||
qDebug("data size: %i", (int) data.size());
|
||||
lib3ds_file_free(f);
|
||||
return NULL;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
QByteArray loadResource(const QString &filename) {
|
||||
QResource res(filename);
|
||||
qDebug("res size: %i", (int) res.size());
|
||||
return QByteArray((const char*) res.data(), (int) res.size());
|
||||
}
|
||||
|
||||
|
||||
PieceLibrary::PieceLibrary(QObject *parent)
|
||||
: QObject(parent), m_pieces(0), m_buffers(0) {
|
||||
m_pawn = read_3ds(loadResource(":/media/pawn.3ds"));
|
||||
setSize(45, 45);
|
||||
}
|
||||
|
||||
PieceLibrary::~PieceLibrary() {
|
||||
lib3ds_file_free(m_pawn);
|
||||
delete [] m_pieces;
|
||||
delete [] m_buffers;
|
||||
}
|
||||
@ -68,5 +178,15 @@ namespace toruschess {
|
||||
if (place <= 0 || place > 12) return;
|
||||
pt.drawImage(rect, *m_buffers[place-1]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PieceLibrary::paint_pawn() {
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(3,GL_FLOAT,0,m_pawn->meshes->pointL);
|
||||
for (unsigned int i = 0; i < m_pawn->meshes->faces; i++) {
|
||||
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, m_pawn->meshes->faceL[i].points);
|
||||
}
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,8 @@
|
||||
|
||||
#include <QSvgRenderer>
|
||||
|
||||
#include <lib3ds/file.h>
|
||||
|
||||
/**
|
||||
@author Stefan Bühler <stbuehler@web.de>
|
||||
*/
|
||||
@ -40,10 +42,14 @@ namespace toruschess {
|
||||
void paint(QPainter &pt, int place) const;
|
||||
void paint(QPainter &pt, int place, const QRect &rect) const;
|
||||
|
||||
void paint_pawn();
|
||||
|
||||
private:
|
||||
QSvgRenderer **m_pieces;
|
||||
QImage **m_buffers;
|
||||
int m_width, m_height;
|
||||
|
||||
Lib3dsFile *m_pawn;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -23,3 +23,5 @@ toruschess.h \
|
||||
field3d.h
|
||||
CONFIG -= release
|
||||
|
||||
LIBS += -l3ds
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user