Skip to content

Commit

Permalink
Added new textures
Browse files Browse the repository at this point in the history
Texture loading will load multiple textures
Current texture array is set to 5 textures
Need to fix the black lines when drawing outlines. Currently it is using a texture which it shouldn't have to
  • Loading branch information
Krishna committed Mar 19, 2010
1 parent dfa524b commit b4706cc
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 15 deletions.
Binary file added black.bmp
Binary file not shown.
Binary file added blue.bmp
Binary file not shown.
11 changes: 8 additions & 3 deletions game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
#include <algorithm>

#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[] = {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
Binary file added lightBlue.bmp
Binary file not shown.
Binary file added lightRed.bmp
Binary file not shown.
Binary file added red.bmp
Binary file not shown.
30 changes: 19 additions & 11 deletions viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Viewer::Viewer()
doubleBuffer = false;

gameOver = false;

numTextures = 0;
Glib::RefPtr<Gdk::GL::Config> glconfig;

// Ask for an OpenGL Setup with
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion viewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b4706cc

Please sign in to comment.