/// This is just a very basic sprite drawing routine. all it uses are screen coords void c_sprite::draw_screen(int x, int y) { int sheetx = sheetindex % SHEET_OBJECTSWIDE; int sheety = sheetindex / SHEET_OBJECTSWIDE; if(fileindex == -1) { if(config.block_count) config.drawcount ++; al_draw_bitmap_region(IMGObjectSheet, sheetx * spritewidth * spritescale, sheety * spriteheight * spritescale, spritewidth * spritescale, spriteheight * spritescale, x + offset_x, y + offset_y, 0); } else { if(config.block_count) config.drawcount ++; al_draw_bitmap_region(getImgFile(fileindex), sheetx * spritewidth * spritescale, sheety * spriteheight * spritescale, spritewidth * spritescale, spriteheight * spritescale, x + offset_x, y + (offset_y - WALLHEIGHT * spritescale), 0); } if(!subsprites.empty()) { for(int i = 0; i < subsprites.size(); i++) { subsprites[i].draw_screen(x, y); } } }
inline ALLEGRO_BITMAP* imageSheet(t_subSprite sprite, ALLEGRO_BITMAP* defaultBmp) { if (sprite.fileIndex == -1) { return defaultBmp; } else { return getImgFile(sprite.fileIndex); } }
inline BITMAP* imageSheet(t_SpriteWithOffset sprite, BITMAP* defaultBmp) { if (sprite.fileIndex == -1) { return defaultBmp; } else { return getImgFile(sprite.fileIndex); } }
void GUIPolygon::drawGL(const GUIVisualizationSettings& s) const { Boundary boundary = myShape.getBoxBoundary(); if (s.scale * MAX2(boundary.getWidth(), boundary.getHeight()) < s.minPolySize) { return; } if (getFill()) { if (myShape.size() < 3) { return; } } else { if (myShape.size() < 2) { return; } } AbstractMutex::ScopedLocker locker(myLock); //if (myDisplayList == 0 || (!getFill() && myLineWidth != s.polyExaggeration)) { // storeTesselation(s.polyExaggeration); //} glPushName(getGlID()); glPushMatrix(); glTranslated(0, 0, getLayer()); // XXX shape should be rotated around its center when initializing the polygon. do we even need this? //glRotated(getAngle(), 0, 0, 1); GLHelper::setColor(getColor()); int textureID = -1; if (getFill()) { const std::string& file = getImgFile(); if (file != "") { textureID = GUITexturesHelper::getTextureID(file); } } // init generation of texture coordinates if (textureID >= 0) { glEnable(GL_TEXTURE_2D); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); // without DEPTH_TEST vehicles may be drawn below roads glDisable(GL_LIGHTING); glDisable(GL_COLOR_MATERIAL); glDisable(GL_ALPHA_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBindTexture(GL_TEXTURE_2D, textureID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // http://www.gamedev.net/topic/133564-glutesselation-and-texture-mapping/ glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_S, GL_OBJECT_PLANE, xPlane); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_T, GL_OBJECT_PLANE, yPlane); } // recall tesselation //glCallList(myDisplayList); performTesselation(s.polyExaggeration); // de-init generation of texture coordinates if (textureID >= 0) { glEnable(GL_DEPTH_TEST); glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); } glPopMatrix(); drawName(myShape.getPolygonCenter(), s.scale, s.polyName); glPopName(); }
void c_sprite::draw_world_offset(int x, int y, int z, Block * b, int tileoffset, bool chop) { if(defaultsheet == 0) defaultsheet = IMGObjectSheet; //sprites can be offset by a random amount, both animationwise, and just variationwise. //the base offset is set here. int rando = randomCube[(b->x)%RANDOM_CUBE][(b->y)%RANDOM_CUBE][(b->z)%RANDOM_CUBE]; //and the random offset of the animation frame is set here, provided the sprite iis set to use random animation frames. int offsetAnimFrame = ((randomanimation?rando:0) + currentAnimationFrame) % MAX_ANIMFRAME; //the following stuff is only bothered with if the animation frames say it should be drawn. this can be over-ridden // by setting animate to 0 if(sheetindex == 48) { int spam = 0; spam++; } if ((animframes & (1 << offsetAnimFrame)) || !animate) { //if set by the xml file, a random offset between 0 and 'variations' is added to the sprite. int randoffset = 0; if(variations) randoffset = rando%variations; if(!b) return; //if the xml says that this is a blood sprite, and offset is set here for proper pooling. this over-rides the random offset. if(bloodsprite) randoffset = getBloodOffset(b); if((water_direction < 0) || (water_direction == get_relative_water_direction(b))) { if(( //these are all border conditions. this first section is a list of positive conditions. if at least one of the border conditions is met, the tile can be shown. (openborders & b->openborders) || (upstairborders & b->upstairborders) || (downstairborders & b->downstairborders) || (rampborders & b->rampborders) || (wallborders & b->wallborders) || (floorborders & b->floorborders) || (lightborders & b->lightborders) ) && !( //This second block consists of negative conditions. if /any/ of these border conditions are met, the tile will not be drawn (notopenborders & b->openborders) || (notupstairborders & b->upstairborders) || (notdownstairborders & b->downstairborders) || (notrampborders & b->rampborders) || (notwallborders & b->wallborders) || (notfloorborders & b->floorborders) || (darkborders & b->lightborders) )) { int foo = 0; if( ( snowmin <= b->snowlevel && (snowmax == -1 || snowmax >= b->snowlevel) ) && ( bloodmin <= b->bloodlevel && (bloodmax == -1 || bloodmax >= b->bloodlevel) ) && ( mudmin <= b->mudlevel && (mudmax == -1 || mudmax >= b->mudlevel) ) && ( grassmin <= b->grasslevel && (grassmax == -1 || grassmax >= b->grasslevel) ) && //only bother with this tile if it's in the light, or not. ( (light==LIGHTANY) || ( (light==LIGHTYES) && b->designation.bits.outside ) || ( (light==LIGHTNO) && !(b->designation.bits.outside) ) ) && ( (grasstype == -1) || (grasstype == b->grassmat) ) && ( (grass_growth == GRASS_GROWTH_ANY) || ( (grass_growth == GRASS_GROWTH_NORMAL) && ( (b->tileMaterial == tiletype_material::GRASS_DARK) || (b->tileMaterial == tiletype_material::GRASS_LIGHT) ) ) || ( (grass_growth == GRASS_GROWTH_DRY) && (b->tileMaterial == tiletype_material::GRASS_DRY) ) || ( (grass_growth == GRASS_GROWTH_DEAD) && (b->tileMaterial == tiletype_material::GRASS_DEAD) ) ) ) { int32_t drawx = x; int32_t drawy = y; int32_t drawz = z; //- ownerSegment->sizez + 1; correctBlockForSegmetOffset( drawx, drawy, drawz); correctBlockForRotation( drawx, drawy, drawz, b->ownerSegment->rotation); int32_t viewx = drawx; int32_t viewy = drawy; int32_t viewz = drawz; pointToScreen((int*)&drawx, (int*)&drawy, drawz); drawx -= (TILEWIDTH>>1)*config.scale; if(((drawx + spritewidth*config.scale) < 0) || (drawx > al_get_bitmap_width(al_get_target_bitmap())) || ((drawy + spriteheight*config.scale) < 0) || (drawy > al_get_bitmap_height(al_get_target_bitmap()))) return; int sheetx, sheety; if(tilelayout == BLOCKTILE) { sheetx = ((sheetindex+tileoffset+randoffset) % SHEET_OBJECTSWIDE) * spritewidth; sheety = ((sheetindex+tileoffset+randoffset) / SHEET_OBJECTSWIDE) * spriteheight; } else if(tilelayout == RAMPBOTTOMTILE) { sheetx = SPRITEWIDTH * b->ramp.index; sheety = ((TILEHEIGHT + FLOORHEIGHT + SPRITEHEIGHT) * (sheetindex+tileoffset+randoffset))+(TILEHEIGHT + FLOORHEIGHT); } else if(tilelayout == RAMPTOPTILE) { sheetx = SPRITEWIDTH * b->ramp.index; sheety = (TILEHEIGHT + FLOORHEIGHT + SPRITEHEIGHT) * (sheetindex+tileoffset+randoffset); } else { sheetx = ((sheetindex+tileoffset+randoffset) % SHEET_OBJECTSWIDE) * spritewidth; sheety = ((sheetindex+tileoffset+randoffset) / SHEET_OBJECTSWIDE) * spriteheight; } ALLEGRO_COLOR shade_color = get_color(b); if(!b->designation.bits.pile && config.fog_of_war && (contentLoader->gameMode.g_mode == GAMEMODE_ADVENTURE)) { shade_color.r *= 0.25f; shade_color.g *= 0.25f; shade_color.b *= 0.25f; } if(chop && ( halftile == HALFTILECHOP)) { if(fileindex < 0) { if(config.block_count) config.drawcount ++; if(shade_color.a > 0.001f) al_draw_tinted_scaled_bitmap( defaultsheet, premultiply(shade_color), sheetx * spritescale, (sheety+WALL_CUTOFF_HEIGHT) * spritescale, spritewidth * spritescale, (spriteheight-WALL_CUTOFF_HEIGHT) * spritescale, drawx + (offset_x + offset_user_x)*config.scale, drawy + (offset_user_y + (offset_y - WALLHEIGHT)+WALL_CUTOFF_HEIGHT)*config.scale, spritewidth*config.scale, (spriteheight-WALL_CUTOFF_HEIGHT)*config.scale, 0); } else { if(config.block_count) config.drawcount ++; if(shade_color.a > 0.001f) al_draw_tinted_scaled_bitmap( getImgFile(fileindex), premultiply(shade_color), sheetx * spritescale, (sheety+WALL_CUTOFF_HEIGHT) * spritescale, spritewidth * spritescale, (spriteheight-WALL_CUTOFF_HEIGHT) * spritescale, drawx + (offset_x + offset_user_x)*config.scale, drawy + (offset_user_y + (offset_y - WALLHEIGHT)+WALL_CUTOFF_HEIGHT)*config.scale, spritewidth*config.scale, (spriteheight-WALL_CUTOFF_HEIGHT)*config.scale, 0); } //draw cut-off floor thing if(config.block_count) config.drawcount ++; if(shade_color.a > 0.001f) al_draw_scaled_bitmap(IMGObjectSheet, TILEWIDTH * SPRITEFLOOR_CUTOFF, 0, SPRITEWIDTH, SPRITEWIDTH, drawx+offset_x, drawy+offset_y-((SPRITEHEIGHT-WALL_CUTOFF_HEIGHT)/2), SPRITEWIDTH*config.scale, SPRITEWIDTH*config.scale, 0); } else if ((chop && (halftile == HALFTILEYES)) || (!chop && (halftile == HALFTILENO)) || (!chop && (halftile == HALFTILECHOP)) || (halftile == HALFTILEBOTH)) { if((isoutline == OUTLINENONE) || ((isoutline == OUTLINERIGHT) && (b->depthBorderNorth)) || ((isoutline == OUTLINELEFT) && (b->depthBorderWest)) || ((isoutline == OUTLINEBOTTOM) && (b->depthBorderDown))) { if(fileindex < 0) { if(config.block_count) config.drawcount ++; if(shade_color.a > 0.001f) al_draw_tinted_scaled_bitmap( defaultsheet, premultiply(shade_color), sheetx * spritescale, sheety * spritescale, spritewidth * spritescale, spriteheight * spritescale, drawx + (offset_x + offset_user_x)*config.scale, drawy + (offset_user_y + (offset_y - WALLHEIGHT))*config.scale, spritewidth*config.scale, spriteheight*config.scale, 0); } else { if(config.block_count) config.drawcount ++; if(shade_color.a > 0.001f) al_draw_tinted_scaled_bitmap( getImgFile(fileindex), premultiply(shade_color), sheetx * spritescale, sheety * spritescale, spritewidth * spritescale, spriteheight * spritescale, drawx + (offset_x + offset_user_x)*config.scale, drawy + (offset_user_y + (offset_y - WALLHEIGHT))*config.scale, spritewidth*config.scale, spriteheight*config.scale, 0); } } if(needoutline) { //drawy -= (WALLHEIGHT); //Northern border if(b->depthBorderNorth) DrawSpriteFromSheet(281, IMGObjectSheet, al_map_rgb(255,255,255), drawx + (offset_x)*config.scale, drawy + (offset_y)*config.scale, b ); //Western border if(b->depthBorderWest) DrawSpriteFromSheet(280, IMGObjectSheet, al_map_rgb(255,255,255), drawx + (offset_x)*config.scale, drawy + (offset_y)*config.scale, b ); //drawy += (WALLHEIGHT); } } //draw_textf_border(font, al_map_rgb(255,255,255), drawx, drawy, 0, "%d,%d", fileindex, sheetindex); } }
void GUIPolygon::drawGL(const GUIVisualizationSettings& s) const { if (s.polySize.getExaggeration(s) == 0) { return; } Boundary boundary = myShape.getBoxBoundary(); if (s.scale * MAX2(boundary.getWidth(), boundary.getHeight()) < s.polySize.minSize) { return; } if (getFill()) { if (myShape.size() < 3) { return; } } else { if (myShape.size() < 2) { return; } } AbstractMutex::ScopedLocker locker(myLock); //if (myDisplayList == 0 || (!getFill() && myLineWidth != s.polySize.getExaggeration(s))) { // storeTesselation(s.polySize.getExaggeration(s)); //} glPushName(getGlID()); glPushMatrix(); glTranslated(0, 0, getLayer()); glRotated(-getNaviDegree(), 0, 0, 1); GLHelper::setColor(getColor()); int textureID = -1; if (getFill()) { const std::string& file = getImgFile(); if (file != "") { textureID = GUITexturesHelper::getTextureID(file, true); } } // init generation of texture coordinates if (textureID >= 0) { glEnable(GL_TEXTURE_2D); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); // without DEPTH_TEST vehicles may be drawn below roads glDisable(GL_LIGHTING); glDisable(GL_COLOR_MATERIAL); glDisable(GL_ALPHA_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBindTexture(GL_TEXTURE_2D, textureID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // http://www.gamedev.net/topic/133564-glutesselation-and-texture-mapping/ glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_S, GL_OBJECT_PLANE, xPlane); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_T, GL_OBJECT_PLANE, yPlane); } // recall tesselation //glCallList(myDisplayList); performTesselation(myLineWidth * s.polySize.getExaggeration(s)); // de-init generation of texture coordinates if (textureID >= 0) { glEnable(GL_DEPTH_TEST); glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); } #ifdef GUIPolygon_DEBUG_DRAW_VERTICES GLHelper::debugVertices(myShape, 80 / s.scale); #endif glPopMatrix(); const Position namePos = myShape.getPolygonCenter(); drawName(namePos, s.scale, s.polyName); if (s.polyType.show) { GLHelper::drawText(myType, namePos + Position(0, -0.6 * s.polyType.size / s.scale), GLO_MAX, s.polyType.size / s.scale, s.polyType.color); } glPopName(); }