- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# C:/Documents and Settings/jegan/Desktop/projectX/Background.cpp

Go to the documentation of this file.

    00001 #include "Background.h"
    00002 #include "Screen.h"
    00003 #include "glfuncs.h"
    00004 #include "Level.h"
    00005
    00008 Background::Background(std::string filename, double depth)
    00009 :Sprite( filename ),
    00010  _depth( depth )
    00011 {
    00012 }
    00013
    00014 Background::Background(std::string filename, int width, int height, double depth)
    00015 :Sprite( filename, width, height ),
    00016  _depth( depth )
    00017 {
    00018 }
    00019
    00020 void Background::draw()
    00021 {
    00022         SDL_Rect screen = Screen::instance()->getScreenRect();
    00023         int height = Level::instance()->getHeight();
    00024         int width = Level::instance()->getWidth();
    00025
    00026         GLfloat texcoords[4];
    00027
    00028         texcoords[ 0 ] = ((GLfloat)screen.x/width)*_coords[2]*_depth;
    00029         texcoords[ 2 ] = texcoords[ 0 ] + ((GLfloat)screen.w/width)*_coords[2];
    00030         texcoords[ 1 ] = ((GLfloat)screen.y/height)*_coords[3]*_depth;
    00031         texcoords[ 3 ] = texcoords[ 1 ] + ((GLfloat)screen.h/height)*_coords[3];
    00032
    00033         glfuncs::instance()->glBindTexture(GL_TEXTURE_2D, _hTexture);
    00034         glfuncs::instance()->glBegin(GL_QUADS);
    00035         glfuncs::instance()->glTexCoord2f(texcoords[0],texcoords[1]);   glfuncs::instance()->glVertex2f(0,0);
    00036         glfuncs::instance()->glTexCoord2f(texcoords[2],texcoords[1]);   glfuncs::instance()->glVertex2f(screen.w,0);
    00037         glfuncs::instance()->glTexCoord2f(texcoords[2],texcoords[3]);   glfuncs::instance()->glVertex2f(screen.w,screen.h);
    00038         glfuncs::instance()->glTexCoord2f(texcoords[0],texcoords[3]);   glfuncs::instance()->glVertex2f(0,screen.h);
    00039         glfuncs::instance()->glEnd();
    00040 }
    00041
    00042 Background::~Background()
    00043 {
    00044         glfuncs::instance()->glDeleteTextures(1,&_hTexture);
    00045 }