/// <summary> Updates the underlying atlas bitmap, fields, and texture. </summary> public void UpdateState(BlockInfo info, Bitmap bmp) { if (!FastBitmap.CheckFormat(bmp.PixelFormat)) { Utils.LogDebug("Converting terrain atlas to 32bpp image"); drawer.ConvertTo32Bpp(ref bmp); } AtlasBitmap = bmp; elementSize = bmp.Width >> 4; using (FastBitmap fastBmp = new FastBitmap(bmp, true)) { info.RecalculateSpriteBB(fastBmp); TexId = graphics.CreateTexture(fastBmp); } }
/// <summary> Creates a 2D texture with origin at the specified window coordinates. </summary> public Texture Make2DTexture(Bitmap bmp, Size used, int windowX, int windowY) { int texId = graphics.CreateTexture(bmp, true); return(new Texture(texId, windowX, windowY, used.Width, used.Height, (float)used.Width / bmp.Width, (float)used.Height / bmp.Height)); }
static void CheckShadowTexture(IGraphicsApi graphics) { if (shadowTex != -1) { return; } const int size = 128, half = size / 2; using (Bitmap bmp = Platform.CreateBmp(size, size)) using (FastBitmap fastBmp = new FastBitmap(bmp, true, false)) { int inPix = new FastColour(0, 0, 0, 200).ToArgb(); int outPix = new FastColour(0, 0, 0, 0).ToArgb(); for (int y = 0; y < fastBmp.Height; y++) { int *row = fastBmp.GetRowPtr(y); for (int x = 0; x < fastBmp.Width; x++) { double dist = (half - (x + 0.5)) * (half - (x + 0.5)) + (half - (y + 0.5)) * (half - (y + 0.5)); row[x] = dist < half * half ? inPix : outPix; } } shadowTex = graphics.CreateTexture(fastBmp, true); } }
/// <summary> Creates a new texture that contains the tile at the specified index. </summary> public int LoadTextureElement(int index) { int size = TileSize; using (FastBitmap atlas = new FastBitmap(AtlasBitmap, true, true)) using (Bitmap bmp = Platform.CreateBmp(size, size)) using (FastBitmap dst = new FastBitmap(bmp, true, false)) { int x = index % TilesPerRow, y = index / TilesPerRow; FastBitmap.MovePortion(x * size, y * size, 0, 0, atlas, dst, size); return(gfx.CreateTexture(dst, true)); } }
/// <summary> Creates a new texture that contains the tile at the specified index. </summary> public int LoadTextureElement(int index) { int size = elementSize; using (FastBitmap atlas = new FastBitmap(AtlasBitmap, true, true)) using (Bitmap bmp = new Bitmap(size, size)) using (FastBitmap dst = new FastBitmap(bmp, true, false)) { FastBitmap.MovePortion((index & 0x0F) * size, (index >> 4) * size, 0, 0, atlas, dst, size); return(graphics.CreateTexture(dst)); } }
void Make1DTexture(int i, FastBitmap atlas, TerrainAtlas2D atlas2D, int atlas1DHeight, ref int index) { int elemSize = atlas2D.elementSize; using (Bitmap atlas1d = new Bitmap(atlas2D.elementSize, atlas1DHeight)) using (FastBitmap dst = new FastBitmap(atlas1d, true, false)) { for (int index1D = 0; index1D < elementsPerAtlas1D; index1D++) { FastBitmap.MovePortion((index & 0x0F) * elemSize, (index >> 4) * elemSize, 0, index1D * elemSize, atlas, dst, elemSize); index++; } TexIds[i] = graphics.CreateTexture(dst); } }
static void CheckShadowTexture( IGraphicsApi graphics ) { if( shadowTex != -1 ) return; const int size = 128, half = size / 2; using( Bitmap bmp = new Bitmap( size, size ) ) using( FastBitmap fastBmp = new FastBitmap( bmp, true, false ) ) { int inPix = new FastColour( 0, 0, 0, 200 ).ToArgb(); int outPix = new FastColour( 0, 0, 0, 0 ).ToArgb(); for( int y = 0; y < fastBmp.Height; y++ ) { int* row = fastBmp.GetRowPtr( y ); for( int x = 0; x < fastBmp.Width; x++ ) { double dist = (half - (x + 0.5)) * (half - (x + 0.5)) + (half - (y + 0.5)) * (half - (y + 0.5)); row[x] = dist < half * half ? inPix : outPix; } } shadowTex = graphics.CreateTexture( fastBmp ); } }