|
|
|
@ -27,8 +27,6 @@
|
|
|
|
|
|
|
|
|
|
#include <QGLPixelBuffer>
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
@ -55,13 +53,11 @@ namespace toruschess {
|
|
|
|
|
m_originX(0), m_originY(0), m_mouseLastX(0), m_mouseLastY(0),
|
|
|
|
|
m_skySphere(0), m_skyTextureID(0), m_skyTimerID(0), m_skyOffset(0),
|
|
|
|
|
m_pickTextureID(0) {
|
|
|
|
|
qDebug("Field3d::Field3D");
|
|
|
|
|
for (int x = 0; x < 8; x++) for (int y = 0; y < 8; y++) m_marked[x][y] = false;
|
|
|
|
|
m_lib->setSize(m_textureSize / 8, m_textureSize / 8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Field3D::~Field3D() {
|
|
|
|
|
qDebug("Field3d::~Field3D");
|
|
|
|
|
freeTexture();
|
|
|
|
|
|
|
|
|
|
if (m_skySphere) gluDeleteQuadric(m_skySphere);
|
|
|
|
@ -83,21 +79,23 @@ namespace toruschess {
|
|
|
|
|
void Field3D::initializeGL() {
|
|
|
|
|
glClearColor(0.0, 0.0, 0.0, 0.0);
|
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
|
// glEnable(GL_CULL_FACE);
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
|
glEnable(GL_LIGHT0);
|
|
|
|
|
glDisable(GL_LIGHT1);
|
|
|
|
|
glEnable(GL_COLOR_MATERIAL);
|
|
|
|
|
{
|
|
|
|
|
const GLfloat white[] = { 1.0, 1.0, 1.0, 1.0 },
|
|
|
|
|
inv[] = { 0.0, 0.0, 0.0, 0.0 };
|
|
|
|
|
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, white);
|
|
|
|
|
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, inv);
|
|
|
|
|
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, white);
|
|
|
|
|
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, inv);
|
|
|
|
|
glLightfv(GL_LIGHT0, GL_AMBIENT, white);
|
|
|
|
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, inv);
|
|
|
|
|
glLightfv(GL_LIGHT1, GL_AMBIENT, inv);
|
|
|
|
|
glLightfv(GL_LIGHT1, GL_DIFFUSE, white);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glFogi(GL_FOG_MODE, GL_EXP2);
|
|
|
|
@ -127,8 +125,8 @@ namespace toruschess {
|
|
|
|
|
void Field3D::paintGL() {
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
|
// m_lib->paint_pawn();
|
|
|
|
|
// return;
|
|
|
|
|
glEnable(GL_LIGHT0);
|
|
|
|
|
glDisable(GL_LIGHT1);
|
|
|
|
|
|
|
|
|
|
if (m_boardMode == TORUS) {
|
|
|
|
|
glDisable(GL_FOG);
|
|
|
|
@ -180,6 +178,29 @@ namespace toruschess {
|
|
|
|
|
glTexCoord2f( repeat+ox, -repeat+oy); glVertex3f( 10*repeat, 0, 10*repeat);
|
|
|
|
|
glTexCoord2f( repeat+ox, repeat+oy); glVertex3f( 10*repeat, 0, -10*repeat);
|
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
|
glEnable(GL_LIGHT1);
|
|
|
|
|
glDisable(GL_LIGHT0);
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
|
ox *= -10.0; oy *= 10.0;
|
|
|
|
|
ox += 10.0/16; oy += 10.0/16;
|
|
|
|
|
for (int i = 0; i < 8; i++) for (int j = 0; j < 8; j++) {
|
|
|
|
|
if (m_game->field()->piece(Pos(i, j)) == PAWN) {
|
|
|
|
|
if (m_game->field()->player(Pos(i, j)) == WHITE) {
|
|
|
|
|
glColor3f(1.0, 1.0, 1.0);
|
|
|
|
|
} else {
|
|
|
|
|
glColor3f(.0, .0, .0);
|
|
|
|
|
}
|
|
|
|
|
for (int x = -10; x <= 10; x++) for (int y = -10; y <= 10; y++) {
|
|
|
|
|
glPushMatrix();
|
|
|
|
|
glTranslatef(ox + 10.0/8.0*i + 10*x, 0, oy + 10.0/8.0*j + 10*y);
|
|
|
|
|
glRotatef(-90, 1, 0, 0);
|
|
|
|
|
m_lib->paint_pawn();
|
|
|
|
|
glPopMatrix();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
@ -235,7 +256,6 @@ namespace toruschess {
|
|
|
|
|
unsigned char pxbuf[3];
|
|
|
|
|
glReadPixels(mx, height() - 1 - my, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pxbuf);
|
|
|
|
|
paintGL();
|
|
|
|
|
qDebug() << pxbuf[0] << pxbuf[1];
|
|
|
|
|
p = Pos(pxbuf[0] - 50, pxbuf[1] - 50);
|
|
|
|
|
return pxbuf[0] >= 50;
|
|
|
|
|
}
|
|
|
|
@ -256,9 +276,7 @@ namespace toruschess {
|
|
|
|
|
|
|
|
|
|
void Field3D::createTexture() {
|
|
|
|
|
freeTexture();
|
|
|
|
|
// m_textureBuffer = new QGLPixelBuffer(QSize(m_textureSize, m_textureSize), QGLFormat::defaultFormat(), this);
|
|
|
|
|
m_textureBuffer = new QImage(QSize(m_textureSize, m_textureSize), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
|
// m_textureID = m_textureBuffer->generateDynamicTexture();
|
|
|
|
|
|
|
|
|
|
updateTexture();
|
|
|
|
|
|
|
|
|
@ -305,13 +323,12 @@ namespace toruschess {
|
|
|
|
|
m_textureID = 0;
|
|
|
|
|
}
|
|
|
|
|
if (m_textureBuffer) {
|
|
|
|
|
// delete m_textureBuffer;
|
|
|
|
|
delete m_textureBuffer;
|
|
|
|
|
m_textureBuffer = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Field3D::updateTexture() {
|
|
|
|
|
// m_textureBuffer->fill(Qt::black);
|
|
|
|
|
QPainter pt(m_textureBuffer);
|
|
|
|
|
pt.fillRect(QRect(0, 0, m_textureSize, m_textureSize), Qt::black);
|
|
|
|
|
|
|
|
|
@ -334,7 +351,6 @@ namespace toruschess {
|
|
|
|
|
pt.setCompositionMode(QPainter::CompositionMode_Plus);
|
|
|
|
|
pt.fillRect(0, 0, m_textureSize, m_textureSize, Qt::black);
|
|
|
|
|
pt.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
|
|
|
|
// m_textureBuffer->updateDynamicTexture(m_textureID);
|
|
|
|
|
if (m_textureID) deleteTexture(m_textureID);
|
|
|
|
|
m_textureID = bindTexture(*m_textureBuffer);
|
|
|
|
|
}
|
|
|
|
|