diff options
-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); |