diff --git a/Makefile b/Makefile index 82fc6bf..da94a9a 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ SOURCES = $(wildcard *.cpp) OBJECTS = $(SOURCES:.cpp=.o) DEPENDS = $(SOURCES:.cpp=.d) -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) +LDFLAGS = $(shell pkg-config --libs gtkmm-2.4 gtkglextmm-1.2 sdl libpng) -lglut -lsdl_mixer +CPPFLAGS = $(shell pkg-config --cflags gtkmm-2.4 gtkglextmm-1.2 sdl libpng) CXXFLAGS = $(CPPFLAGS) -W -Wall -g CXX = g++ -m32 MAIN = game488 diff --git a/algebra.hpp b/algebra.hpp index 9848adf..cf917ba 100644 --- a/algebra.hpp +++ b/algebra.hpp @@ -187,6 +187,11 @@ inline Point3D operator +(const Point3D& a, const Vector3D& b) return Point3D(a[0]+b[0], a[1]+b[1], a[2]+b[2]); } +inline bool operator ==(const Point3D& a, const Point3D& b) +{ + return (a[0] == b[0] && a[1] == b[1] && a[2] == b[2]); +} + inline Vector3D operator -(const Point3D& a, const Point3D& b) { return Vector3D(a[0]-b[0], a[1]-b[1], a[2]-b[2]); diff --git a/appwindow.cpp b/appwindow.cpp index efe63f9..9876952 100644 --- a/appwindow.cpp +++ b/appwindow.cpp @@ -22,10 +22,10 @@ AppWindow::AppWindow() // which shuts down the application. m_menu_app.items().push_back(MenuElem("_New Game", Gtk::AccelKey("n"), sigc::mem_fun(m_viewer, &Viewer::newGame ) ) ); m_menu_app.items().push_back(MenuElem("_Reset", Gtk::AccelKey("r"), sigc::mem_fun(m_viewer, &Viewer::resetView ) ) ); + m_menu_app.items().push_back(MenuElem("_Pause", Gtk::AccelKey("p"), sigc::mem_fun(m_viewer, &Viewer::pauseGame ) ) ); m_menu_app.items().push_back(MenuElem("_Quit", Gtk::AccelKey("q"), sigc::mem_fun(*this, &AppWindow::hide))); - 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 ) ) ); diff --git a/game.cpp b/game.cpp index c71d428..f59cd57 100644 --- a/game.cpp +++ b/game.cpp @@ -19,8 +19,7 @@ #define OBLOCKCOL 2 #define XCLEARBLOCKCOL 3 #define OCLEARBLOCKCOL 4 - -int counter = 0; +#define COUNTER_SPACE 16 int lastClearedRow = -1; static const Piece PIECES[] = { Piece( @@ -166,7 +165,7 @@ Game::Game(int width, int height) , score_(0) { int sz = board_width_ * (board_height_+4); - +counter=0; board_ = new int[ sz ]; std::fill(board_, board_ + sz, -1); generateNewPiece(); @@ -312,7 +311,6 @@ void Game::placePiece(const Piece& p, int x, int y) } } } -//dropShadowPiece(); } void Game::generateNewPiece() @@ -342,7 +340,7 @@ int Game::tick() markBlocksForClearing(); collapse(); moveClearBar(); - if (counter < 10) + if (counter < COUNTER_SPACE) { counter++; placePiece(piece_, px_, py_); @@ -385,10 +383,12 @@ int Game::tick() ++ny; placePiece(piece_, px_, ny);*/ dropPiece(0); + counter = COUNTER_SPACE; } else if(get(ny-2, px_+1) == -1 && get(ny-2, px_+2) != -1) { dropPiece(1); + counter = COUNTER_SPACE; } int rm = 0; /* int level = 1 + linesCleared_ / 10; @@ -418,6 +418,7 @@ int Game::tick() else { placePiece(piece_, px_, ny); + sy_ = py_; py_ = ny; return 0; } @@ -456,7 +457,8 @@ bool Game::moveLeft() removePiece(piece_, px_, py_); if(doesPieceFit(piece_, nx, py_)) { placePiece(piece_, nx, py_); - px_ = nx; + sx_ = px_; + px_ = nx; return true; } else { placePiece(piece_, px_, py_); @@ -471,7 +473,8 @@ bool Game::moveRight() removePiece(piece_, px_, py_); if(doesPieceFit(piece_, nx, py_)) { placePiece(piece_, nx, py_); - px_ = nx; + sx_ = px_; + px_ = nx; return true; } else { placePiece(piece_, px_, py_); @@ -503,6 +506,7 @@ bool Game::drop() } else { + sy_ = py_; py_ = ny; return true; } @@ -511,7 +515,6 @@ bool Game::drop() bool Game::rotateCW() { removePiece(piece_, px_, py_); - //removePiece(shadowPiece_, sx_, sy_); Piece npiece = piece_.rotateCW(); if(doesPieceFit(npiece, px_, py_)) @@ -531,7 +534,6 @@ bool Game::rotateCW() bool Game::rotateCCW() { removePiece(piece_, px_, py_); -// removePiece(shadowPiece_, sx_, sy_); Piece npiece = piece_.rotateCCW(); if(doesPieceFit(npiece, px_, py_)) { @@ -547,34 +549,7 @@ bool Game::rotateCCW() } } -void Game::dropShadowPiece() -{ - removePiece(shadowPiece_, sx_, sy_); - int ny = sy_; - sx_ = px_; - while(true) - { - --ny; - if(!doesPieceFit(shadowPiece_, sx_, ny)) - break; - } - - ++ny; - - for(int r = 0; r < 4; ++r) - { - for(int c = 0; c < 4; ++c) - { - if(shadowPiece_.isOn(r, c)) - get(ny-r, sx_+c) = shadowPiece_.getColourIndex(r, c); - } - } - - if(ny != sy_) - sy_ = ny; -} - -void Game::moveClearBar() +bool Game::moveClearBar() { if (clearBarPos > board_width_) { diff --git a/game.hpp b/game.hpp index e820fb0..428569b 100644 --- a/game.hpp +++ b/game.hpp @@ -35,7 +35,6 @@ class Piece { Piece rotateCCW() const; bool isOn(int row, int col) const; - int margins_[4]; void removeHalf(int side) { @@ -51,7 +50,7 @@ class Piece { desc_[ 2*4 + 2 ] = '.'; } } - + private: void getColumn(int col, char *buf) const; void getColumnRev(int col, char *buf) const; @@ -136,9 +135,12 @@ void dropShadowPiece(); return clearBarPos; } - void moveClearBar(); + bool moveClearBar(); void pullDown(int x, int y); - + int sx_, sy_; + int px_; + int py_; + int counter; private: bool doesPieceFit(const Piece& p, int x, int y) const; @@ -162,11 +164,10 @@ void dropShadowPiece(); Piece piece_; Piece shadowPiece_; - int px_, sx_; - int py_, sy_; - int* board_; + int* board_; + // Extra stuff int score_, linesCleared_; double clearBarPos; diff --git a/playButton.bmp b/playButton.bmp new file mode 100644 index 0000000..3ae09f9 Binary files /dev/null and b/playButton.bmp differ diff --git a/playButtonClicked.bmp b/playButtonClicked.bmp new file mode 100644 index 0000000..fea4073 Binary files /dev/null and b/playButtonClicked.bmp differ diff --git a/viewer.cpp b/viewer.cpp index 9f69306..d32f457 100644 --- a/viewer.cpp +++ b/viewer.cpp @@ -10,7 +10,7 @@ #define DEFAULT_GAME_SPEED 50 #define WIDTH 16 #define HEIGHT 10 -int SND_ID_1 , SND_ID_2, SND_ID_3, MUS_ID_4; +int SND_ID_1 = 0; Viewer::Viewer() { @@ -34,24 +34,26 @@ Viewer::Viewer() rotateAboutX = false; rotateAboutY = false; rotateAboutZ = false; - + clickedButton = false; // loadScreen = false; activeTextureId = 0; - loadTexture = false; + loadTexture = true; loadBumpMapping = false; transluceny = false; // Game starts at a slow pace of 500ms - gameSpeed = 500; + gameSpeed = DEFAULT_GAME_SPEED; // By default turn double buffer on - doubleBuffer = false; + doubleBuffer = true; gameOver = false; numTextures = 0; - - + lightPos[0] = 8.0f; + lightPos[1] = 15.0f; + lightPos[2] = 5.0f; + lightPos[3] = 1.0f; Glib::RefPtr glconfig; @@ -63,7 +65,8 @@ Viewer::Viewer() // - Multisample rendering to smooth out edges glconfig = Gdk::GL::Config::create( Gdk::GL::MODE_RGB | Gdk::GL::MODE_DEPTH | - Gdk::GL::MODE_DOUBLE ); + Gdk::GL::MODE_DOUBLE | + Gdk::GL::MODE_ACCUM); if (glconfig == 0) { // If we can't get this configuration, die abort(); @@ -125,6 +128,8 @@ void Viewer::on_realize() LoadGLTextures("black.bmp", texture[4]); LoadGLTextures("normal.bmp", bumpMap); LoadGLTextures("floor.bmp", floorTexId); + LoadGLTextures("playButton.bmp", playButtonTex); + LoadGLTextures("playButtonClicked.bmp", playButtonClickedTex); std::cout << "normal\t" << bumpMap << "\n"; @@ -161,15 +166,22 @@ 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);*/ - + square = glGenLists(1); + glNewList(square, GL_COMPILE); + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); + glVertex3d(0, 0, 1); + + glTexCoord2f(1.0f, 0.0f); + glVertex3d(1, 0, 1); + + glTexCoord2f(1.0f, 1.0f); + glVertex3d(1, 1, 1); + + glTexCoord2f(0.0f, 1.0f); + glVertex3d(0, 1, 1); + glEnd(); + glEndList(); gldrawable->gl_end(); } @@ -191,7 +203,7 @@ bool Viewer::on_expose_event(GdkEventExpose* event) // Clear the screen - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // Modify the current projection matrix so that we move the // camera away from the origin. We'll draw the game at the @@ -211,12 +223,8 @@ bool Viewer::on_expose_event(GdkEventExpose* event) // Initialize lighting settings glShadeModel(GL_SMOOTH); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); - glEnable(GL_LIGHTING); // Create one light source - glEnable(GL_LIGHT0); - 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 diffuseLight0[] = { 0.8f, 0.8f, 0.8f, 1.0f }; @@ -227,6 +235,7 @@ bool Viewer::on_expose_event(GdkEventExpose* event) glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight0); glLightfv(GL_LIGHT0, GL_POSITION, position0); */ + // Scale and rotate the scene if (scaleFactor != 1) @@ -239,7 +248,7 @@ bool Viewer::on_expose_event(GdkEventExpose* event) glRotated(rotationAngleY, 0, 1, 0); if (rotationAngleZ != 0) - glRotated(rotationAngleZ, 0, 0, 1); + glTranslatef(rotationAngleZ, 0, 0); // Increment rotation angles for next render if ((mouseB1Down && !shiftIsDown) || rotateAboutX) @@ -268,6 +277,7 @@ bool Viewer::on_expose_event(GdkEventExpose* event) glTranslated(-5.0, -10.0, 10.0); // Create one light source + glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); @@ -275,18 +285,15 @@ bool Viewer::on_expose_event(GdkEventExpose* event) 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[] = { 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, lightPos); if (loadScreen) { - draw_start_screen(false); + drawStartScreen(false, playButtonTex); // We pushed a matrix onto the PROJECTION stack earlier, we // need to pop it. @@ -298,120 +305,431 @@ bool Viewer::on_expose_event(GdkEventExpose* event) // just drew. This should only be done if double buffering is enabled. if (doubleBuffer) gldrawable->swap_buffers(); - else - glFlush(); +/* else + glFlush(); */ gldrawable->gl_end(); return true; } + +/* // Draw game + drawFloor(); + drawScene(0); +// + + + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + glDepthMask(GL_FALSE); + glEnable(GL_CULL_FACE); + glEnable(GL_STENCIL_TEST); + glEnable(GL_POLYGON_OFFSET_FILL); + glPolygonOffset(0.0f, 100.0f); + + glCullFace(GL_FRONT); + glStencilFunc(GL_ALWAYS, 0x0, 0xff); + glStencilOp(GL_KEEP, GL_INCR, GL_KEEP); + drawShadowVolumes(); + + glCullFace(GL_BACK); + glStencilFunc(GL_ALWAYS, 0x0, 0xff); + glStencilOp(GL_KEEP, GL_DECR, GL_KEEP); + drawShadowVolumes(); + + glDisable(GL_POLYGON_OFFSET_FILL); + glDisable(GL_CULL_FACE); + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glDepthMask(GL_TRUE); + + glStencilFunc(GL_NOTEQUAL, 0x0, 0xff); + glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); +/* glPushMatrix(); + glLoadIdentity(); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(0, 1, 1, 0, 0, 1); + glDisable(GL_DEPTH_TEST); + + glColor4f(0.0f, 0.0f, 0.0f, 0.5f); + glBegin(GL_QUADS); + glVertex2i(0, 0); + glVertex2i(0, 1); + glVertex2i(1, 1); + glVertex2i(1, 0); + glEnd(); + + glEnable(GL_DEPTH_TEST); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + glDisable(GL_STENCIL_TEST); - glBegin(GL_LINE_LOOP); - glVertex3d(game->getClearBarPos(), 0, 0); - glVertex3d(game->getClearBarPos(), 0, 1); - glVertex3d(game->getClearBarPos(), HEIGHT, 1); - glVertex3d(game->getClearBarPos(), HEIGHT, 0); - glEnd(); + drawFloor();*/ + +/* glColor4f(0.7f, 0.4f, 0.0f, 1.0f); // Set Color To An Orange + glDisable(GL_LIGHTING); // Disable Lighting + glDepthMask(GL_FALSE); // Disable Depth Mask + glTranslatef(lightPos[0], lightPos[1], lightPos[2]); // Translate To Light's Position + + GLUquadricObj *quadratic; + quadratic=gluNewQuadric(); // Notice We're Still In Local Coordinate System + gluSphere(quadratic, 0.2f, 16, 8); // Draw A Little Yellow Sphere (Represents Light) +// glEnable(GL_LIGHTING); // Enable Lighting + glDepthMask(GL_TRUE); // Enable Depth Mask*/ + + + GLUquadricObj *quadratic; + quadratic=gluNewQuadric(); // Create A Pointer To The Quadric Object ( NEW ) + gluQuadricNormals(quadratic, GLU_SMOOTH); // Create Smooth Normals ( NEW ) + gluQuadricTexture(quadratic, GL_TRUE); + glPushMatrix(); + glTranslatef(lightPos[0], lightPos[1], lightPos[2]); + gluSphere(quadratic,1.3f,32,32); + glPopMatrix(); - // 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++) + +// drawShadowVolumes(); +// silhouette.clear(); + +// drawRoom(); + + //drawScene(0); + drawBar(); + + if (game->counter == 15) { - drawCube(y, -1, 7, GL_LINE_LOOP); + drawScene(0); + drawFallingBox(); + + glAccum(GL_RETURN, 1.f); + } + else + drawScene(0); + + +/* for (int i = 16;i>=1;i--) + { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + // drawBar(i); + drawScene(i); + glAccum(GL_ACCUM, 1.f/16); + } + glAccum(GL_RETURN, 1.f); */ + - drawCube(y, WIDTH, 7, GL_LINE_LOOP); + // We pushed a matrix onto the PROJECTION stack earlier, we + // need to pop it. + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + + // Swap the contents of the front and back buffers so we see what we + // just drew. This should only be done if double buffering is enabled. + if (doubleBuffer) + gldrawable->swap_buffers(); +/* else + glFlush(); */ + + gldrawable->gl_end(); + + return true; +} + +void Viewer::drawRoom() // Draw The Room (Box) +{ + glColor3d(0, 1, 0); + glBegin(GL_QUADS); // Begin Drawing Quads + // Floor + glNormal3f(0.0f, 1.0f, 0.0f); // Normal Pointing Up + glVertex3f(-4.0f,0.0f,-20.0f); // Back Left + glVertex3f(-4.0f,0.0f, 20.0f); // Front Left + glVertex3f( 20.0f,0.0f, 20.0f); // Front Right + glVertex3f( 20.0f,0.0f,-20.0f); // Back Right + // Ceiling + glNormal3f(0.0f,-1.0f, 0.0f); // Normal Point Down + glVertex3f(-4.0f, 20.0f, 20.0f); // Front Left + glVertex3f(-4.0f, 20.0f,-20.0f); // Back Left + glVertex3f( 20.0f, 20.0f,-20.0f); // Back Right + glVertex3f( 20.0f, 20.0f, 20.0f); // Front Right + // Front Wall + glNormal3f(0.0f, 0.0f, 1.0f); // Normal Pointing Away From Viewer + glVertex3f(-4.0f, 20.0f,-20.0f); // Top Left + glVertex3f(-4.0f, 0.0f,-20.0f); // Bottom Left + glVertex3f( 20.0f, 0.0f,-20.0f); // Bottom Right + glVertex3f( 20.0f, 20.0f,-20.0f); // Top Right +/* // Back Wall + glNormal3f(0.0f, 0.0f,-1.0f); // Normal Pointing Towards Viewer + glVertex3f( 20.0f, 15.0f, 20.0f); // Top Right + glVertex3f( 20.0f,-15.0f, 20.0f); // Bottom Right + glVertex3f(-20.0f,-15.0f, 20.0f); // Bottom Left + glVertex3f(-20.0f, 15.0f, 20.0f); // Top Left*/ + // Left Wall + glNormal3f(1.0f, 0.0f, 0.0f); // Normal Pointing Right + glVertex3f(-4.0f, 20.0f, 20.0f); // Top Front + glVertex3f(-4.0f, 0.0f, 20.0f); // Bottom Front + glVertex3f(-4.0f, 0.0f,-20.0f); // Bottom Back + glVertex3f(-4.0f, 20.0f,-20.0f); // Top Back + // Right Wall + glNormal3f(-1.0f, 0.0f, 0.0f); // Normal Pointing Left + glVertex3f( 20.0f, 20.0f,-20.0f); // Top Back + glVertex3f( 20.0f, 0.0f,-20.0f); // Bottom Back + glVertex3f( 20.0f, 0.0f, 20.0f); // Bottom Front + glVertex3f( 20.0f, 20.0f, 20.0f); // Top Front + glEnd(); // Done Drawing Quads +} +void Viewer::drawShadowVolumes() +{ + float frac = 1.f/16; + for (int i = HEIGHT+3;i>=0;i--) // row + { + for (int j = WIDTH - 1; j>=0;j--) // column + { + + bool condition = game->get(i, j) != -1 && i > 1 &&( game->get(i - 2, j) == -1 && i == game->py_ - 1 && j == game->px_ + 1 + || game->get(i - 2, j) == -1 && i == game->py_ - 1 && j == game->px_ + 2); + condition = condition || (i > 0 && game->get(i - 1, j) == -1 && i == game->py_ - 2 && j == game->px_ + 1 || game->get(i - 1, j) == -1 && i == game->py_ - 2 && j == game->px_ + 2); + if (condition) + { + drawShadowCube (i - game->counter * frac, j, GL_LINE_LOOP ); + + } + else if (game->get(i, j) != -1) + { + drawShadowCube (i, j, GL_QUADS ); + + } + + + // Draw outline for cube + } } - for (int x = 0;x < WIDTH; x++) + + + Vector3D temp, temp2; + Point3D temp3; + Point3D lightPoint(lightPos[0], lightPos[1], lightPos[2]); + glColor4d(0, 0, 0, 0.3); + glBegin(GL_QUADS); + for (int i = 0;i 0) + { + silhouette.push_back(std::pair(a, b )); + silhouette.push_back(std::pair(c, b )); + silhouette.push_back(std::pair(c, d )); + silhouette.push_back(std::pair(d, a)); + } + +/* if (Vector3D(0, 1, 0).dot(lightVec) > 0) + { + silhouette.push_back(std::pair(c, d) ); + silhouette.push_back(std::pair(c, g) ); + silhouette.push_back(std::pair(g, h) ); + silhouette.push_back(std::pair(h, d) ); + } + + - // Draw current state of Lumines - if (currentDrawMode == Viewer::WIRE) + if (Vector3D(1, 0, 0).dot(lightVec) > 0) { - for (int i = HEIGHT + 3;i>=0;i--) // row + silhouette.push_back(std::pair(b, f) ); + silhouette.push_back(std::pair(c, g) ); + silhouette.push_back(std::pair(b, c) ); + silhouette.push_back(std::pair(g, f) ); + } + */ + if (Vector3D(-1, 0, 0).dot(lightVec) > 0) + { + silhouette.push_back(std::pair(a, e) ); + silhouette.push_back(std::pair(d, h) ); + silhouette.push_back(std::pair(a, d) ); + silhouette.push_back(std::pair(h, e) ); + std::cerr << "left face " << Vector3D(-1, 0, 0).dot(lightVec) << "\n"; + } + + if (Vector3D(0, -1, 0).dot(lightVec) > 0) + { + silhouette.push_back(std::pair(b, a) ); + silhouette.push_back(std::pair(b, f) ); + silhouette.push_back(std::pair(f, e) ); + silhouette.push_back(std::pair(e, a) ); + std::cerr << "bottom face " << Vector3D(0, -1, 0).dot(lightVec) << "\n"; + } + + if (Vector3D(0, 0, -1).dot(lightVec) > 0) + { + silhouette.push_back(std::pair(e, f) ); + silhouette.push_back(std::pair(g, f) ); + silhouette.push_back(std::pair(g, h) ); + silhouette.push_back(std::pair(h, e) ); + std::cerr << "back face " << Vector3D(0, 0, -1).dot(lightVec) << "\n"; + } + for (int i = 0;i=0;j--) // column + if (silhouette[i].first == silhouette[j].first && silhouette[i].second == silhouette[j].second) { - drawCube (i, j, game->get(i, j), GL_LINE_LOOP ); + // std::cerr << silhouette[i].first << "\t" << silhouette[j].first << "\t" << silhouette[i].second << "\t" << silhouette[j].second << std::endl; + silhouette.erase (silhouette.begin() + i); + silhouette.erase (silhouette.begin() + j-1); + break; + } + else if (silhouette[i].first == silhouette[j].second && silhouette[i].second == silhouette[j].first) + { + // std::cerr << silhouette[i].first << "\t" << silhouette[j].second << "\t" << silhouette[i].second << "\t" << silhouette[j].first << std::endl; + silhouette.erase (silhouette.begin() + i); + silhouette.erase (silhouette.begin() + j-1); + break; } } } - else if (currentDrawMode == Viewer::MULTICOLOURED) + +} + +void Viewer::drawBar() +{ + // Clear bar + glBegin(GL_LINE_LOOP); + glVertex3d(game->getClearBarPos(), 0, 0); + glVertex3d(game->getClearBarPos(), 0, 1); + glVertex3d(game->getClearBarPos(), HEIGHT, 1); + glVertex3d(game->getClearBarPos(), HEIGHT, 0); + glEnd(); +} + +void Viewer::drawFallingBox() +{ + + int iter = 16; + float iterFrac = 1.f/iter; + for (int i = 0;i=0;i--) // row + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + drawCube (game->py_ - 1 + i * iterFrac, game->px_ + 1, game->get(game->py_ - 1, game->px_ + 1), GL_QUADS ); + drawCube (game->py_ - 1 + i * iterFrac, game->px_ + 2, game->get(game->py_ - 1, game->px_ + 2), GL_QUADS ); + drawCube (game->py_ - 2 + i * iterFrac, game->px_ + 1, game->get(game->py_ - 1, game->px_ + 1), GL_QUADS ); + drawCube (game->py_ - 2 + i * iterFrac, game->px_ + 2, game->get(game->py_ - 1, game->px_ + 2), GL_QUADS ); + + drawCube (game->py_ - 1 + i * iterFrac, game->px_ + 1, 7, GL_LINE_LOOP ); + drawCube (game->py_ - 1 + i * iterFrac, game->px_ + 2, 7, GL_LINE_LOOP ); + drawCube (game->py_ - 2 + i * iterFrac, game->px_ + 1, 7, GL_LINE_LOOP ); + drawCube (game->py_ - 2 + i * iterFrac, game->px_ + 2, 7, GL_LINE_LOOP ); + glAccum(GL_ACCUM, iterFrac); + } + +} + +void Viewer::drawFloor() +{ + // 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); + glNormal3f(0.0, 1.0, 0.0); + // 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); +} +void Viewer::drawScene(int itesdfr) +{ + + // Draw Border + for (int y = -1;y< HEIGHT;y++) { - for (int j = WIDTH - 1; j>=0;j--) // column - { - // 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, true ); - } + drawCube(y, -1, 7, GL_LINE_LOOP); + + drawCube(y, WIDTH, 7, GL_LINE_LOOP); } - } - else if (currentDrawMode == Viewer::FACE) - { + for (int x = 0;x < WIDTH; x++) + { + drawCube (-1, x, 7, GL_LINE_LOOP); + } + + + + + float frac = 1.f/16; for (int i = HEIGHT+3;i>=0;i--) // row { for (int j = WIDTH - 1; j>=0;j--) // column { - - if (loadBumpMapping) - drawBumpCube(i, j, game->get(i,j), GL_QUADS); - else + bool condition = i > 1 &&( game->get(i - 2, j) == -1 && i == game->py_ - 1 && j == game->px_ + 1 + || game->get(i - 2, j) == -1 && i == game->py_ - 1 && j == game->px_ + 2); + condition = condition || (i > 0 && game->get(i - 1, j) == -1 && i == game->py_ - 2 && j == game->px_ + 1 || game->get(i - 1, j) == -1 && i == game->py_ - 2 && j == game->px_ + 2); + /*if (condition) + { + drawCube (i - game->counter * frac, j, game->get(i, j), GL_QUADS ); + } + else*/ if(game->get(i, j) != -1) drawCube (i, j, game->get(i, j), GL_QUADS ); - + // Draw outline for cube - if (game->get(i, j) != -1) + /*if (game->get(i, j) != -1 && condition) + { + + drawCube(i - game->counter * frac, j, 7, GL_LINE_LOOP); + } + else */if (game->get(i, j) != -1) drawCube(i, j, 7, GL_LINE_LOOP); } } - } - - if (gameOver) - { - // Some game over animation - } - - // We pushed a matrix onto the PROJECTION stack earlier, we - // need to pop it. - - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - - // Swap the contents of the front and back buffers so we see what we - // just drew. This should only be done if double buffering is enabled. - if (doubleBuffer) - gldrawable->swap_buffers(); - else - glFlush(); - - gldrawable->gl_end(); - - return true; + + if (gameOver) + { + // Some game over animation + } } - bool Viewer::on_configure_event(GdkEventConfigure* event) { Glib::RefPtr gldrawable = get_gl_drawable(); @@ -461,7 +779,7 @@ bool Viewer::on_button_press_event(GdkEventButton* event) glTranslated(-5.0, -12.0, 0.0); glInitNames(); glPushName(0); - draw_start_screen(true); + drawStartScreen(true, playButtonTex); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); @@ -476,7 +794,10 @@ bool Viewer::on_button_press_event(GdkEventButton* event) if (hits > 0) { - loadScreen = false; + clickedButton = true; + playButtonTex = playButtonClickedTex; + drawStartScreen(false, playButtonClickedTex); + invalidate(); } } // Stop rotating if a mosue button was clicked and the shift button is not down @@ -508,7 +829,11 @@ bool Viewer::on_button_release_event(GdkEventButton* event) { startScalePos[0] = 0; startScalePos[1] = 0; - + if (clickedButton) + { + loadScreen = false; + } + if (!shiftIsDown) { // Set the rotation speed based on how far the cursor has moved since the mouse down event @@ -565,8 +890,6 @@ bool Viewer::on_motion_notify_event(GdkEventMotion* event) if (scaleFactor < 0.5) scaleFactor = 0.5; - else if (scaleFactor > 2) - scaleFactor = 2; startScalePos[0] = event->x; startScalePos[1] = event->y; @@ -601,7 +924,7 @@ bool Viewer::on_motion_notify_event(GdkEventMotion* event) return true; } -void Viewer::drawCube(int y, int x, int colourId, GLenum mode, bool multiColour) +void Viewer::drawCube(float y, float x, int colourId, GLenum mode, bool multiColour) { if (mode == GL_LINE_LOOP) glLineWidth (1.2); @@ -687,7 +1010,9 @@ void Viewer::drawCube(int y, int x, int colourId, GLenum mode, bool multiColour) { glColor3d(r, g, b); } + + glBegin(mode); glTexCoord2f(0.0f, 0.0f); glVertex3d(innerXMin + x, innerYMin + y, zMax); @@ -778,300 +1103,6 @@ void Viewer::drawCube(int y, int x, int colourId, GLenum mode, bool multiColour) } -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); -} - - void Viewer::startScale() { shiftIsDown = true; @@ -1125,10 +1156,10 @@ bool Viewer::on_key_press_event( GdkEventKey *ev ) if (gameOver) return true; - if (ev->keyval == GDK_Left || ev->keyval == GDK_Right) +/* 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); + sm.PlaySound(turnSound);*/ if (ev->keyval == GDK_Left) @@ -1182,6 +1213,7 @@ bool Viewer::gameTick() { gameOver = true; tickTimer.disconnect(); + std::cerr << "Boo!"; } invalidate(); @@ -1241,93 +1273,25 @@ bool Viewer::moveClearBar() return true; } -void Viewer::draw_start_screen(bool pick) +void Viewer::drawStartScreen(bool pick, GLuint texId) { if (pick) glPushName(1); - -/* for (int i = HEIGHT + 3;i>=0;i--) // row - { - for (int j = WIDTH - 1; j>=0;j--) // column - */ -// glEnable(GL_POLYGON_SMOOTH); - drawCube (3, 0, 7, GL_LINE_LOOP ); - drawCube (4, 0, 7, GL_LINE_LOOP ); - drawCube (5, 0, 7, GL_LINE_LOOP ); - drawCube (6, 0, 7, GL_LINE_LOOP ); - drawCube (7, 0, 7, GL_LINE_LOOP ); - drawCube (7, 1, 7, GL_LINE_LOOP ); - drawCube (7, 2, 7, GL_LINE_LOOP ); - drawCube (5, 1, 7, GL_LINE_LOOP ); - drawCube (5, 2, 7, GL_LINE_LOOP ); - drawCube (6, 2, 7, GL_LINE_LOOP ); - - drawCube (3, 0, 3, GL_QUADS ); - drawCube (4, 0, 3, GL_QUADS ); - drawCube (5, 0, 3, GL_QUADS ); - drawCube (6, 0, 3, GL_QUADS ); - drawCube (7, 0, 3, GL_QUADS ); - drawCube (7, 1, 3, GL_QUADS ); - drawCube (7, 2, 3, GL_QUADS ); - drawCube (5, 1, 3, GL_QUADS ); - drawCube (5, 2, 3, GL_QUADS ); - drawCube (6, 2, 3, GL_QUADS ); - - - drawCube(3, 4, 7, GL_LINE_LOOP); - drawCube(4, 4, 7, GL_LINE_LOOP); - drawCube(5, 4, 7, GL_LINE_LOOP); - drawCube(6, 4, 7, GL_LINE_LOOP); - drawCube(7, 4, 7, GL_LINE_LOOP); - drawCube(3, 5, 7, GL_LINE_LOOP); - drawCube(3, 6, 7, GL_LINE_LOOP); - - drawCube(3, 4, 4, GL_QUADS); - drawCube(4, 4, 4, GL_QUADS); - drawCube(5, 4, 4, GL_QUADS); - drawCube(6, 4, 4, GL_QUADS); - drawCube(7, 4, 4, GL_QUADS); - drawCube(3, 5, 4, GL_QUADS); - drawCube(3, 6, 4, GL_QUADS); - - drawCube(3, 8, 7, GL_LINE_LOOP); - drawCube(4, 8, 7, GL_LINE_LOOP); - drawCube(5, 8, 7, GL_LINE_LOOP); - drawCube(6, 8, 7, GL_LINE_LOOP); - drawCube(7, 9, 7, GL_LINE_LOOP); - drawCube(4, 9, 7, GL_LINE_LOOP); - drawCube(3, 10, 7, GL_LINE_LOOP); - drawCube(4, 10, 7, GL_LINE_LOOP); - drawCube(5, 10, 7, GL_LINE_LOOP); - drawCube(6, 10, 7, GL_LINE_LOOP); - - drawCube(3, 8, 5, GL_QUADS); - drawCube(4, 8, 5, GL_QUADS); - drawCube(5, 8, 5, GL_QUADS); - drawCube(6, 8, 5, GL_QUADS); - drawCube(7, 9, 5, GL_QUADS); - drawCube(4, 9, 5, GL_QUADS); - drawCube(3, 10, 5,GL_QUADS); - drawCube(4, 10, 5,GL_QUADS); - drawCube(5, 10, 5,GL_QUADS); - drawCube(6, 10, 5,GL_QUADS); - - drawCube(3, 13, 7, GL_LINE_LOOP); - drawCube(4, 13, 7, GL_LINE_LOOP); - drawCube(5, 13, 7, GL_LINE_LOOP); - drawCube(6, 12, 7, GL_LINE_LOOP); - drawCube(7, 12, 7, GL_LINE_LOOP); - drawCube(6, 14, 7, GL_LINE_LOOP); - drawCube(7, 14, 7, GL_LINE_LOOP); - - drawCube(3, 13, 6, GL_QUADS); - drawCube(4, 13, 6, GL_QUADS); - drawCube(5, 13, 6, GL_QUADS); - drawCube(6, 12, 6, GL_QUADS); - drawCube(7, 12, 6, GL_QUADS); - drawCube(6, 14, 6, GL_QUADS); - drawCube(7, 14, 6, GL_QUADS); -// glDisable(GL_MULTISAMPLE_ARB); + + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, texId); + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); + glVertex3d(5, 3, 1); + glTexCoord2f(1.0f, 0.0f); + glVertex3d(13, 3, 1); + glTexCoord2f(1.0f, 1.0f); + glVertex3d(13, 7, 1); + glTexCoord2f(0.0f, 1.0f); + glVertex3d(5, 7, 1); + glEnd(); + glBindTexture(GL_TEXTURE_2D, 0); + if (pick) glPopName(); @@ -1460,6 +1424,11 @@ void Viewer::toggleBumpMapping() transluceny = !transluceny; } +void Viewer::pauseGame() +{ + tickTimer.disconnect(); +} + int Viewer::GenNormalizationCubeMap(unsigned int size, GLuint &texid) { glGenTextures(1, &texid); diff --git a/viewer.hpp b/viewer.hpp index b7a067a..c325912 100644 --- a/viewer.hpp +++ b/viewer.hpp @@ -6,7 +6,8 @@ #include #include "game.hpp" #include "SoundManager.hpp" - +#include +#include // The "main" OpenGL widget class Viewer : public Gtk::GL::DrawingArea { public: @@ -55,8 +56,7 @@ class Viewer : public Gtk::GL::DrawingArea { void setScoreWidgets(Gtk::Label *score, Gtk::Label *linesCleared); bool moveClearBar(); - void draw_start_screen(bool picking); - + void pauseGame(); // Texture mapping stuff @@ -75,8 +75,6 @@ class Viewer : public Gtk::GL::DrawingArea { int ImageLoad(char *filename, Image *image); 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() @@ -139,8 +137,16 @@ class Viewer : public Gtk::GL::DrawingArea { private: - - void drawCube(int y, int x, int colourId, GLenum mode, bool multiColour = false); + void drawScene(int iter); + void drawBar(); + void drawFallingBox(); + void drawFloor(); + void drawShadowVolumes(); + void drawShadowCube(float y, float x, GLenum mode); + void drawRoom(); + void drawStartScreen(bool picking, GLuint texId); + + void drawCube(float y, float x, int colourId, GLenum mode, bool multiColour = false); void drawBumpCube(int y, int x, int colourId, GLenum mode, bool multiColour = false); DrawMode currentDrawMode; @@ -210,8 +216,16 @@ class Viewer : public Gtk::GL::DrawingArea { int backgroundMusic; int turnSound; int moveSound; -// int backgroundSoundIndex; -// int backgroundSoundBuf; + GLuint square; + float shadowProj[16]; + float lightPos[4]; + + float planeNormal[4]; + bool drawingShadow; + GLuint normalization_cube_map, bumpMap, floorTexId, playButtonTex, playButtonClickedTex; + bool clickedButton; + std::vector< std::pair > silhouette; + }; #endif