diff --git a/black.bmp b/black.bmp new file mode 100644 index 0000000..f1fbc75 Binary files /dev/null and b/black.bmp differ diff --git a/blue.bmp b/blue.bmp new file mode 100644 index 0000000..bc6d5fc Binary files /dev/null and b/blue.bmp differ diff --git a/game.cpp b/game.cpp index 58511da..c71d428 100644 --- a/game.cpp +++ b/game.cpp @@ -15,6 +15,11 @@ #include #include "game.hpp" +#define XBLOCKCOL 1 +#define OBLOCKCOL 2 +#define XCLEARBLOCKCOL 3 +#define OCLEARBLOCKCOL 4 + int counter = 0; int lastClearedRow = -1; static const Piece PIECES[] = { @@ -101,9 +106,9 @@ int Piece::getBottomMargin() const int Piece::getColourIndex(int row, int col) const { if (desc_[ row*4 + col ] == 'x') - return 1; + return XBLOCKCOL; else if (desc_[ row*4 + col ] == 'o') - return 2; + return OBLOCKCOL; return 0; } @@ -278,7 +283,7 @@ int Game::collapse() for (int r = board_height_ + 2; r>= 0; --r) { - if (get(r, c) == 3 || get(r, c) == 4 ) + if (get(r, c) == XCLEARBLOCKCOL || get(r, c) == OCLEARBLOCKCOL ) { // Collapse get(r, c) = -1; diff --git a/lightBlue.bmp b/lightBlue.bmp new file mode 100644 index 0000000..d510ffb Binary files /dev/null and b/lightBlue.bmp differ diff --git a/lightRed.bmp b/lightRed.bmp new file mode 100644 index 0000000..7a37f9a Binary files /dev/null and b/lightRed.bmp differ diff --git a/red.bmp b/red.bmp new file mode 100644 index 0000000..9aa7353 Binary files /dev/null and b/red.bmp differ diff --git a/viewer.cpp b/viewer.cpp index b60791c..a4cec8a 100644 --- a/viewer.cpp +++ b/viewer.cpp @@ -47,7 +47,7 @@ Viewer::Viewer() doubleBuffer = false; gameOver = false; - + numTextures = 0; Glib::RefPtr glconfig; // Ask for an OpenGL Setup with @@ -111,8 +111,12 @@ void Viewer::on_realize() if (!gldrawable->gl_begin(get_gl_context())) return; - LoadGLTextures("256.bmp"); - + glGenTextures(5, texture); + LoadGLTextures("red.bmp"); + LoadGLTextures("blue.bmp"); + LoadGLTextures("lightRed.bmp"); + LoadGLTextures("lightBlue.bmp"); + LoadGLTextures("black.bmp"); // Just enable depth testing and set the background colour. glEnable(GL_DEPTH_TEST); @@ -222,7 +226,7 @@ bool Viewer::on_expose_event(GdkEventExpose* event) // 10 and height 24 (game = 20, stripe = 4). Let's translate // the game so that we can draw it starting at (0,0) but have // it appear centered in the window. - glTranslated(-5.0, -12.0, 0.0); + glTranslated(-5.0, -10.0, 10.0); // Create one light source /* glEnable(GL_LIGHT0); @@ -536,7 +540,7 @@ void Viewer::drawCube(int y, int x, int colourId, GLenum mode, bool multiColour) { if (mode == GL_LINE_LOOP) glLineWidth (2); - + double r, g, b; r = 0; g = 0; @@ -597,10 +601,13 @@ void Viewer::drawCube(int y, int x, int colourId, GLenum mode, bool multiColour) glNormal3d(1, 0, 0); - if (loadTexture) - glBindTexture(GL_TEXTURE_2D, texture[activeTextureId]); + if (loadTexture && colourId < 5) + glBindTexture(GL_TEXTURE_2D, texture[colourId - 1]); + else if (loadTexture && colourId == 7) + glBindTexture(GL_TEXTURE_2D, texture[4]); + else + glColor3d(r, g, b); - glColor3d(r, g, b); glBegin(mode); glTexCoord2f(0.0f, 0.0f); @@ -1039,15 +1046,16 @@ void Viewer::LoadGLTextures(char *filename) { } // Create Texture - glGenTextures(1, &texture[0]); - glBindTexture(GL_TEXTURE_2D, texture[0]); // 2d texture (x and y size) + glBindTexture(GL_TEXTURE_2D, texture[numTextures]); // 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 - + glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL ); // 2d texture, level of detail 0 (normal), 3 components (red, green, blue), x size from image, y size from image, // border 0 (normal), rgb color data, unsigned byte data, and finally the data itself. glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->sizeX, image1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image1->data); + + numTextures++; } void Viewer::toggleTexture() diff --git a/viewer.hpp b/viewer.hpp index ca44e62..696d173 100644 --- a/viewer.hpp +++ b/viewer.hpp @@ -56,7 +56,8 @@ class Viewer : public Gtk::GL::DrawingArea { void draw_start_screen(bool picking); /* storage for one texture */ - GLuint texture[1]; + int numTextures; + GLuint texture[5]; /* Image type - contains height, width, and data */ struct Image {