summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/main.c b/main.c
index e629966..260328c 100644
--- a/main.c
+++ b/main.c
@@ -12,10 +12,8 @@ SDL_Texture *createTiledTexture(SDL_Renderer *context, const char *filename) {
int tile_h = texture_surface->h;
SDL_FreeSurface(texture_surface);
- Uint32 pixelformat;
- SDL_QueryTexture(texture_tile, &pixelformat, 0, 0, 0);
SDL_Texture *texture = SDL_CreateTexture(context,
- pixelformat,
+ SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET,
WINDOW_W, WINDOW_H);
SDL_SetRenderTarget(context, texture);
@@ -47,19 +45,34 @@ int main() {
SDL_Texture *background = createTiledTexture(context, "background.bmp");
SDL_Texture *foreground = createTiledTexture(context, "foreground.bmp");
+ SDL_SetTextureBlendMode(foreground, SDL_BLENDMODE_BLEND);
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;
+ ((Uint32 *)mask_surface->pixels)[i] = 0x00000000;
}
- for (int i = 0; i < mask_surface->w * 50; i++) {
+ for (int i = mask_surface->w * 500; i < mask_surface->w * mask_surface->h; i++) {
((Uint32 *)mask_surface->pixels)[i] = 0xffffffff;
}
SDL_UnlockSurface(mask_surface);
- SDL_Texture *terrain_texture = SDL_CreateTextureFromSurface(context, mask_surface);
+
+ SDL_Texture *terrain = SDL_CreateTextureFromSurface(context, mask_surface);
+
+ SDL_BlendMode true_mul = SDL_ComposeCustomBlendMode(
+ SDL_BLENDFACTOR_ZERO,
+ SDL_BLENDFACTOR_SRC_COLOR,
+ SDL_BLENDOPERATION_ADD,
+ SDL_BLENDFACTOR_ONE,
+ SDL_BLENDFACTOR_ZERO,
+ SDL_BLENDOPERATION_ADD);
+ SDL_SetTextureBlendMode(terrain, true_mul);
+
+ SDL_SetRenderTarget(context, foreground);
+ SDL_RenderCopy(context, terrain, 0, 0);
+ SDL_SetRenderTarget(context, 0);
int exit = 0;
while (!exit) {
@@ -70,10 +83,6 @@ int main() {
}
}
SDL_RenderCopy(context, background, 0, 0);
- SDL_SetRenderTarget(context, foreground);
- 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);