|
|
@ -25,8 +25,6 @@ |
|
|
|
#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); |
|
|
@ -117,7 +115,7 @@ typedef size_t (*Lib3dsIoWriteFunc)(void *self, const void *buffer, size_t size) |
|
|
|
IO3ds io(data); |
|
|
|
Lib3dsFile *f = lib3ds_file_new(); |
|
|
|
if (!lib3ds_file_read(f, io.io())) { |
|
|
|
qDebug("data size: %i", (int) data.size()); |
|
|
|
// qDebug("data size: %i", (int) data.size());
|
|
|
|
lib3ds_file_free(f); |
|
|
|
return NULL; |
|
|
|
} |
|
|
@ -126,13 +124,13 @@ typedef size_t (*Lib3dsIoWriteFunc)(void *self, const void *buffer, size_t size) |
|
|
|
|
|
|
|
QByteArray loadResource(const QString &filename) { |
|
|
|
QResource res(filename); |
|
|
|
qDebug("res size: %i", (int) res.size()); |
|
|
|
// 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) { |
|
|
|
: QObject(parent), m_pieces(0), m_buffers(0), m_pawn_list(0) { |
|
|
|
m_board = new QImage*[2]; |
|
|
|
m_board[0] = new QImage(":/media/board2_white.png"); |
|
|
|
m_board[1] = new QImage(":/media/board2_dark.png"); |
|
|
@ -142,6 +140,7 @@ typedef size_t (*Lib3dsIoWriteFunc)(void *self, const void *buffer, size_t size) |
|
|
|
|
|
|
|
PieceLibrary::~PieceLibrary() { |
|
|
|
if (m_pawn) lib3ds_file_free(m_pawn); |
|
|
|
if (m_pawn_list) glDeleteLists(m_pawn_list, 1); |
|
|
|
delete [] m_pieces; |
|
|
|
delete [] m_buffers; |
|
|
|
delete [] m_board; |
|
|
@ -190,9 +189,16 @@ typedef size_t (*Lib3dsIoWriteFunc)(void *self, const void *buffer, size_t size) |
|
|
|
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++) { |
|
|
|
glNormal3fv(m_pawn->meshes->faceL[i].normal); |
|
|
|
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, m_pawn->meshes->faceL[i].points); |
|
|
|
if (m_pawn_list) { |
|
|
|
glCallList(m_pawn_list); |
|
|
|
} else { |
|
|
|
m_pawn_list = glGenLists(1); |
|
|
|
if (m_pawn_list) glNewList(m_pawn_list, GL_COMPILE_AND_EXECUTE); |
|
|
|
for (unsigned int i = 0; i < m_pawn->meshes->faces; i++) { |
|
|
|
glNormal3fv(m_pawn->meshes->faceL[i].normal); |
|
|
|
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, m_pawn->meshes->faceL[i].points); |
|
|
|
} |
|
|
|
if (m_pawn_list) glEndList(); |
|
|
|
} |
|
|
|
glDisableClientState(GL_VERTEX_ARRAY); |
|
|
|
} |
|
|
|