diff options
author | davidovski <david@davidovski.xyz> | 2023-07-11 21:37:38 +0100 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2023-07-11 21:37:38 +0100 |
commit | ce892407370be42479bb05e9a2faa60a297c9886 (patch) | |
tree | d28da24f8f9978568cdcf2fd393e8c1bd2a7d74a /src/tiled.c | |
parent | ebbb6c8b0302589626a594399ec04e3c4555d5f6 (diff) |
make render changes on texture rather than image
Diffstat (limited to 'src/tiled.c')
-rw-r--r-- | src/tiled.c | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/src/tiled.c b/src/tiled.c index 65b9d1d..43afa7b 100644 --- a/src/tiled.c +++ b/src/tiled.c @@ -45,14 +45,34 @@ Vector2 translateTiledScreenPosition(Tiled tiled, Vector2 tiledPos) { }; } +void redrawTiledMap(Tiled tiled) { + BeginTextureMode(tiled.tilemapTexture); + for (int y = 0; y < tiled.tiledMap.height; y++) { + for (int x = 0; x < tiled.tiledMap.width; x++) { + int i = (tiled.tiledMap.height - y - 1)*tiled.tiledMap.width + x; + Color c = (Color){ + tiled.tiledMap.tilelayout[i], + 0, 0, 255 + }; + DrawPixel(x, y, c); + } + } + EndTextureMode(); + +} + + Tiled initTiled(TiledMap tiledMap) { Tiled tiled; tiled.tiledMap = tiledMap; + tiled.offset = (Vector2) {0, 0}; tiled.zoom = 64; - tiled.mapSize[0] = tiled.tiledMap.width; - tiled.mapSize[1] = tiled.tiledMap.height; + + tiled.mapSize[0] = tiledMap.width; + tiled.mapSize[1] = tiledMap.height; tiled.targetTexture = LoadRenderTexture(1, 1); + tiled.tilemapTexture = LoadRenderTexture(tiledMap.width, tiledMap.width); tiled.atlasSize[0] = tiledMap.atlasSize[0]; tiled.atlasSize[1] = tiledMap.atlasSize[1]; @@ -63,7 +83,7 @@ Tiled initTiled(TiledMap tiledMap) { tiledMap.atlasSize[1] * tiledMap.tileSize); - renderTilemapTexture(&tiled.tilemapTexture, tiled.tiledMap); + redrawTiledMap(tiled); initTiledShader(&tiled); return tiled; } @@ -73,20 +93,20 @@ void setTiledShaderUniforms(Tiled tiled) { SetShaderValue(tiled.shader, tiled.zoomLoc, &tiled.zoom, SHADER_UNIFORM_FLOAT); SetShaderValue(tiled.shader, tiled.atlasSizeLoc, &tiled.atlasSize, SHADER_UNIFORM_IVEC2); - SetShaderValue(tiled.shader, tiled.mapSizeLoc, &tiled.tilemapTexture.width, SHADER_UNIFORM_IVEC2); + SetShaderValue(tiled.shader, tiled.mapSizeLoc, &tiled.mapSize, SHADER_UNIFORM_IVEC2); SetShaderValueTexture(tiled.shader, tiled.atlasTextureLoc, tiled.atlasTexture); - SetShaderValueTexture(tiled.shader, tiled.tilemapTextureLoc, tiled.tilemapTexture); + SetShaderValueTexture(tiled.shader, tiled.tilemapTextureLoc, tiled.tilemapTexture.texture); } void unloadTiled(Tiled *tiled) { UnloadShader(tiled->shader); UnloadTexture(tiled->atlasTexture); - UnloadTexture(tiled->tilemapTexture); + UnloadRenderTexture(tiled->tilemapTexture); UnloadRenderTexture(tiled->targetTexture); } - void drawTiled(Tiled *tiled) { + //renderTiledMapTexture(tiled->tiledMap, tiled->tilemapTexture); BeginShaderMode(tiled->shader); setTiledShaderUniforms(*tiled); @@ -95,6 +115,10 @@ void drawTiled(Tiled *tiled) { (Vector2){0, 0}, WHITE); EndShaderMode(); + //DrawTextureRec(tiled->tilemapTexture.texture, + //(Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, + //(Vector2){0, 0}, + //WHITE); } int launchTiledView() { |