void GameBoard::initializeGL( QGLWidget & target ) { QImage wall( "textures/wall.jpg" ); this->wallTexture = target.bindTexture( wall ); QImage grass( "textures/grass.jpg" ); this->grassTexture = target.bindTexture( grass ); QImage roof( "textures/roof.jpg" ); this->roofTexture = target.bindTexture( roof ); QImage tiles( "textures/tiles.jpg" ); this->ghostsStartTexture = target.bindTexture( tiles ); QImage dot( "textures/dot.png" ); this->dotTexture = target.bindTexture( dot ); this->staticList = glGenLists( 1 ); glNewList( this->staticList, GL_COMPILE ); { for ( int y = 0; y < this->height; ++y ) { for ( int x = 0; x < this->width; ++x ) { if ( GameBoard::Wall == this->blocks[ y ][ x ] ) { this->addWallBlock( x, y ); } else if ( GameBoard::Path == this->blocks[ y ][ x ] ) { this->addGrassBlock( x, y ); } else if ( GameBoard::Dot == this->blocks[ y ][ x ] ) { this->addGrassBlock( x, y ); } else if ( GameBoard::Powerup == this->blocks[ y ][ x ] ) { this->addGrassBlock( x, y ); } else if ( GameBoard::Teleport1 == this->blocks[ y ][ x ] ) { this->addGrassBlock( x, y ); } else if ( GameBoard::PlayerStart == this->blocks[ y ][ x ] ) { this->addGrassBlock( x, y ); } else if ( GameBoard::PlayerWall == this->blocks[ y ][ x ] ) { this->addFloorBlock( x, y, this->roofTexture, this->defaultMaterial ); } else if ( GameBoard::GhostsStart == this->blocks[ y ][ x ] ) { this->addFloorBlock( x, y, this->ghostsStartTexture, this->defaultMaterial ); } } } } glEndList(); this->dotList = glGenLists( 1 ); this->dotQuadric = gluNewQuadric(); gluQuadricTexture( this->dotQuadric, true ); glNewList( this->dotList, GL_COMPILE ); { glBindTexture( GL_TEXTURE_2D, this->dotTexture ); gluSphere( this->dotQuadric, 0.1f, 360 / 30, 180 / 30 ); } glEndList(); }
void PacMan::initializeGL( QGLWidget & target ) { QImage pacman( "textures/pacman.png" ); this->pacmanTexture = target.bindTexture( pacman ); this->sphereList = glGenLists( 1 ); this->sphereQuadric = gluNewQuadric(); gluQuadricTexture( this->sphereQuadric, true ); glNewList( this->sphereList, GL_COMPILE ); { glBindTexture( GL_TEXTURE_2D, this->pacmanTexture ); this->material.updateGlState( Material::Front ); glRotatef( 180, 1.0f, 0.0f, 0.0f ); gluSphere( this->sphereQuadric, this->radius, 360 / 5, 180 / 5 ); } glEndList(); }
void Ghost::initializeGL(QGLWidget& target) { QImage ghost("../gfx/ghost.png"); _ghostTexture = target.bindTexture(ghost); _sphereList = glGenLists(1); _sphereQuadric = gluNewQuadric(); gluQuadricTexture(_sphereQuadric, true); glNewList(_sphereList, GL_COMPILE); { glBindTexture(GL_TEXTURE_2D, _ghostTexture); _material.updateGlState(Material::Front); glRotatef(180, 1.0f, 0.0f, 0.0f); gluSphere(_sphereQuadric, _radius, 360/5, 180/5); } glEndList(); }
Sprite::Sprite(const QString& name, const QVector3D& boundsMin, const QVector3D& boundsMax, QGLWidget& glWidget) : imageDiffuse_("assets:/demo_data/sprites/" + name + "_diffuse_0.png") , imageNormal_("assets:/demo_data/sprites/" + name + "_normal_0.png") , imageOffset_("assets:/demo_data/sprites/" + name + "_offset_0.png") , boundsMin_(boundsMin) , boundsMax_(boundsMax) , pixelSize_(QVector2D(0.0f, 0.0f)) , valid_(false) , creatorWidget_(glWidget) { // All images must be successfully loaded if(imageDiffuse_.isNull()) { qDebug() << "Failed to load diffuse image for sprite " << name; return; } if(imageNormal_.isNull()) { qDebug() << "Failed to load normal image for sprite " << name; return; } if(imageOffset_.isNull()) { qDebug() << "Failed to load offset image for sprite " << name; return; } // Image sizes must match if(!(imageDiffuse_.size() == imageNormal_.size() && imageNormal_.size() == imageOffset_.size())) { qDebug() << "Image sizes in sprite " << name << " don't match"; return; } pixelSize_ = QVector2D(imageDiffuse_.size().width(), imageDiffuse_.size().height()); // Image sizes must be powers of two if(!isPowerOfTwo(imageDiffuse_.size().width()) || !isPowerOfTwo(imageDiffuse_.size().height())) { qDebug() << "Non-power of two texture size for sprite " << name << " - not supported yet"; return; } // Upload to GL textures. textureDiffuse_ = glWidget.bindTexture(imageDiffuse_, GL_TEXTURE_2D, GL_RGBA, QGLContext::InvertedYBindOption); textureNormal_ = glWidget.bindTexture(imageNormal_, GL_TEXTURE_2D, GL_RGB, QGLContext::InvertedYBindOption); textureOffset_ = glWidget.bindTexture(imageOffset_, GL_TEXTURE_2D, GL_RGB, QGLContext::InvertedYBindOption); // Check that the textures were uploaded successfully. if(textureDiffuse_ == 0) { qDebug() << "Failed to create diffuse texture for sprite " << name; return; } if(textureNormal_ == 0) { qDebug() << "Failed to create normal texture for sprite " << name; return; } if(textureOffset_ == 0) { qDebug() << "Failed to create offset texture for sprite " << name; return; } valid_ = true; }