Skip to content

Commit

Permalink
Test menu background picture render
Browse files Browse the repository at this point in the history
  • Loading branch information
necromyhan committed Nov 21, 2023
1 parent 5e98236 commit 6d14200
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "game.h"
#include "menu.h"

static SDL_Texture* gStartMenuPic = NULL;

MENU*
CreateMenu(
Expand Down Expand Up @@ -109,12 +110,34 @@ StartMenuRender(GAME* Game)
goto exit;
}

if (!gStartMenuPic)
{
gStartMenuPic = CreateTextureFromImage(Game->Renderer, "assets/title.png");
if (NULL == gStartMenuPic)
{
status = -1;
goto exit;
}
}

status = SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 0);
if (status) { goto exit; }

status = SDL_RenderFillRect(Game->Renderer, NULL);
if (status) { goto exit; }

int w, h;
status = SDL_GetWindowSizeInPixels(Game->Window, &w, &h);
if (status) { goto exit; }

SDL_FRect picRect = {
(w - (Game->Field.WidthInCells - 1) * Game->Field.CellSize) / 2,
0,
(Game->Field.WidthInCells - 1) * Game->Field.CellSize,
(Game->Field.WidthInCells - 1) * Game->Field.CellSize };
SDL_RenderTexture(Game->Renderer, gStartMenuPic, NULL, &picRect);
if (status) { goto exit; }

int posX = Game->Field.CellSize;
int posY = Game->Field.CellSize;
for (int i = 0; i < Game->StartMenu->Count; ++i)
Expand Down

0 comments on commit 6d14200

Please sign in to comment.