diff options
author | Juan Manuel Tomas <jtomas1815@gmail.com> | 2022-01-15 02:33:41 -0300 |
---|---|---|
committer | Juan Manuel Tomas <jtomas1815@gmail.com> | 2022-01-15 02:33:41 -0300 |
commit | 5372bf4e4d5dace73cd8d6e02f7d172cdec97cd0 (patch) | |
tree | e6cd05572355c3d6c9bd1a3f987eb6308e460f03 | |
parent | 29145a136faf9acd7442708741fd26bb56dba66f (diff) | |
download | cannons-5372bf4e4d5dace73cd8d6e02f7d172cdec97cd0.tar.gz cannons-5372bf4e4d5dace73cd8d6e02f7d172cdec97cd0.zip |
Apply mask to foreground
-rw-r--r-- | main.c | 27 |
1 files changed, 19 insertions, 8 deletions
@@ -14,7 +14,10 @@ SDL_Texture *createTiledTexture(SDL_Renderer *context, const char *filename) { Uint32 pixelformat; SDL_QueryTexture(texture_tile, &pixelformat, 0, 0, 0); - SDL_Texture *texture = SDL_CreateTexture(context, pixelformat, SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET, WINDOW_W, WINDOW_H); + SDL_Texture *texture = SDL_CreateTexture(context, + pixelformat, + SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET, + WINDOW_W, WINDOW_H); SDL_SetRenderTarget(context, texture); for (int y = 0; y < WINDOW_H; y += tile_h) { for (int x = 0; x < WINDOW_W; x += tile_w) { @@ -45,9 +48,18 @@ int main() { SDL_Texture *background = createTiledTexture(context, "background.bmp"); SDL_Texture *foreground = createTiledTexture(context, "foreground.bmp"); - // TODO: - // - Map has a mask generated by the game, of where the terrain (foregroud) exists - float *mask = calloc(WINDOW_W * WINDOW_H, 4); + SDL_Surface *mask_surface = SDL_CreateRGBSurfaceWithFormat(0, + WINDOW_W, WINDOW_H, 32, SDL_PIXELFORMAT_RGBA8888); + + SDL_LockSurface(mask_surface); + for (int i = 0; i < mask_surface->w * mask_surface->h; i++) { + ((Uint32 *)mask_surface->pixels)[i] = 0x000000ff; + } + for (int i = 0; i < mask_surface->w * 50; i++) { + ((Uint32 *)mask_surface->pixels)[i] = 0xffffffff; + } + SDL_UnlockSurface(mask_surface); + SDL_Texture *terrain_texture = SDL_CreateTextureFromSurface(context, mask_surface); int exit = 0; while (!exit) { @@ -59,11 +71,10 @@ int main() { } SDL_RenderCopy(context, background, 0, 0); SDL_SetRenderTarget(context, foreground); - - // TODO: Get masking right - SDL_SetTextureBlendMode(mask_texture, SDL_BLENDMODE_MUL); - SDL_RenderCopy(context, mask_texture, 0, 0); + SDL_SetTextureBlendMode(terrain_texture, SDL_BLENDMODE_MUL); + SDL_RenderCopy(context, terrain_texture, 0, 0); SDL_SetRenderTarget(context, 0); + SDL_RenderCopy(context, foreground, 0, 0); SDL_RenderPresent(context); SDL_Delay(10); |