scummvm/engines/myst3/nodecube.cpp

123 lines
3.6 KiB
C++
Raw Normal View History

2011-09-05 20:13:48 +02:00
/* Residual - A 3D game interpreter
*
* Residual is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the AUTHORS
* file distributed with this source distribution.
*
2012-01-05 10:07:48 +01:00
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
2011-09-05 20:13:48 +02:00
2012-01-05 10:07:48 +01:00
* This program is distributed in the hope that it will be useful,
2011-09-05 20:13:48 +02:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2012-01-05 10:07:48 +01:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
2011-09-05 20:13:48 +02:00
2012-01-05 10:07:48 +01:00
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2011-09-05 20:13:48 +02:00
*
*/
#include "engines/myst3/nodecube.h"
2012-01-05 13:38:31 +01:00
#include "engines/myst3/directorysubentry.h"
#include "engines/myst3/myst3.h"
2011-09-05 20:13:48 +02:00
#include "common/debug.h"
2011-09-05 20:13:48 +02:00
namespace Myst3 {
2012-01-05 13:38:31 +01:00
NodeCube::NodeCube(Myst3Engine *vm, uint16 id) :
Node(vm, id) {
2011-09-05 20:13:48 +02:00
for (int i = 0; i < 6; i++) {
2012-01-05 13:38:31 +01:00
const DirectorySubEntry *jpegDesc = _vm->getFileDescription(id, i + 1, DirectorySubEntry::kCubeFace);
if (!jpegDesc)
error("Face %d does not exist", id);
Common::MemoryReadStream *jpegStream = jpegDesc->getData();
2011-09-05 20:13:48 +02:00
if (jpegStream) {
Graphics::JPEG jpeg;
jpeg.read(jpegStream);
_faces[i] = new Face();
_faces[i]->setTextureFromJPEG(&jpeg);
_faces[i]->markTextureDirty();
2011-09-05 20:13:48 +02:00
delete jpegStream;
}
}
}
2011-09-05 20:13:48 +02:00
NodeCube::~NodeCube() {
}
2011-09-05 20:13:48 +02:00
void NodeCube::draw() {
// Size of the cube
float t = 1.0f;
// Used fragment of the textures
float s = 640 / (float)_cubeTextureSize;
// Update the OpenGL textures if needed
for (uint i = 0; i < 6; i++)
_faces[i]->uploadTexture();
glEnable(GL_TEXTURE_2D);
2011-09-05 20:13:48 +02:00
glDepthMask(GL_FALSE);
glBindTexture(GL_TEXTURE_2D, _faces[4]->_textureId);
2011-09-05 20:13:48 +02:00
glBegin(GL_TRIANGLE_STRIP); // X-
glTexCoord2f(0, s); glVertex3f(-t,-t, t);
glTexCoord2f(s, s); glVertex3f(-t,-t,-t);
glTexCoord2f(0, 0); glVertex3f(-t, t, t);
glTexCoord2f(s, 0); glVertex3f(-t, t,-t);
glEnd();
glBindTexture(GL_TEXTURE_2D, _faces[3]->_textureId);
2011-09-05 20:13:48 +02:00
glBegin(GL_TRIANGLE_STRIP); // X+
glTexCoord2f(0, s); glVertex3f( t,-t,-t);
glTexCoord2f(s, s); glVertex3f( t,-t, t);
glTexCoord2f(0, 0); glVertex3f( t, t,-t);
glTexCoord2f(s, 0); glVertex3f( t, t, t);
glEnd();
glBindTexture(GL_TEXTURE_2D, _faces[1]->_textureId);
2011-09-05 20:13:48 +02:00
glBegin(GL_TRIANGLE_STRIP); // Y-
glTexCoord2f(0, s); glVertex3f( t,-t,-t);
glTexCoord2f(s, s); glVertex3f(-t,-t,-t);
glTexCoord2f(0, 0); glVertex3f( t,-t, t);
glTexCoord2f(s, 0); glVertex3f(-t,-t, t);
glEnd();
glBindTexture(GL_TEXTURE_2D, _faces[5]->_textureId);
2011-09-05 20:13:48 +02:00
glBegin(GL_TRIANGLE_STRIP); // Y+
glTexCoord2f(0, s); glVertex3f( t, t, t);
glTexCoord2f(s, s); glVertex3f(-t, t, t);
glTexCoord2f(0, 0); glVertex3f( t, t,-t);
glTexCoord2f(s, 0); glVertex3f(-t, t,-t);
glEnd();
glBindTexture(GL_TEXTURE_2D, _faces[0]->_textureId);
2011-09-05 20:13:48 +02:00
glBegin(GL_TRIANGLE_STRIP); // Z-
glTexCoord2f(0, s); glVertex3f(-t,-t,-t);
glTexCoord2f(s, s); glVertex3f( t,-t,-t);
glTexCoord2f(0, 0); glVertex3f(-t, t,-t);
glTexCoord2f(s, 0); glVertex3f( t, t,-t);
glEnd();
glBindTexture(GL_TEXTURE_2D, _faces[2]->_textureId);
2011-09-05 20:13:48 +02:00
glBegin(GL_TRIANGLE_STRIP); // Z+
glTexCoord2f(0, s); glVertex3f( t,-t, t);
glTexCoord2f(s, s); glVertex3f(-t,-t, t);
glTexCoord2f(0, 0); glVertex3f( t, t, t);
glTexCoord2f(s, 0); glVertex3f(-t, t, t);
glEnd();
glDepthMask(GL_TRUE);
}
2011-09-05 20:13:48 +02:00
} /* namespace Myst3 */