static void init_textures(void) { int i; glGenTextures(NUM_TYPES, &scene.typeTextures[0]); for(i = 22; i < NUM_TYPES; ++i) { if(scene.typeImages[i] != NULL) { int glFormat = GL_RGB; if(bitmap_bytesPerPixel(scene.typeImages[i]) == 4) glFormat = GL_RGBA; glBindTexture(GL_TEXTURE_2D, scene.typeTextures[i]); gluBuild2DMipmaps( GL_TEXTURE_2D, // the current 2D texture glFormat, //internal format for texture bitmap_width(scene.typeImages[i]), // size in s coor bitmap_height(scene.typeImages[i]), // size in t coord glFormat, // incoming data format; should match internal GL_UNSIGNED_BYTE, // type of incoming data bitmap_pixels(scene.typeImages[i]) // pointer to the data ); glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 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); glTexImage2D(GL_TEXTURE_2D, 0, glFormat, bitmap_width(scene.typeImages[i]), bitmap_height(scene.typeImages[i]), 0, glFormat, GL_UNSIGNED_BYTE, bitmap_pixels(scene.typeImages[i])); } } }
// ------- Begin of function SnowInfo::draw_at ------// void SnowInfo::draw_at(short absX, short absY) { //----------- calculate absolute positions ------------// int absX1 = absX + offset_x; int absY1 = absY + offset_y; //----------- use fast method for non-gate square short bitmapWidth = bitmap_width(); short bitmapHeight = bitmap_height(); int absX2 = absX1 + bitmapWidth - 1; int absY2 = absY1 + bitmapHeight - 1; //-------- check if the firm is within the view area --------// int x1 = absX1 - World::view_top_x; if( x1 <= -bitmapWidth || x1 >= ZOOM_WIDTH ) // out of the view area, not even a slight part of it appears in the view area return; int y1 = absY1 - World::view_top_y; if( y1 <= -bitmapHeight || y1 >= ZOOM_HEIGHT ) return; //------- decide which approach to use for displaying -----// int x2 = absX2 - World::view_top_x; int y2 = absY2 - World::view_top_y; //---- only portion of the sprite is inside the view area ------// if( x1 < 0 || x2 >= ZOOM_WIDTH || y1 < 0 || y2 >= ZOOM_HEIGHT ) { // no put_bitmap_area_remap vga_back.put_bitmap_area_trans_decompress( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr, MAX(0,x1)-x1, MAX(0,y1)-y1, MIN(ZOOM_WIDTH-1,x2)-x1, MIN(ZOOM_HEIGHT-1,y2)-y1); } else //---- the whole sprite is inside the view area ------// { vga_back.put_bitmap_trans_decompress( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr); } }
void bitmap_draw(bitmap_t* bitmap, short* buffer, unsigned int x, unsigned int y) { if (bitmap == NULL) { return; } int width = bitmap_width(bitmap); int height = bitmap_height(bitmap); if (!video_check_bounds(x, y)) { return; } int i; int screen_location = y + height - 1; short* buffer_position = (short*) buffer + screen_location * video_width() + x; short* bitmap_position = bitmap->bitmapData; for (i = 0; i < height; i++) { memcpy((char*) buffer_position, (char*) bitmap_position, width << 1); if (width % 2 == 0) { bitmap_position += width; } else { bitmap_position += width + 1; } buffer_position -= video_width(); } }
//------- Begin of function WallInfo::draw_at -----------// // // Draw the wall on the zoom map, given the exact pixel position to put // the bitmap. // // <int> absBaseX, absBaseY - the absolute base (center-bottom) coordination // of the building. // // Draw the current plant on the map // void WallInfo::draw_at(int absBaseX, int absBaseY, char *remapTbl) { //-------- check if the wall is within the view area --------// int x1 = absBaseX - World::view_top_x; int x2 = x1 + bitmap_width() -1; if( x2 < 0 || x1 >= ZOOM_WIDTH ) // out of the view area, not even a slight part of it appears in the view area return; int y1 = absBaseY - World::view_top_y; int y2 = y1 + bitmap_height() -1; if( y2 < 0 || y1 >= ZOOM_HEIGHT ) return; //------- decide which approach to use for displaying -----// //---- only portion of the sprite is inside the view area ------// if( x1 < 0 || x2 >= ZOOM_WIDTH || y1 < 0 || y2 >= ZOOM_HEIGHT ) { // no put_bitmap_area_remap if(is_trans()) { if( remapTbl) vga_back.put_bitmap_area_trans_remap( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr, max(0,x1)-x1, max(0,y1)-y1, min(ZOOM_WIDTH-1,x2)-x1, min(ZOOM_HEIGHT-1,y2)-y1, remapTbl); else vga_back.put_bitmap_area_trans( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr, max(0,x1)-x1, max(0,y1)-y1, min(ZOOM_WIDTH-1,x2)-x1, min(ZOOM_HEIGHT-1,y2)-y1); } else { if( remapTbl) vga_back.put_bitmap_area_remap( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr, max(0,x1)-x1, max(0,y1)-y1, min(ZOOM_WIDTH-1,x2)-x1, min(ZOOM_HEIGHT-1,y2)-y1, remapTbl); else vga_back.put_bitmap_area( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr, max(0,x1)-x1, max(0,y1)-y1, min(ZOOM_WIDTH-1,x2)-x1, min(ZOOM_HEIGHT-1,y2)-y1); } } //---- the whole sprite is inside the view area ------// else { if(is_trans() ) { if( remapTbl) vga_back.put_bitmap_trans_remap( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr, remapTbl); else vga_back.put_bitmap_trans( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr); } else { if( remapTbl) vga_back.put_bitmap_remap( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr, remapTbl ); else vga_back.put_bitmap( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr); } } }