SDL_SetColorKey(temp, SDL_SRCCOLORKEY, SDL_MapRGB(temp->format, transparency[0], transparency[1], transparency[2]));
/** Loads image into animation */
- SDL_Surface* surface = SDL_DisplayFormat(temp);
+ SDL_Surface* surface = SDL_DisplayFormatAlpha(temp);
+ SDL_FreeSurface(temp);
mFrames[count].width=surface->w;
mFrames[count].height=surface->h;
- SDL_FreeSurface(temp);
// Check that the image\92s width is a power of 2
if ( (surface->w & (surface->w - 1)) != 0 ) {
GLenum texture_format=NULL;
//contains an alpha channel
- if(nofcolors==4)
- {
- if(surface->format->Rmask==0x000000ff)
- texture_format=GL_RGBA;
- else
- texture_format=GL_BGRA;
- }
- else if(nofcolors==3) //no alpha channel
- {
- if(surface->format->Rmask==0x000000ff)
- texture_format=GL_RGB;
- else
- texture_format=GL_BGR;
- }
+ if(surface->format->Rmask==0x000000ff)
+ texture_format=GL_RGBA;
else
+ texture_format=GL_BGRA;
+ if(!(nofcolors==4 || nofcolors==3))
{
cout<<"warning: the image is not truecolor...this will break "<<endl;
}
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
// when texture area is small, bilinear filter the closest mipmap
- glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
- GL_LINEAR_MIPMAP_NEAREST );
+ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// when texture area is large, bilinear filter the original
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
/** load sprites */
Sprite* vikings1 = new Sprite(screen, "viking1", l->getAnimation("viking.anim"));
- vikings1->setPosition(10,30);
+ vikings1->setPosition(0,0);
vikings1->setSpeed(1);
Sprite* vikings2 = new Sprite(screen, "viking2", l->getAnimation("viking.anim"));
mLastUpdate = SDL_GetTicks();
}
}
- SDL_Rect dest;
if(mVisible == true){
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glColor4f(1, 1, 1, mTransparency);
glLoadIdentity();
+ glTranslated(mPos.x,mPos.y,0);//move to position
+ glTranslated(frame->animationPeg.x,frame->animationPeg.y,0);//move back to where it was
+ glRotatef(mAngle,0.0f,0.0f,1.0f);//rotate shape
+ glTranslated(-frame->animationPeg.x,-frame->animationPeg.y,0);//place animation peg on origin
glBindTexture(GL_TEXTURE_2D, frame->image);
glBegin( GL_QUADS );
// Top-left vertex (corner)
- glTexCoord2i( 0, 0 );
- glVertex3f( mPos.x, mPos.y, 0 );
+ glTexCoord2f( 0, 0 );
+ glVertex3d( 0, 0, 0 );
// Bottom-left vertex (corner)
- glTexCoord2i( 1, 0 );
- glVertex3f( mPos.x+frame->width, mPos.y, 0 );
+ glTexCoord2f( 1, 0 );
+ glVertex3d( frame->width, 0, 0 );
// Bottom-right vertex (corner)
- glTexCoord2i( 1, 1 );
- glVertex3f( mPos.x+frame->width, mPos.y+frame->height, 0 );
+ glTexCoord2f( 1, 1 );
+ glVertex3d( frame->width, frame->height, 0 );
// Top-right vertex (corner)
- glTexCoord2i( 0, 1 );
- glVertex3f( mPos.x, mPos.y+frame->height, 0 );
+ glTexCoord2f( 0, 1 );
+ glVertex3d( 0, frame->height, 0 );
glEnd();
+ glDisable(GL_BLEND);
glLoadIdentity();
}
{
public:
WorldObject(int z = 0) :
- ZOrder(z),
- mVisible(true)
+ ZOrder(z),
+ mVisible(true),
+ mTransparency(1),
+ mAngle(0)
{}
virtual void draw() = 0;/**< Draws the Object. */
void drawCollisions(vector<Collision*>& vec, const Point2D& pos);/**< Draws Collision data for the Object */
void xset(int x) {mPos.x = x;}/**< Sets the Sprite's x Coordinate. */
void yset(int y) {mPos.y = y;}/**< Sets the Sprite's y coordinate. */
void setPosition(int x, int y) {mPos.x = x; mPos.y = y;}/**< Sets the Sprite's x an y coordinate. */
+ void setTransparency(float f){ mTransparency = f>1?1:f<0?0:f;}/**< Sets the Sprite's transparency. \param f The sprite's transparancy [0,1] other values will be force set */
+ float getTransparency(){return mTransparency;}/**< Gets the Sprite's transparency. */
+ void setAngle(float a){ mAngle = a; while(a>360)a-=360;}/**< Sets the Sprite's angle in degrees. \param a Angle in degrees */
+ float getAngle(){return mAngle;}/**< Gets the Sprite's angle. */
protected:
Point2D mPos;/**< The current (x,y) position */
bool mVisible;/**< Determine if Object should be visible */
+ float mTransparency;/**< Transparency! */
+ float mAngle;/**< Angle of rotation */
int ZOrder;/**< Stacking order. Determines what draws on top. \todo implement. */
};
#endif
static void DoNothing(){}
///Texture name
typedef unsigned int Texture;
+///deg/rad
+const float deg2rad = (float)(3.14159/180);
SDL_Surface* LoadImage( std::string filename );/**< Loads supported images. */