void OSScreenManager::fillRect(SurfaceNum surfaceNum, Rect *rect, byte r, byte g, byte b) { DirectDrawSurface *surface = getDDSurface(surfaceNum); if (!surface) return; // If bounds are provided, clip and use them. Otherwise, use entire surface area Rect surfaceRect(0, 0, surface->getWidth(), surface->getHeight()); Rect tempRect; if (rect) { tempRect = *rect; tempRect.clip(surfaceRect); } else { tempRect = surfaceRect; } // Constrain the fill area to the set modification area of the surface Rect surfaceBounds = (surfaceNum == SURFACE_PRIMARY) ? _frontSurfaceBounds : _backSurfaces[surfaceNum]._bounds; if (!surfaceBounds.isEmpty()) tempRect.constrain(surfaceBounds); // If there is any area defined, clear it if (tempRect.isValidRect()) surface->fillRect(&tempRect, r, g, b); }
void OSScreenManager::fillRect(SurfaceNum surfaceNum, Rect *rect, byte r, byte g, byte b) { DirectDrawSurface *surface = getDDSurface(surfaceNum); if (!surface) return; // If bounds are provided, clip and use them. Otherwise, use entire surface area Rect surfaceRect(0, 0, surface->getWidth(), surface->getHeight()); Rect tempRect; if (rect) { tempRect = *rect; tempRect.clip(surfaceRect); } else { tempRect = surfaceRect; } if (tempRect.isValidRect()) surface->fillRect(&tempRect, r, g, b); }
DirectDrawSurface *DirectDrawSurface::LoadSurface(const string& filename,bool flip,unsigned char *buffer,int bufsize){ unsigned char *buf; DDSHeader *dds; File* file; int len; if(buffer==NULL){ file=File::ReadFile(filename); if(file==NULL) return 0; len=file->FileSize(); buffer=new unsigned char[len]; file->Read(buffer,1,len); }else{ len=bufsize; } buf=buffer; if(strncasecmp((char*)buf,"DDS ",4)) return NULL; buf+=4; dds=(DDSHeader*)buf; buf+=sizeof(DDSHeader); unsigned int format,target; int components; // Just to silence the compiler format=0; target=0; components=0; if(!DDS_GetInfo(dds,format,components,target)) return NULL; DirectDrawSurface *surface=new DirectDrawSurface; int mipmaps; surface->buffer=buffer; mipmaps=dds->mipmapcount; if(mipmaps!=0) mipmaps--; for(int i=0; i<(target==GL_TEXTURE_CUBE_MAP?6:1); i++){ DirectDrawSurface *base; if(target==GL_TEXTURE_CUBE_MAP){ surface->mipmaps.push_back(DirectDrawSurface()); base=&surface->mipmaps.back(); }else base=surface; base->format=format; base->target=target; base->dxt=buf; base->width=dds->width; base->height=dds->height; base->depth=DDS_Clamp(dds->depth); base->pitch=DDS_GetPitch(base->width,format,components); base->size=DDS_GetSizeBytes(base->width,base->height,format,components) * base->depth; base->components=components; base->mipmapcount=mipmaps; buf+=base->size; if(flip) base->Flip(); int w,h,d; w=DDS_Clamp(base->width>>1); h=DDS_Clamp(base->height>>1); d=DDS_Clamp(base->depth>>1); for(int j=0; j<mipmaps && ( w || h ); j++){ DirectDrawSurface *mip; base->mipmaps.push_back(DirectDrawSurface()); mip=&base->mipmaps.back(); mip->format=format; mip->target=target; mip->dxt=buf; mip->width=w; mip->height=h; mip->depth=d; mip->pitch=DDS_GetPitch(w,format,components); mip->size=DDS_GetSizeBytes(w,h,format,components) * d; mip->components=components; buf+=mip->size; if(flip) mip->Flip(); w=DDS_Clamp(w>>1); h=DDS_Clamp(h>>1); d=DDS_Clamp(d>>1); } } if(target==GL_TEXTURE_CUBE_MAP && flip){ DirectDrawSurface tmp=surface->mipmaps[3]; surface->mipmaps[3]=surface->mipmaps[2]; surface->mipmaps[2]=tmp; } return surface; }
DirectDrawSurface *DirectDraw::createSurfaceFromDesc(const DDSurfaceDesc &desc) { DirectDrawSurface *surface = new DirectDrawSurface(); surface->create(desc._w, desc._h, desc._bpp); return surface; }