Hi, I'm using the BGRA OpenGL and I want to draw the stretched bitmap in a pixelated way, instead of the bitmap get smooth when resized.
This is my code. Actually a window of 1280 by 720 pixels. It gets smooth when I upscale the window.
Edit: Maybe I must just stretch the bitmap when the object is created?
unit ugame;
{$mode objfpc}{$H+}
interface
uses
Classes, Forms, SysUtils, Graphics, BGRABitmap, BGRABitmapTypes, BGRAOpenGL,
Math;
type
{ TGame }
TGame = class
private
FTilesX: integer;
FTilesY: integer;
FTileW: integer;
FTileH: integer;
FOffsetX: integer;
FOffsetY: integer;
FWidth: integer;
FHeight: integer;
FTexture: IBGLTexture;
public
constructor Create(Width, Height: integer);
destructor Destroy; override;
public
procedure Draw;
end;
implementation
{ TGame }
constructor TGame.Create(Width, Height: integer);
begin
{ window size }
FWidth := Width;
FHeight := Height;
{ number of tiles, zero based, to be specified in level file }
FTilesX := 40 - 1;
FTilesY := 23 - 1;
{ tile width resolution dependant, window size is fixed and can be set only at startup }
FTileW := round(FWidth * 0.025); // 40 tiles of 32x32 @ 1280p
FTileH := round(FHeight * 0.045); // 22,5 tiles of 32x32 @ 720p
{ center the map }
FOffsetX := round((FWidth - ((FTilesX + 1) * FTileW)) * 0.5); // center x
FOffsetY := round((FHeight - ((FTilesY + 1) * FTileH)) * 0.5); // center y
{ graphics loading, to be specified in level file }
FTexture := BGLTexture(ExtractFilePath(Application.ExeName) + 'tile.png');
end;
destructor TGame.Destroy;
begin
FTexture.FreeMemory;
inherited Destroy;
end;
procedure TGame.Draw;
var
y, x: integer;
begin
{ Fill background }
BGLViewPort(FWidth, FHeight, BGRABlack);
for y := 0 to FTilesY do
begin
for x := 0 to FTilesX do
begin
FTexture.StretchDraw(FOffsetX + (x * FTileW), FOffsetY + (y * FTileH), FTileW, FTileH);
end;
end;
end;
end.