scummvm/engines/myst3/nodecube.cpp
2011-12-29 11:38:49 +01:00

112 lines
3.4 KiB
C++

/* 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.
*
* This library 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 2.1 of the License, or (at your option) any later version.
* This library 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
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
*/
#include "engines/myst3/nodecube.h"
#include "common/debug.h"
namespace Myst3 {
NodeCube::NodeCube(Myst3Engine *vm, Archive *archive, uint16 id) :
Node(vm, archive, id) {
for (int i = 0; i < 6; i++) {
const DirectorySubEntry *jpegDesc = archive->getDescription(id, i + 1, DirectorySubEntry::kCubeFace);
Common::MemoryReadStream *jpegStream = archive->getData(jpegDesc);
if (jpegStream) {
Graphics::JPEG jpeg;
jpeg.read(jpegStream);
_faces[i].createTexture();
_faces[i].setTextureFromJPEG(&jpeg);
_faces[i].uploadTexture();
delete jpegStream;
}
}
}
NodeCube::~NodeCube() {
}
void NodeCube::draw() {
// Size of the cube
float t = 1.0f;
// Used fragment of the textures
float s = 640 / (float)_cubeTextureSize;
glDepthMask(GL_FALSE);
glBindTexture(GL_TEXTURE_2D, _faces[4]._textureId);
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);
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);
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);
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);
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);
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);
}
} /* namespace Myst3 */