Permalink
Browse files

Merged pull request #190 from hydrosolar/master.

Improved Code Comments
  • Loading branch information...
2 parents 1e91568 + 59f0f95 commit 78c5d57774eea22f9d0e96aba329bbad7908430a @dave256 committed Apr 28, 2011
Showing with 228 additions and 59 deletions.
  1. +9 −2 Background.cpp
  2. +1 −1 Background.h
  3. +9 −2 Coin.cpp
  4. +85 −10 EnemyFireball.cpp
  5. +4 −0 EnemyFireball.h
  6. +8 −2 FireFlower.cpp
  7. +9 −0 Goomba.cpp
  8. +11 −4 Mario.cpp
  9. +9 −4 MarioFireball.cpp
  10. +7 −7 Mushroom.cpp
  11. +5 −0 Pipe.cpp
  12. +9 −1 Plant.cpp
  13. +43 −12 SceneWindow.cpp
  14. +8 −2 Shell.cpp
  15. +11 −12 Star.cpp
View
@@ -10,12 +10,13 @@
void Background::draw()
{
-
+ //Set proper blending for alpha
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, texture_);
+ //Draw QUAD
glColor4f(0.7f,0.9f,1.0f,1.0f);
glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0); glVertex2d(left(),bottom());
@@ -24,13 +25,15 @@ void Background::draw()
glTexCoord2d(0.0,1.0); glVertex2d(left(),top());
glEnd();
+ //Disable unwanted gl modes
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
}
void Background::sprite()
{
+ //Array of background element types
std::string types[11] = {"bush0", "bush1", "bush2", "cloud0", "cloud1", "cloud2", "mountain0", "mountain1", "trunk0", "trunk1", "trunk2"};
// Mac environment variable for home directory
@@ -51,7 +54,7 @@ void Background::sprite()
-
+ //Read in the texture file
FILE *fp = fopen(homeDir.c_str(), "r");
unsigned char *texture = new unsigned char[4 * width_ * height_ * 4];
if (fread(texture, sizeof(unsigned char), 4 * width_ * height_ * 4, fp)
@@ -61,9 +64,11 @@ void Background::sprite()
fclose(fp);
+ //Bind Texture to a GLuint
glGenTextures(1, &texture_);
glBindTexture(GL_TEXTURE_2D, texture_);
+ //Set paramaters for how the texture is displayed
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_NEAREST );
@@ -73,6 +78,8 @@ void Background::sprite()
GL_CLAMP );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
GL_CLAMP );
+
+ //Build Mipmap
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, (2*width_), (2*height_) , GL_RGBA,
GL_UNSIGNED_BYTE, texture);
delete [] texture;
View
@@ -24,7 +24,7 @@ class Background:public Drawable{
public:
Background(char kind)
{
- //Bush
+ //Determine background element type
if (kind == 'u') {
kind_ = 0;
width_ = 32;
View
@@ -10,12 +10,13 @@
void Coin::draw()
{
-
+ //Set proper blending for alpha
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, texture_);
+ //Draw QUAD
glColor4f(0.7f,0.9f,1.0f,1.0f);
glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0); glVertex2d(left(),bottom());
@@ -24,6 +25,7 @@ void Coin::draw()
glTexCoord2d(0.0,1.0); glVertex2d(left(),top());
glEnd();
+ //Disable unwanted gl modes
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
@@ -46,7 +48,8 @@ void Coin::sprite()
homeDir += "/CS330/sprites/coin0.tex";
-
+ //Read in the texture file
+
FILE *fp = fopen(homeDir.c_str(), "r");
unsigned char *texture = new unsigned char[4 * 32 * 32];
if (fread(texture, sizeof(unsigned char), 4 * 32 * 32, fp)
@@ -56,9 +59,11 @@ void Coin::sprite()
fclose(fp);
+ //Bind Texture to a GLuint
glGenTextures(1, &texture_);
glBindTexture(GL_TEXTURE_2D, texture_);
+ //Set paramaters for how the texture is displayed
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_NEAREST );
@@ -68,6 +73,8 @@ void Coin::sprite()
GL_CLAMP );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
GL_CLAMP );
+
+ //Build Mipmap
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 32, 32, GL_RGBA,
GL_UNSIGNED_BYTE, texture);
delete [] texture;
View
@@ -10,6 +10,8 @@
//---------------------------------------------------------
#include "EnemyFireball.h"
+#include <string>
+#include <sstream>
//---------------------------------------------------------
@@ -33,26 +35,99 @@ EnemyFireball::~EnemyFireball()
void EnemyFireball::draw()
{
- glColor3ub(255, 48, 48);
- glBegin(GL_POLYGON);
- glVertex2d(left(),bottom());
- glVertex2d(right(),bottom());
- glVertex2d(right(),top());
- glVertex2d(left(),top());
- glEnd();
-
-
+ //Determine Texture Position
+ if (texturePos < 3) {
+ texturePos++;
+ }
+ else{
+ texturePos = 0;
+ }
+
+ //Set proper blending for alpha
+ glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+ glEnable( GL_TEXTURE_2D );
+ glBindTexture( GL_TEXTURE_2D, texture_[texturePos]);
+ //Draw QUAD
+ glColor4f(0.7f,0.9f,1.0f,1.0f);
+ glBegin( GL_QUADS );
+ glTexCoord2d(0.0,0.0); glVertex2d(left(),bottom());
+ glTexCoord2d(1.0,0.0); glVertex2d(right(),bottom());
+ glTexCoord2d(1.0,1.0); glVertex2d(right(),top());
+ glTexCoord2d(0.0,1.0); glVertex2d(left(),top());
+ glEnd();
+ //Disable unwanted gl modes
+ glDisable(GL_BLEND);
+ glDisable(GL_TEXTURE_2D);
+
+}
+
+//---------------------------------------------------------
+
+void EnemyFireball::sprite()
+{
+ texturePos = 0;
+ // Mac environment variable for home directory
+ char *cHomeDir = NULL;
+ cHomeDir = getenv("HOME");
+ // I think Windows uses HOMEPATH
+ if (!cHomeDir) {
+ cHomeDir = getenv("HOMEPATH");
+ }
+ std::string homeDir = cHomeDir;
+ std::string iName;
+ homeDir += "/CS330/sprites/fireball";
+ std::string pos;
+ for (int i = 0; i<4; ++i) {
+ std::stringstream out;
+ //Generates Filename
+ iName = homeDir;
+ out<<i;
+ pos = out.str();
+ iName += pos;
+ iName += ".tex";
+
+ //Read in the texture file
+ FILE *fp = fopen(iName.c_str(), "r");
+ unsigned char *texture = new unsigned char[4 * 16 * 16];
+ if (fread(texture, sizeof(unsigned char), 4 * 16 * 16, fp)
+ != 4* 16 *16) {
+ fprintf(stderr, "error reading %s", iName.c_str());
+ }
+ fclose(fp);
+
+ //Bind Texture to a GLuint
+ glGenTextures(1, &texture_[i]);
+ glBindTexture(GL_TEXTURE_2D, texture_[i]);
+
+ //Set parameters for how the texture is displayed
+ glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
+ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+ GL_LINEAR_MIPMAP_NEAREST );
+ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
+ GL_LINEAR );
+ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
+ GL_CLAMP );
+ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
+ GL_CLAMP );
+
+ //Build Mipmap
+ gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 16, 16, GL_RGBA,
+ GL_UNSIGNED_BYTE, texture);
+ delete [] texture;
+
+ }
}
-//---------------------------------------------------------
+
View
@@ -17,6 +17,10 @@
//---------------------------------------------------------
class EnemyFireball: public Movable {
+private:
+ GLuint texture_[4];
+ int texturePos;
+ void sprite();
public:
// openGL draw method
View
@@ -10,12 +10,13 @@
void FireFlower::draw()
{
-
+ //Set proper blending for alpha
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, texture_);
+ //Draw QUAD
glColor4f(0.7f,0.9f,1.0f,1.0f);
glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0); glVertex2d(left(),bottom());
@@ -24,6 +25,7 @@ void FireFlower::draw()
glTexCoord2d(0.0,1.0); glVertex2d(left(),top());
glEnd();
+ //Disable unwanted gl modes
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
@@ -45,7 +47,7 @@ void FireFlower::sprite()
homeDir += "/CS330/sprites/flower0.tex";
-
+ //Read in the texture file
FILE *fp = fopen(homeDir.c_str(), "r");
unsigned char *texture = new unsigned char[4 * 32 * 32];
if (fread(texture, sizeof(unsigned char), 4 * 32 * 32, fp)
@@ -54,9 +56,11 @@ void FireFlower::sprite()
}
fclose(fp);
+ //Bind Texture to a GLuint
glGenTextures(1, &texture_);
glBindTexture(GL_TEXTURE_2D, texture_);
+ //Set paramaters for how the texture is displayed
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_NEAREST );
@@ -66,6 +70,8 @@ void FireFlower::sprite()
GL_CLAMP );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
GL_CLAMP );
+
+ //Build Mipmap
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 32, 32, GL_RGBA,
GL_UNSIGNED_BYTE, texture);
delete [] texture;
View
@@ -51,11 +51,13 @@ void Goomba::draw()
texturePos = 0;
}
+ //Set proper blending for alpha
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, texture_[texturePos]);
+ //Draw QUAD
glColor4f(0.7f,0.9f,1.0f,1.0f);
glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0); glVertex2d(left(),bottom());
@@ -64,6 +66,7 @@ void Goomba::draw()
glTexCoord2d(0.0,1.0); glVertex2d(left(),top());
glEnd();
+ //Disable unwanted gl modes
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
@@ -100,6 +103,8 @@ void Goomba::sprite()
iName += pos;
iName += ".tex";
+
+ //Read in the texture file
FILE *fp = fopen(iName.c_str(), "r");
unsigned char *texture = new unsigned char[4 * 32 * 32];
if (fread(texture, sizeof(unsigned char), 4 * 32 * 32, fp)
@@ -108,9 +113,11 @@ void Goomba::sprite()
}
fclose(fp);
+ //Bind Texture to a GLuint
glGenTextures(1, &texture_[i]);
glBindTexture(GL_TEXTURE_2D, texture_[i]);
+ //Set parameters for how the texture is displayed
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_NEAREST );
@@ -120,6 +127,8 @@ void Goomba::sprite()
GL_CLAMP );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
GL_CLAMP );
+
+ //Build Mipmap
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 32, 32, GL_RGBA,
GL_UNSIGNED_BYTE, texture);
delete [] texture;
Oops, something went wrong.

0 comments on commit 78c5d57

Please sign in to comment.