diff --git a/256.bmp b/256.bmp index b58f7a0..a01061f 100644 Binary files a/256.bmp and b/256.bmp differ diff --git a/Makefile b/Makefile index 2c8e978..82fc6bf 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ SOURCES = $(wildcard *.cpp) OBJECTS = $(SOURCES:.cpp=.o) DEPENDS = $(SOURCES:.cpp=.d) -LDFLAGS = $(shell pkg-config --libs gtkmm-2.4 gtkglextmm-1.2) -CPPFLAGS = $(shell pkg-config --cflags gtkmm-2.4 gtkglextmm-1.2) +LDFLAGS = $(shell pkg-config --libs gtkmm-2.4 gtkglextmm-1.2 sdl) -lglut -lsdl_mixer +CPPFLAGS = $(shell pkg-config --cflags gtkmm-2.4 gtkglextmm-1.2 sdl) CXXFLAGS = $(CPPFLAGS) -W -Wall -g -CXX = g++ +CXX = g++ -m32 MAIN = game488 all: $(MAIN) @@ -16,11 +16,11 @@ clean: $(MAIN): $(OBJECTS) @echo Creating $@... - @$(CXX) -arch i386 -o $@ $(OBJECTS) $(LDFLAGS) + @$(CXX) -o $@ $(OBJECTS) $(LDFLAGS) %.o: %.cpp @echo Compiling $<... - @$(CXX) -arch i386 -o $@ -c $(CXXFLAGS) $< + @$(CXX) -o $@ -c $(CXXFLAGS) $< %.d: %.cpp @echo Building $@... diff --git a/SoundManager.cpp b/SoundManager.cpp new file mode 100644 index 0000000..a3b4f8b --- /dev/null +++ b/SoundManager.cpp @@ -0,0 +1,143 @@ +/* *************************************************************** + * + * File : SoundManager.cpp + * + * Author : Tiberiu Popa + * J. Alexander Clarke + * Date : June 18th, 2002 + * + * Modified: + * + * Purpose: Implementation of the sound manager + * + * ****************************************************************/ +#pragma implementation +#include "SoundManager.hpp" +#include + + +SoundManager SM; + +SoundManager::SoundManager(){ + + nSounds = 0; + nMusics = 0; + + // initialize the sound library + SDL_Init(SDL_INIT_AUDIO /*| SDL_INIT_VIDEO */); + + /* sound setup */ + int audio_rate = 44100; + Uint16 audio_format = AUDIO_S16; + int audio_channels = 2; + int audio_buffers = 4096; + + // open the audio stream + if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) { + printf("Unable to open audio!\n"); + exit(1); + } +} + +SoundManager::~SoundManager(){ +} + + +/* *************** Manipulate Sound Chunks *******************/ + +int SoundManager::ResetSound(int snd){ + if(snd<0 || snd>=nSounds) return -1; + + Mix_HaltChannel(channel[snd]); + channel[snd] = -1; + + return 0; +} + +int SoundManager::LoadSound(char* file){ + + chunks[nSounds] = Mix_LoadWAV(file); + channel[nSounds] = -1; + + nSounds+=1; + return nSounds - 1; + +} + +int SoundManager::PlaySound(int snd){ + if(snd<0 && snd>=nSounds) return -1; + channel[snd] = Mix_PlayChannel(-1, chunks[snd], 0 /*-1*/); + return 0; +} + +int SoundManager::StopSound(int snd){ + if(snd<0 && snd>=nSounds) return -1; + ResetSound(snd); + return 0; +} + +int SoundManager::PauseSound(int snd){ + if(snd<0 && snd>=nSounds) return -1; + Mix_Pause(channel[snd]); + return 0; +} + +int SoundManager::ResumeSound(int snd){ + if(snd<0 && snd>=nSounds) return -1; + Mix_Resume(channel[snd]); + return 0; +} + + +/* *************** Manipulate Music *******************/ + +int SoundManager::ResetMusic(int snd){ + if(snd<0 || snd>=nMusics) return -1; + + Mix_HaltMusic(); + + return 0; +} + +int SoundManager::LoadMusic(char* file){ + + music[nMusics] = Mix_LoadMUS(file); + if(!music[nMusics]) + { + printf("Mix_LoadMUS(\"music.mp3\"): %s\n", Mix_GetError()); + // this might be a critical error... + } + nMusics+=1; + return nMusics - 1; + +} + +int SoundManager::PlayMusic(int snd){ + if(snd<0 && snd>=nMusics) return -1; + //Mix_PlayMusic(music[snd], 1 /*-1*/); + + if(Mix_PlayMusic(music[snd], -1)==-1) + { + printf("Mix_PlayMusic: %s\n", Mix_GetError()); + // well, there's no music, but most games don't break without music... + } + return 0; +} + +int SoundManager::StopMusic(int snd){ + if(snd<0 && snd>=nMusics) return -1; + ResetMusic(snd); + return 0; +} + +int SoundManager::PauseMusic(int snd){ + if(snd<0 && snd>=nMusics) return -1; + Mix_PauseMusic(); + return 0; +} + +int SoundManager::ResumeMusic(int snd){ + if(snd<0 && snd>=nMusics) return -1; + Mix_ResumeMusic(); + return 0; +} diff --git a/SoundManager.hpp b/SoundManager.hpp new file mode 100644 index 0000000..58eb522 --- /dev/null +++ b/SoundManager.hpp @@ -0,0 +1,76 @@ + /* *************************************************************** + * + * File : SoundManager.h + * + * Author : Tiberiu Popa + * J. Alexander Clarke + * Date : June 18th, 2002 + * + * Modified: + * + * Purpose: Header file for the sound manager + * + * ****************************************************************/ +#ifndef _SOUND_MANAGER__H +#define _SOUND_MANAGER__H +#pragma interface + +// include SDL header files +#include "SDL.h" +#include "SDL_mixer.h" + +// if you want more than 100 sounds, change the MAX_SOUND +#define MAX_SOUNDS 100 +#define MAX_MUSIC 100 + +// wrapper calss around SDL and SDL_mixer libraries +class SoundManager { + public: + SoundManager(); + ~SoundManager(); + + // manipulating sound clips + // sound clips can be played simultaneously + int LoadSound(char* file); + + // snd is the sound ID returned by LoadSound + int PlaySound(int snd); + int StopSound(int snd); + int PauseSound(int snd); + int ResumeSound(int snd); + + // manipulating music clips + // should have only one music clip + + int LoadMusic(char* file); + + int PlayMusic(int); + int StopMusic(int); + int PauseMusic(int); + int ResumeMusic(int); + + private: + + // internal data + + // sound clips + Mix_Chunk * chunks[MAX_SOUNDS]; + Mix_Music *music[MAX_MUSIC]; + + // sound channels for active sounds + int channel[MAX_SOUNDS]; + + // number of sound clips loaded + int nSounds; + int nMusics; + + int ResetSound(int snd); + int ResetMusic(int snd); +}; + + +// the global instance of the sound manager +extern SoundManager SM; + + +#endif // _SOUND_MANAGER__H diff --git a/appwindow.cpp b/appwindow.cpp index 1b8b8f8..efe63f9 100644 --- a/appwindow.cpp +++ b/appwindow.cpp @@ -28,6 +28,7 @@ AppWindow::AppWindow() m_menu_drawMode.items().push_back(MenuElem("_Wire-Frame", Gtk::AccelKey("w"), sigc::bind( draw_slot, Viewer::WIRE ) ) ); m_menu_drawMode.items().push_back(MenuElem("_Face", Gtk::AccelKey("f"), sigc::bind( draw_slot, Viewer::FACE ) ) ); m_menu_drawMode.items().push_back(MenuElem("_Texture 1", Gtk::AccelKey("t"), sigc::mem_fun(m_viewer, &Viewer::toggleTexture ) ) ); + m_menu_drawMode.items().push_back(MenuElem("_Bump Mapping 1", Gtk::AccelKey("b"), sigc::mem_fun(m_viewer, &Viewer::toggleBumpMapping ) ) ); m_menu_speed.items().push_back(RadioMenuElem(m_group_speed, "_Slow", sigc::bind( speed_slot, Viewer::SLOW ) ) ); m_menu_speed.items().push_back(RadioMenuElem(m_group_speed, "_Medium", sigc::bind( speed_slot, Viewer::MEDIUM ) ) ); diff --git a/floor.bmp b/floor.bmp new file mode 100644 index 0000000..f85756a Binary files /dev/null and b/floor.bmp differ diff --git a/lumines.ogg b/lumines.ogg new file mode 100644 index 0000000..f3d1c05 Binary files /dev/null and b/lumines.ogg differ diff --git a/move.ogg b/move.ogg new file mode 100644 index 0000000..272150d Binary files /dev/null and b/move.ogg differ diff --git a/normal.bmp b/normal.bmp new file mode 100644 index 0000000..7e21516 Binary files /dev/null and b/normal.bmp differ diff --git a/turn.ogg b/turn.ogg new file mode 100644 index 0000000..ad059b7 Binary files /dev/null and b/turn.ogg differ diff --git a/viewer.cpp b/viewer.cpp index a4cec8a..9f69306 100644 --- a/viewer.cpp +++ b/viewer.cpp @@ -3,13 +3,14 @@ #include #include #include +#include #include #include "appwindow.hpp" #define DEFAULT_GAME_SPEED 50 #define WIDTH 16 #define HEIGHT 10 - +int SND_ID_1 , SND_ID_2, SND_ID_3, MUS_ID_4; Viewer::Viewer() { @@ -20,7 +21,7 @@ Viewer::Viewer() rotationSpeed = 0; // Default draw mode is multicoloured - currentDrawMode = Viewer::MULTICOLOURED; + currentDrawMode = Viewer::FACE; // Default scale factor is 1 scaleFactor = 1; @@ -39,7 +40,8 @@ Viewer::Viewer() activeTextureId = 0; loadTexture = false; - + loadBumpMapping = false; + transluceny = false; // Game starts at a slow pace of 500ms gameSpeed = 500; @@ -48,6 +50,10 @@ Viewer::Viewer() gameOver = false; numTextures = 0; + + + + Glib::RefPtr glconfig; // Ask for an OpenGL Setup with @@ -111,14 +117,38 @@ void Viewer::on_realize() if (!gldrawable->gl_begin(get_gl_context())) return; - glGenTextures(5, texture); - LoadGLTextures("red.bmp"); - LoadGLTextures("blue.bmp"); - LoadGLTextures("lightRed.bmp"); - LoadGLTextures("lightBlue.bmp"); - LoadGLTextures("black.bmp"); + texture = new GLuint[7]; + LoadGLTextures("red.bmp", texture[0]); + LoadGLTextures("blue.bmp", texture[1]); + LoadGLTextures("lightRed.bmp", texture[2]); + LoadGLTextures("lightBlue.bmp", texture[3]); + LoadGLTextures("black.bmp", texture[4]); + LoadGLTextures("normal.bmp", bumpMap); + LoadGLTextures("floor.bmp", floorTexId); + std::cout << "normal\t" << bumpMap << "\n"; + + + // Load music + backgroundMusic = sm.LoadSound("lumines.ogg"); + moveSound = sm.LoadSound("move.ogg"); + turnSound = sm.LoadSound("turn.ogg"); +// sm.PlaySound(backgroundMusic); + + + GenNormalizationCubeMap(256, normalization_cube_map); // Just enable depth testing and set the background colour. - glEnable(GL_DEPTH_TEST); + // glEnable(GL_DEPTH_TEST); + + + + + glClearDepth (1.0f); + glDepthFunc (GL_LEQUAL); + glEnable (GL_DEPTH_TEST); + glShadeModel (GL_SMOOTH); + glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + + /* // Basic line anti aliasing // Blendfunc is set wrong though. Need to figure out what is good @@ -130,6 +160,17 @@ void Viewer::on_realize() */ glClearColor(0.7, 0.7, 1.0, 0.0); + + +/* backgroundSoundBuf = sm.LoadWav("OBS.wav"); + backgroundSoundIndex = sm.MakeSource(); + sm.QueueBuffer(backgroundSoundIndex, backgroundSoundBuf); + + backgroundSoundBuf = sm.LoadWav("cutman.wav"); + backgroundSoundIndex = sm.MakeSource(); + sm.QueueBuffer(backgroundSoundIndex, backgroundSoundBuf);*/ + + gldrawable->gl_end(); } @@ -141,9 +182,7 @@ bool Viewer::on_expose_event(GdkEventExpose* event) if (!gldrawable->gl_begin(get_gl_context())) return false; - - if (loadTexture) - glEnable(GL_TEXTURE_2D); + // Decide which buffer to write to if (doubleBuffer) glDrawBuffer(GL_BACK); @@ -179,7 +218,7 @@ bool Viewer::on_expose_event(GdkEventExpose* event) glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); // Define properties of light - float ambientLight0[] = { 0.3f, 0.3f, 0.3f, 1.0f }; +/* float ambientLight0[] = { 0.3f, 0.3f, 0.3f, 1.0f }; float diffuseLight0[] = { 0.8f, 0.8f, 0.8f, 1.0f }; float specularLight0[] = { 0.6f, 0.6f, 0.6f, 1.0f }; float position0[] = { 5.0f, 0.0f, 0.0f, 1.0f }; @@ -187,7 +226,7 @@ bool Viewer::on_expose_event(GdkEventExpose* event) glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight0); glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight0); glLightfv(GL_LIGHT0, GL_POSITION, position0); - + */ // Scale and rotate the scene if (scaleFactor != 1) @@ -229,7 +268,7 @@ bool Viewer::on_expose_event(GdkEventExpose* event) glTranslated(-5.0, -10.0, 10.0); // Create one light source -/* glEnable(GL_LIGHT0); + glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); // Define properties of light @@ -237,10 +276,13 @@ bool Viewer::on_expose_event(GdkEventExpose* event) float diffuseLight0[] = { 0.8f, 0.8f, 0.8f, 1.0f }; float specularLight0[] = { 0.6f, 0.6f, 0.6f, 1.0f }; float position0[] = { 20.0f, 5.0f, 2.0f, 1.0f }; + lightPos[0] = 20.0; + lightPos[1] = 5.0; + lightPos[2] = 2.0; glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight0); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight0); glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight0); - glLightfv(GL_LIGHT0, GL_POSITION, position0);*/ + glLightfv(GL_LIGHT0, GL_POSITION, position0); if (loadScreen) { @@ -271,7 +313,26 @@ bool Viewer::on_expose_event(GdkEventExpose* event) glVertex3d(game->getClearBarPos(), HEIGHT, 0); glEnd(); - + + // Draw Floor +/* glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, floorTexId); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );*/ + glColor3d(1, 1, 1); + glBegin(GL_QUADS); +// glTexCoord2f(0.0, 0.0); + glVertex3d(-100, -1, -100); +// glTexCoord2f(0.0, 10.0); + glVertex3d(-100, -1, 100); +// glTexCoord2f(10.0, 10.0); + glVertex3d(100, -1, 100); +// glTexCoord2f(10.0, 0.0); + glVertex3d(100, -1, -100); + glEnd(); + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + // Draw Border for (int y = -1;y< HEIGHT;y++) { @@ -315,11 +376,15 @@ bool Viewer::on_expose_event(GdkEventExpose* event) { for (int j = WIDTH - 1; j>=0;j--) // column { + + if (loadBumpMapping) + drawBumpCube(i, j, game->get(i,j), GL_QUADS); + else + drawCube (i, j, game->get(i, j), GL_QUADS ); + // Draw outline for cube if (game->get(i, j) != -1) drawCube(i, j, 7, GL_LINE_LOOP); - - drawCube (i, j, game->get(i, j), GL_QUADS ); } } } @@ -539,7 +604,7 @@ bool Viewer::on_motion_notify_event(GdkEventMotion* event) void Viewer::drawCube(int y, int x, int colourId, GLenum mode, bool multiColour) { if (mode == GL_LINE_LOOP) - glLineWidth (2); + glLineWidth (1.2); double r, g, b; r = 0; @@ -598,28 +663,45 @@ void Viewer::drawCube(int y, int x, int colourId, GLenum mode, bool multiColour) double zMax = 1; double zMin = 0; - + if (transluceny) + { + glColor4f(1.0f,1.0f,1.0f,0.5f); + glEnable (GL_BLEND); + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + glNormal3d(1, 0, 0); - if (loadTexture && colourId < 5) + if (loadTexture && colourId != 7) + { + glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture[colourId - 1]); + } + else if (loadTexture && colourId == 7) - glBindTexture(GL_TEXTURE_2D, texture[4]); + { + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, texture[4]); + } else + { glColor3d(r, g, b); + } - glBegin(mode); glTexCoord2f(0.0f, 0.0f); glVertex3d(innerXMin + x, innerYMin + y, zMax); + glTexCoord2f(1.0f, 0.0f); glVertex3d(innerXMax + x, innerYMin + y, zMax); + glTexCoord2f(1.0f, 1.0f); glVertex3d(innerXMax + x, innerYMax + y, zMax); + glTexCoord2f(0.0f, 1.0f); glVertex3d(innerXMin + x, innerYMax + y, zMax); glEnd(); - + // top face glNormal3d(0, 1, 0); @@ -635,7 +717,7 @@ void Viewer::drawCube(int y, int x, int colourId, GLenum mode, bool multiColour) glEnd(); // left face - glNormal3d(0, 0, 1); + glNormal3d(0, 0, -1); glBegin(mode); glTexCoord2f(0.0f, 0.0f); @@ -649,7 +731,7 @@ void Viewer::drawCube(int y, int x, int colourId, GLenum mode, bool multiColour) glEnd(); // bottom face - glNormal3d(0, 1, 0); + glNormal3d(0, -1, 0); glBegin(mode); glTexCoord2f(0.0f, 0.0f); @@ -677,7 +759,7 @@ void Viewer::drawCube(int y, int x, int colourId, GLenum mode, bool multiColour) glEnd(); // Back of front face - glNormal3d(1, 0, 0); + glNormal3d(-1, 0, 0); glBegin(mode); glTexCoord2f(0.0f, 0.0f); @@ -689,6 +771,304 @@ void Viewer::drawCube(int y, int x, int colourId, GLenum mode, bool multiColour) glTexCoord2f(0.0f, 1.0f); glVertex3d(innerXMin + x, innerYMax + y, zMin); glEnd(); + + glBindTexture(GL_TEXTURE_2D, 0); + if (transluceny) + glDisable(GL_BLEND); + +} + +void Viewer::drawBumpCube(int y, int x, int colourId, GLenum mode, bool multiColour) +{ + if (mode == GL_LINE_LOOP) + glLineWidth (1.2); + + double r, g, b; + r = 0; + g = 0; + b = 0; + switch (colourId) + { + case 0: // blue + r = 0.514; + g = 0.839; + b = 0.965; + break; + case 1: // purple + r = 0.553; + g = 0.6; + b = 0.796; + break; + case 2: // orange + r = 0.988; + g = 0.627; + b = 0.373; + break; + case 3: // green + r = 0.69; + g = 0.835; + b = 0.529; + break; + case 4: // red + r = 1.00; + g = 0.453; + b = 0.339; + break; + case 5: // pink + r = 0.949; + g = 0.388; + b = 0.639; + break; + case 6: // yellow + r = 1; + g = 0.792; + b = 0.204; + break; + case 7: // black + r = 0; + g = r; + b = g; + break; + default: + return; + } + + double innerXMin = 0; + double innerYMin = 0; + double innerXMax = 1; + double innerYMax = 1; + double zMax = 1; + double zMin = 0; + + +// glNormal3d(1, 0, 0); + glBlendFunc(GL_DST_COLOR, GL_ZERO); + glEnable(GL_BLEND); + // Set The First Texture Unit To Normalize Our Vector From The Surface To The Light. + // Set The Texture Environment Of The First Texture Unit To Replace It With The + // Sampled Value Of The Normalization Cube Map. + glActiveTexture(GL_TEXTURE0); + glEnable(GL_TEXTURE_CUBE_MAP); + glBindTexture(GL_TEXTURE_CUBE_MAP, normalization_cube_map); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE) ; + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE) ; + + // Set The Second Unit To The Bump Map. + // Set The Texture Environment Of The Second Texture Unit To Perform A Dot3 + // Operation With The Value Of The Previous Texture Unit (The Normalized + // Vector Form The Surface To The Light) And The Sampled Texture Value (The + // Normalized Normal Vector Of Our Bump Map). + glActiveTexture(GL_TEXTURE1); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, bumpMap); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); + glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGB) ; + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS) ; + glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE) ; + + // Set The Third Texture Unit To Our Tefsxture. + // Set The Texture Environment Of The Third Texture Unit To Modulate + // (Multiply) The Result Of Our Dot3 Operation With The Texture Value. + glActiveTexture(GL_TEXTURE2); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, texture[colourId - 1]); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + + //glBindTexture(GL_TEXTURE_2D, texture[colourId - 1]); + + + + double vertex_to_light_x, vertex_to_light_y, vertex_to_light_z; + vertex_to_light_z = lightPos[2] - zMax; + glBegin(mode); + Vector3D temp = lightPos - Point3D(innerXMin + x, innerYMin + y, zMax); + temp.normalize(); + std::cout << temp << "\n"; + glMultiTexCoord3d(GL_TEXTURE0, temp[0], temp[1], temp[2]); + glMultiTexCoord2d(GL_TEXTURE1, 0.0, 0.0); + glMultiTexCoord2d(GL_TEXTURE2, 0.0, 0.0); + glVertex3d(innerXMin + x, innerYMin + y, zMax); + + temp = lightPos - Point3D(innerXMax + x, innerYMin + y, zMax); + temp.normalize(); + glMultiTexCoord3d(GL_TEXTURE0, temp[0], temp[1], temp[2]); + glMultiTexCoord2d(GL_TEXTURE1, 1.0, 0.0); + glMultiTexCoord2d(GL_TEXTURE2, 1.0, 0.0); + glVertex3d(innerXMax + x, innerYMin + y, zMax); + + temp = lightPos - Point3D(innerXMax + x, innerYMax + y, zMax); + temp.normalize(); + glMultiTexCoord3d(GL_TEXTURE0, temp[0], temp[1], temp[2]); + glMultiTexCoord2d(GL_TEXTURE1, 1.0, 1.0); + glMultiTexCoord2d(GL_TEXTURE2, 1.0, 1.0); + glVertex3d(innerXMax + x, innerYMax + y, zMax); + + + temp = lightPos - Point3D(innerXMax + x, innerYMax + y, zMax); + temp.normalize(); + glMultiTexCoord3d(GL_TEXTURE0, temp[0], temp[1], temp[2]); + glMultiTexCoord2d(GL_TEXTURE1, 0.0, 1.0); + glMultiTexCoord2d(GL_TEXTURE2, 0.0, 1.0); + glVertex3d(innerXMin + x, innerYMax + y, zMax); + glEnd(); + + // top face + + glBegin(mode); + temp = lightPos - Point3D(innerXMin + x, innerYMax + y, zMin); + temp.normalize(); + vertex_to_light_x = lightPos[0] - (innerXMin + x); + vertex_to_light_y = lightPos[1] - (innerYMax + y); + glMultiTexCoord3d(GL_TEXTURE0, temp[0], temp[1], temp[2]); + glMultiTexCoord2d(GL_TEXTURE1, 0.0, 0.0); + glMultiTexCoord2d(GL_TEXTURE2, 0.0, 0.0); + glVertex3d(innerXMin + x, innerYMax + y, zMin); + + temp = lightPos - Point3D(innerXMax + x, innerYMax + y, zMin); + temp.normalize(); + glMultiTexCoord3d(GL_TEXTURE0, temp[0], temp[1], temp[2]); + glMultiTexCoord2d(GL_TEXTURE1, 1.0, 0.0); + glMultiTexCoord2d(GL_TEXTURE2, 1.0, 0.0); + glVertex3d(innerXMax + x, innerYMax + y, zMin); + + temp = lightPos - Point3D(innerXMax + x, innerYMax + y, zMax); + temp.normalize(); + glMultiTexCoord3d(GL_TEXTURE0, temp[0], temp[1], temp[2]); + glMultiTexCoord2d(GL_TEXTURE1, 1.0, 0.0); + glMultiTexCoord2d(GL_TEXTURE2, 1.0, 0.0); + glVertex3d(innerXMax + x, innerYMax + y, zMax); + + temp = lightPos - Point3D(innerXMin + x, innerYMax + y, zMax); + temp.normalize(); + glMultiTexCoord3d(GL_TEXTURE0, temp[0], temp[1], temp[2]); + glMultiTexCoord2d(GL_TEXTURE1, 1.0, 0.0); + glMultiTexCoord2d(GL_TEXTURE2, 1.0, 0.0); + glVertex3d(innerXMin + x, innerYMax + y, zMax); + glEnd(); + + // left face + + glBegin(mode); + temp = lightPos - Point3D(innerXMin + x, innerYMin + y, zMin); + temp.normalize(); + vertex_to_light_x = lightPos[0] - (innerXMin + x); + vertex_to_light_y = lightPos[1] - (innerYMin + y); + glMultiTexCoord3d(GL_TEXTURE0, temp[0], temp[1], temp[2]); + glMultiTexCoord2d(GL_TEXTURE1, 0.0, 0.0); + glMultiTexCoord2d(GL_TEXTURE2, 0.0, 0.0); + glVertex3d(innerXMin + x, innerYMin + y, zMin); + + temp = lightPos - Point3D(innerXMin + x, innerYMax + y, zMin); + temp.normalize(); + glMultiTexCoord3d(GL_TEXTURE0, temp[0], temp[1], temp[2]); + glMultiTexCoord2d(GL_TEXTURE1, 1.0, 0.0); + glMultiTexCoord2d(GL_TEXTURE2, 1.0, 0.0); + glVertex3d(innerXMin + x, innerYMax + y, zMin); + + temp = lightPos - Point3D(innerXMin + x, innerYMax + y, zMax); + temp.normalize(); + glMultiTexCoord3d(GL_TEXTURE0, temp[0], temp[1], temp[2]); + glMultiTexCoord2d(GL_TEXTURE1, 1.0, 0.0); + glMultiTexCoord2d(GL_TEXTURE2, 1.0, 0.0); + glVertex3d(innerXMin + x, innerYMax + y, zMax); + + temp = lightPos - Point3D(innerXMin + x, innerYMin + y, zMax); + temp.normalize(); + glMultiTexCoord3d(GL_TEXTURE0, temp[0], temp[1], temp[2]); + glMultiTexCoord2d(GL_TEXTURE1, 1.0, 0.0); + glMultiTexCoord2d(GL_TEXTURE2, 1.0, 0.0); + glVertex3d(innerXMin + x, innerYMin + y, zMax); + glEnd(); + + // bottom face + + + glBegin(mode); + temp = lightPos - Point3D(innerXMin + x, innerYMin + y, zMin); + temp.normalize(); + vertex_to_light_x = lightPos[0] - (innerXMin + x); + vertex_to_light_y = lightPos[1] - (innerYMin + y); + glMultiTexCoord3d(GL_TEXTURE0, temp[0], temp[1], temp[2]); + glMultiTexCoord2d(GL_TEXTURE1, 0.0, 0.0); + glMultiTexCoord2d(GL_TEXTURE2, 0.0, 0.0); + glVertex3d(innerXMin + x, innerYMin + y, zMin); + + temp = lightPos - Point3D(innerXMax + x, innerYMin + y, zMin); + temp.normalize(); + glMultiTexCoord3d(GL_TEXTURE0, temp[0], temp[1], temp[2]); + glMultiTexCoord2d(GL_TEXTURE1, 1.0, 0.0); + glMultiTexCoord2d(GL_TEXTURE2, 1.0, 0.0); + glVertex3d(innerXMax + x, innerYMin + y, zMin); + + temp = lightPos - Point3D(innerXMax + x, innerYMin + y, zMax); + temp.normalize(); + glMultiTexCoord3d(GL_TEXTURE0, temp[0], temp[1], temp[2]); + glMultiTexCoord2d(GL_TEXTURE1, 1.0, 0.0); + glMultiTexCoord2d(GL_TEXTURE2, 1.0, 0.0); + glVertex3d(innerXMax + x, innerYMin + y, zMax); + + temp = lightPos - Point3D(innerXMin + x, innerYMin + y, zMax); + temp.normalize(); + glMultiTexCoord3d(GL_TEXTURE0, temp[0], temp[1], temp[2]); + glMultiTexCoord2d(GL_TEXTURE1, 1.0, 0.0); + glMultiTexCoord2d(GL_TEXTURE2, 1.0, 0.0); + glVertex3d(innerXMin + x, innerYMin + y, zMax); + glEnd(); + + // right face + + + glBegin(mode); + temp = lightPos - Point3D(innerXMax + x, innerYMin + y, zMax); + temp.normalize(); + vertex_to_light_x = lightPos[0] - (innerXMax + x); + vertex_to_light_y = lightPos[1] - (innerYMin + y); + glMultiTexCoord3d(GL_TEXTURE0, temp[0], temp[1], temp[2]); + glMultiTexCoord2d(GL_TEXTURE1, 0.0, 0.0); + glMultiTexCoord2d(GL_TEXTURE2, 0.0, 0.0); + glVertex3d(innerXMax + x, innerYMin + y, zMin); + + temp = lightPos - Point3D(innerXMax + x, innerYMax + y, zMax); + temp.normalize(); + glMultiTexCoord3d(GL_TEXTURE0, temp[0], temp[1], temp[2]); + glMultiTexCoord2d(GL_TEXTURE1, 1.0, 0.0); + glMultiTexCoord2d(GL_TEXTURE2, 1.0, 0.0); + glVertex3d(innerXMax + x, innerYMax + y, zMin); + + glVertex3d(innerXMax + x, innerYMax + y, zMax); + + glVertex3d(innerXMax + x, innerYMin + y, zMax); + glEnd(); + + // Back of front face + + + glBegin(mode); + temp = lightPos - Point3D(innerXMin + x, innerYMin + y, zMax); + temp.normalize(); + vertex_to_light_x = lightPos[0] - (innerXMin + x); + vertex_to_light_y = lightPos[1] - (innerYMin + y); + glMultiTexCoord3d(GL_TEXTURE0, temp[0], temp[1], temp[2]); + glMultiTexCoord2d(GL_TEXTURE1, 0.0, 0.0); + glMultiTexCoord2d(GL_TEXTURE2, 0.0, 0.0); + glVertex3d(innerXMin + x, innerYMin + y, zMin); + + vertex_to_light_x = lightPos[0] - (innerXMax + x); + vertex_to_light_y = lightPos[1] - (innerYMin + y); + temp = lightPos - Point3D(innerXMax + x, innerYMin + y, zMax); + temp.normalize(); + glMultiTexCoord3d(GL_TEXTURE0, temp[0], temp[1], temp[2]); + glMultiTexCoord2d(GL_TEXTURE1, 1.0, 0.0); + glMultiTexCoord2d(GL_TEXTURE2, 1.0, 0.0); + glVertex3d(innerXMax + x, innerYMin + y, zMin); + + glVertex3d(innerXMax + x, innerYMax + y, zMin); + + glVertex3d(innerXMin + x, innerYMax + y, zMin); + glEnd(); +glDisable(GL_BLEND); } @@ -745,6 +1125,12 @@ bool Viewer::on_key_press_event( GdkEventKey *ev ) if (gameOver) return true; + if (ev->keyval == GDK_Left || ev->keyval == GDK_Right) + sm.PlaySound(moveSound); + else if (ev->keyval == GDK_Up || ev->keyval == GDK_Down) + sm.PlaySound(turnSound); + + if (ev->keyval == GDK_Left) game->moveLeft(); else if (ev->keyval == GDK_Right) @@ -1030,7 +1416,7 @@ int Viewer::ImageLoad(char *filename, Image *image) { } // Load Bitmaps And Convert To Textures -void Viewer::LoadGLTextures(char *filename) { +int Viewer::LoadGLTextures(char *filename, GLuint &texid) { // Load Texture Image *image1; @@ -1044,9 +1430,10 @@ void Viewer::LoadGLTextures(char *filename) { if (!ImageLoad(filename, image1)) { exit(1); } - + // Create Texture - glBindTexture(GL_TEXTURE_2D, texture[numTextures]); // 2d texture (x and y size) + glGenTextures(1, &texid); + glBindTexture(GL_TEXTURE_2D, texid); // 2d texture (x and y size) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // scale linearly when image bigger than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // scale linearly when image smalled than texture @@ -1056,12 +1443,162 @@ void Viewer::LoadGLTextures(char *filename) { glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->sizeX, image1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image1->data); numTextures++; + return (numTextures-1); } void Viewer::toggleTexture() { loadTexture = !loadTexture; - - if (!loadTexture) - glDisable(GL_TEXTURE_2D); -} \ No newline at end of file + +// if (!loadTexture) +// glDisable(GL_TEXTURE_2D); +} + +void Viewer::toggleBumpMapping() +{ +// loadBumpMapping = !loadBumpMapping; + transluceny = !transluceny; +} + +int Viewer::GenNormalizationCubeMap(unsigned int size, GLuint &texid) +{ + glGenTextures(1, &texid); + std::cerr << texid << "\n"; + glBindTexture(GL_TEXTURE_CUBE_MAP, texid); + + unsigned char* data = new unsigned char[size*size*3]; + + float offset = 0.5f; + float halfSize = size * 0.5f; + Vector3D temp; + unsigned int bytePtr = 0; + + for(unsigned int j=0; j #include #include "game.hpp" +#include "SoundManager.hpp" // The "main" OpenGL widget class Viewer : public Gtk::GL::DrawingArea { @@ -47,6 +48,7 @@ class Viewer : public Gtk::GL::DrawingArea { void resetView(); void newGame(); void toggleTexture(); + void toggleBumpMapping(); void makeRasterFont(); void printString(const char *s); @@ -54,10 +56,13 @@ class Viewer : public Gtk::GL::DrawingArea { void setScoreWidgets(Gtk::Label *score, Gtk::Label *linesCleared); bool moveClearBar(); void draw_start_screen(bool picking); - + + + + // Texture mapping stuff /* storage for one texture */ int numTextures; - GLuint texture[5]; + GLuint *texture; /* Image type - contains height, width, and data */ struct Image { @@ -68,8 +73,48 @@ class Viewer : public Gtk::GL::DrawingArea { typedef struct Image Image; int ImageLoad(char *filename, Image *image); - void LoadGLTextures(char *filename); - + int LoadGLTextures(char *filename, GLuint &texid); + + Point3D lightPos; + GLuint normalization_cube_map, bumpMap, floorTexId; + int GenNormalizationCubeMap(unsigned int size, GLuint &texid); + // Bump mapping stuff +/* bool SetUpARB_multitexture() + { + char * extensionString=(char *)glGetString(GL_EXTENSIONS); + char * extensionName="GL_ARB_multitexture"; + + char * endOfString; //store pointer to end of string + unsigned int distanceToSpace; //distance to next space + + endOfString=extensionString+strlen(extensionString); + + //loop through string + while(extensionString