2008-10-29 10:56:58 -07:00
|
|
|
/*
|
|
|
|
Copyright (C) 2008 by Warzone Resurrection Team
|
|
|
|
|
|
|
|
This program 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 3 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lessser General Public
|
|
|
|
License along with this program. If not, see
|
|
|
|
<http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "wzmglwidget.h"
|
|
|
|
|
2008-11-01 13:57:43 -07:00
|
|
|
#define gl_errors() really_report_gl_errors(__FILE__, __LINE__)
|
2010-04-29 14:48:31 -07:00
|
|
|
static void really_report_gl_errors(const char *file, int line)
|
2008-11-01 13:57:43 -07:00
|
|
|
{
|
|
|
|
GLenum error = glGetError();
|
|
|
|
|
|
|
|
if (error != GL_NO_ERROR)
|
|
|
|
{
|
|
|
|
qFatal("Oops, GL error caught: %s %s:%i", gluErrorString(error), file, line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-29 10:56:58 -07:00
|
|
|
WZMOpenGLWidget::WZMOpenGLWidget(QWidget *parent)
|
2010-04-29 14:48:31 -07:00
|
|
|
: QGLViewer(parent), psModel(NULL), teamIndex(0),
|
|
|
|
selectedMesh(-1), animation(false), now(0)
|
2008-10-29 10:56:58 -07:00
|
|
|
{
|
|
|
|
if (!QGLFormat::hasOpenGL())
|
|
|
|
{
|
|
|
|
qWarning("This system has no OpenGL support!");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
timer.start();
|
2009-02-07 10:21:06 -08:00
|
|
|
setAxisIsDrawn(true);
|
2008-10-29 10:56:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
WZMOpenGLWidget::~WZMOpenGLWidget()
|
|
|
|
{
|
2008-11-01 13:57:43 -07:00
|
|
|
glDisableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
2008-10-29 10:56:58 -07:00
|
|
|
freeModel(psModel);
|
|
|
|
}
|
|
|
|
|
2009-02-07 10:21:06 -08:00
|
|
|
void WZMOpenGLWidget::init()
|
2008-10-29 10:56:58 -07:00
|
|
|
{
|
|
|
|
qWarning("OpenGL version: %s", glGetString(GL_VERSION));
|
|
|
|
qWarning("OpenGL renderer: %s", glGetString(GL_RENDERER));
|
|
|
|
qWarning("OpenGL vendor: %s", glGetString(GL_VENDOR));
|
|
|
|
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glDisable(GL_FOG);
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
2010-04-29 14:48:31 -07:00
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glEnable(GL_ALPHA_TEST);
|
|
|
|
glAlphaFunc(GL_GEQUAL, 0.05f);
|
2008-10-29 10:56:58 -07:00
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
2008-11-01 13:57:43 -07:00
|
|
|
gl_errors();
|
2008-10-29 10:56:58 -07:00
|
|
|
}
|
|
|
|
|
2009-02-07 10:21:06 -08:00
|
|
|
void WZMOpenGLWidget::draw()
|
2008-10-29 10:56:58 -07:00
|
|
|
{
|
|
|
|
if (psModel)
|
|
|
|
{
|
2008-12-10 13:27:42 -08:00
|
|
|
if (animation)
|
|
|
|
{
|
|
|
|
now = timer.elapsed();
|
|
|
|
}
|
2008-10-29 10:56:58 -07:00
|
|
|
|
2010-04-29 14:48:31 -07:00
|
|
|
drawModel(psModel, now, selectedMesh);
|
2008-10-29 10:56:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-27 01:16:49 -07:00
|
|
|
void WZMOpenGLWidget::selectMesh(int index)
|
|
|
|
{
|
2010-04-29 14:48:31 -07:00
|
|
|
selectedMesh = index - 1;
|
2010-04-27 01:16:49 -07:00
|
|
|
}
|
|
|
|
|
2008-10-29 10:56:58 -07:00
|
|
|
void WZMOpenGLWidget::setTeam(int index)
|
|
|
|
{
|
|
|
|
if (!psModel)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2010-04-28 18:26:06 -07:00
|
|
|
|
2008-10-29 10:56:58 -07:00
|
|
|
if (index > 7 || index < 0)
|
|
|
|
{
|
|
|
|
qWarning("setTeam: Bad index %d", index);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < psModel->meshes; i++)
|
|
|
|
{
|
|
|
|
MESH *psMesh = &psModel->mesh[i];
|
|
|
|
|
|
|
|
if (!psMesh->teamColours)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
psMesh->currentTextureArray = index;
|
|
|
|
}
|
|
|
|
teamIndex = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WZMOpenGLWidget::setAnimation(bool value)
|
|
|
|
{
|
|
|
|
animation = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WZMOpenGLWidget::setModel(MODEL *model)
|
|
|
|
{
|
2009-02-07 10:21:06 -08:00
|
|
|
double dimension;
|
|
|
|
|
2008-10-29 10:56:58 -07:00
|
|
|
if (!model)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
prepareModel(model);
|
2008-11-01 13:57:43 -07:00
|
|
|
gl_errors();
|
|
|
|
psModel = model;
|
2008-10-29 10:56:58 -07:00
|
|
|
|
|
|
|
// Calculate best z offset
|
|
|
|
for (int i = 0; i < psModel->meshes; i++)
|
|
|
|
{
|
|
|
|
MESH *psMesh = &psModel->mesh[i];
|
|
|
|
|
|
|
|
for (int j = 0; j < psMesh->vertices * 3; j++)
|
|
|
|
{
|
|
|
|
dimension = MAX(fabs(psMesh->vertexArray[j]), dimension);
|
|
|
|
}
|
|
|
|
}
|
2009-02-07 10:21:06 -08:00
|
|
|
setSceneRadius(dimension);
|
|
|
|
showEntireScene();
|
2008-10-29 10:56:58 -07:00
|
|
|
timer.start();
|
|
|
|
}
|
2009-02-07 10:21:06 -08:00
|
|
|
|
|
|
|
QString WZMOpenGLWidget::helpString() const
|
|
|
|
{
|
2010-04-29 14:48:31 -07:00
|
|
|
QString text("<h2>The Warzone Model Post-production Program</h2>");
|
2009-02-07 10:21:06 -08:00
|
|
|
text += "Welcome! This help needs be a lot more helpful!";
|
|
|
|
return text;
|
|
|
|
}
|