diff --git a/engines/myst3/module.mk b/engines/myst3/module.mk index 5fb02bb03c8..46b45144df4 100755 --- a/engines/myst3/module.mk +++ b/engines/myst3/module.mk @@ -5,7 +5,8 @@ MODULE_OBJS := \ detection.o \ directoryentry.o \ directorysubentry.o \ - myst3.o + myst3.o \ + room.o # This module can be built as a plugin ifeq ($(ENABLE_MYST3), DYNAMIC_PLUGIN) diff --git a/engines/myst3/myst3.cpp b/engines/myst3/myst3.cpp index 4d5e80a1054..1904fb2262d 100644 --- a/engines/myst3/myst3.cpp +++ b/engines/myst3/myst3.cpp @@ -32,6 +32,7 @@ #include "engines/myst3/myst3.h" #include "engines/myst3/archive.h" +#include "engines/myst3/room.h" #include "graphics/jpeg.h" #include "graphics/conversion.h" @@ -45,16 +46,13 @@ namespace Myst3 { -GLuint cubeTextures[6]; +Room room; + float CAMERA_Pitch = 0.0f; float CAMERA_Yaw = 0.0f; -static const int textureSize = 1024; void sbInit() { - // Chargement des six textures - Graphics::Surface *texture_image[6]; - for (int i = 0; i < 6; i++) { char fileName[250]; sprintf(fileName, "1-%d.jpg", i + 1); @@ -63,115 +61,26 @@ void sbInit() { if (!jpegFile.open(fileName)) { error("Unable to open cube face %d", i); } - + Graphics::JPEG jpeg; jpeg.read(&jpegFile); - - byte *y = (byte *)jpeg.getComponent(1)->getBasePtr(0, 0); - byte *u = (byte *)jpeg.getComponent(2)->getBasePtr(0, 0); - byte *v = (byte *)jpeg.getComponent(3)->getBasePtr(0, 0); - - texture_image[i] = new Graphics::Surface(); - texture_image[i]->create(jpeg.getComponent(1)->w, jpeg.getComponent(1)->h, 3); - - byte *ptr = (byte *)texture_image[i]->getBasePtr(0, 0); - for (int j = 0; j < texture_image[i]->w * texture_image[i]->h; j++) { - byte r, g, b; - Graphics::YUV2RGB(*y++, *u++, *v++, r, g, b); - *ptr++ = r; - *ptr++ = g; - *ptr++ = b; - } - + + room.setFaceTextureJPEG(i, &jpeg); + jpegFile.close(); - } - - for (int i = 0; i < 6; i++) - { - // Génération d'une texture - glGenTextures(1, &cubeTextures[i]); - - // Configuration de la texture courante - glBindTexture(GL_TEXTURE_2D, cubeTextures[i]); - - if (texture_image[i]) - { - glTexImage2D(GL_TEXTURE_2D, 0, 3, textureSize, textureSize, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture_image[i]->w, texture_image[i]->h, GL_RGB, GL_UNSIGNED_BYTE, texture_image[i]->pixels); - //glTexImage2D(GL_TEXTURE_2D, 0, 3, texture_image[i]->w, texture_image[i]->h, 0, GL_RGB, GL_UNSIGNED_BYTE, texture_image[i]->pixels); - - delete texture_image[i]; - } - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); } } void DrawSkyBox(float camera_yaw, float camera_pitch) { - // Taille du cube - float t = 1.0f; - - // Portion de texture utilisée - float s = 640 / (float)textureSize; - // Réglage de l'orientation glPushMatrix(); glLoadIdentity(); glRotatef( camera_pitch, 1.0f, 0.0f, 0.0f ); glRotatef( camera_yaw, 0.0f, 1.0f, 0.0f ); - - - glBindTexture(GL_TEXTURE_2D, cubeTextures[4]); - 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, cubeTextures[3]); - 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, cubeTextures[1]); - 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, cubeTextures[5]); - 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, cubeTextures[0]); - 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, cubeTextures[2]); - 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(); + room.draw(); // Réinitialisation de la matrice ModelView glPopMatrix(); diff --git a/engines/myst3/room.cpp b/engines/myst3/room.cpp new file mode 100644 index 00000000000..31168a6bf94 --- /dev/null +++ b/engines/myst3/room.cpp @@ -0,0 +1,120 @@ +/* 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 + * + * $URL$ + * $Id$ + * + */ + +#include "engines/myst3/room.h" + +namespace Myst3 { + +void Room::setFaceTextureJPEG(int face, Graphics::JPEG *jpeg) { + Graphics::Surface *texture = new Graphics::Surface(); + texture->create(jpeg->getComponent(1)->w, jpeg->getComponent(1)->h, 3); + + byte *y = (byte *)jpeg->getComponent(1)->getBasePtr(0, 0); + byte *u = (byte *)jpeg->getComponent(2)->getBasePtr(0, 0); + byte *v = (byte *)jpeg->getComponent(3)->getBasePtr(0, 0); + + byte *ptr = (byte *)texture->getBasePtr(0, 0); + for (int i = 0; i < texture->w * texture->h; i++) { + byte r, g, b; + Graphics::YUV2RGB(*y++, *u++, *v++, r, g, b); + *ptr++ = r; + *ptr++ = g; + *ptr++ = b; + } + + setFaceTextureRGB(face, texture); + + delete texture; +} + +void Room::setFaceTextureRGB(int face, Graphics::Surface *texture) { + glGenTextures(1, &_cubeTextures[face]); + + glBindTexture(GL_TEXTURE_2D, _cubeTextures[face]); + + glTexImage2D(GL_TEXTURE_2D, 0, 3, _cubeTextureSize, _cubeTextureSize, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture->w, texture->h, GL_RGB, GL_UNSIGNED_BYTE, texture->pixels); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); +} + +void Room::draw() { + // Taille du cube + float t = 1.0f; + + // Portion de texture utilisée + float s = 640 / (float)_cubeTextureSize; + + glBindTexture(GL_TEXTURE_2D, _cubeTextures[4]); + 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, _cubeTextures[3]); + 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, _cubeTextures[1]); + 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, _cubeTextures[5]); + 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, _cubeTextures[0]); + 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, _cubeTextures[2]); + 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(); +} + +} // end of namespace Myst3 diff --git a/engines/myst3/room.h b/engines/myst3/room.h new file mode 100644 index 00000000000..3f9818cb92b --- /dev/null +++ b/engines/myst3/room.h @@ -0,0 +1,55 @@ +/* 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 + * + * $URL$ + * $Id$ + * + */ + +#ifndef MYST3_ROOM_H +#define MYST3_ROOM_H + +#ifdef SDL_BACKEND +#include +#else +#include +#include +#endif + +#include "graphics/surface.h" +#include "graphics/jpeg.h" +#include "graphics/conversion.h" + +namespace Myst3 { + +class Room { + private: + static const int _cubeTextureSize = 1024; + GLuint _cubeTextures[6]; + + public: + void setFaceTextureRGB(int face, Graphics::Surface *texture); + void setFaceTextureJPEG(int face, Graphics::JPEG *jpeg); + void draw(); +}; + +} // end of namespace Myst3 + +#endif