diff --git a/data/test_background.bmp b/data/test_background.bmp new file mode 100644 index 0000000..aaec3b0 Binary files /dev/null and b/data/test_background.bmp differ diff --git a/handmade.c b/handmade.c index b0d7143..7e67557 100644 --- a/handmade.c +++ b/handmade.c @@ -84,6 +84,36 @@ static void DrawRectangle(game_offscreen_buffer *Buffer, F32 RealMinX, F32 RealM } } +#pragma pack(push, 1) +typedef struct bitmap_header { + U16 FileType; + U32 FileSize; + U16 Reserved1; + U16 Reserved2; + U32 BitmapOffset; + U32 Size; + S32 Width; + S32 Height; + U16 Planes; + U16 BitsPerPixel; +} bitmap_header; +#pragma pack(pop) + +static U32 *LoadBMP(thread_context *Thread, debug_read_file_result (*DEBUGPlatformReadEntireFile)(thread_context *Thread, const char *), char *FileName) +{ + U32 *Result = 0; + + debug_read_file_result ReadResult = DEBUGPlatformReadEntireFile(Thread, FileName); + if(ReadResult.ContentsSize > 0) { + bitmap_header *Header = (bitmap_header *)ReadResult.Contents; + + U32 *Pixels = (U32 *)((U8 *)ReadResult.Contents + Header->BitmapOffset); + Result = Pixels; + } + + return Result; +} + void UpdateAndRender(thread_context *Thread, game_memory *Memory, game_input *Input, game_offscreen_buffer *Buffer, game_sound_output_buffer *SoundBuffer) { @@ -100,6 +130,8 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory, game_input *In GameState = (game_state *)Memory->PermanentStorage; if(!Memory->IsInitialized) { + GameState->PixelPointer = LoadBMP(Thread, Memory->DEBUGPlatformReadEntireFile, "data/test_background.bmp"); + GameState->PlayerP.AbsTileX = 2; GameState->PlayerP.AbsTileY = 3; GameState->PlayerP.OffsetX = 5.0f; @@ -341,6 +373,16 @@ void UpdateAndRender(thread_context *Thread, game_memory *Memory, game_input *In F32 PlayerTop = ScreenCenterY - MetersToPixels*PlayerHeight; DrawRectangle(Buffer, PlayerLeft, PlayerTop, PlayerLeft + MetersToPixels*PlayerWidth, PlayerTop + MetersToPixels*PlayerHeight, PlayerR, PlayerG, PlayerB); +#if 0 + U32 *Source = GameState->PixelPointer; + U32 *Dest = (U32 *)Buffer->Memory; + for(S32 Y = 0; Y < Buffer->Height; Y++) { + for(S32 X = 0; X < Buffer->Width; X++) { + *Dest++ = *Source++; + } + } +#endif + GameOutputSound(GameState, SoundBuffer, 400); } diff --git a/handmade.h b/handmade.h index 39ea544..1f204d4 100644 --- a/handmade.h +++ b/handmade.h @@ -168,7 +168,9 @@ typedef struct world { typedef struct game_state { memory_arena WorldArena; world *World; + tile_map_position PlayerP; + U32 *PixelPointer; } game_state; #endif diff --git a/sdl_handmade.c b/sdl_handmade.c index acd1f9d..42f6de0 100644 --- a/sdl_handmade.c +++ b/sdl_handmade.c @@ -548,7 +548,7 @@ S32 main(S32 argc, char *argv[]) /* NOTE: Floating windows are not supported oficially by Wayland * protocol. However, SDL_WINDOW_ALWAYS_ON_TOP does work on KDE * under Wayland. I have not tested GNOME. */ - SDL_Window *Window = SDL_CreateWindow("Handmade Hero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, RESOLUTION_WIDTH, RESOLUTION_HEIGHT, SDL_WINDOW_RESIZABLE); + SDL_Window *Window = SDL_CreateWindow("Handmade Hero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, RESOLUTION_WIDTH+20, RESOLUTION_HEIGHT+20, SDL_WINDOW_RESIZABLE); /*SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALWAYS_ON_TOP);*/ @@ -559,6 +559,10 @@ S32 main(S32 argc, char *argv[]) SDL_Renderer *Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER_PRESENTVSYNC); SDL_SetWindowPosition(Window, (display_mode.w - RESOLUTION_WIDTH), (display_mode.h - RESOLUTION_HEIGHT)); + /* NOTE: For future reference, the custom window bar should use + * SDL_SetWindowHitTest to define areas that will be used to + * drag the window. */ + /* "Wayland needs an event loop and rendering or it won't function." * https://github.com/libsdl-org/SDL/issues/7699#issuecomment-1545684792 */ /* NOTE: This means that we need to readraw to even resize the @@ -581,8 +585,9 @@ S32 main(S32 argc, char *argv[]) GlobalRunning = TRUE; - sdl_window_dimension Dimension = SDLGetWindowDimension(Window); - SDLResizeTexture(&GlobalBackbuffer, Renderer, Dimension.Width, Dimension.Height); + //sdl_window_dimension Dimension = SDLGetWindowDimension(Window); + //SDLResizeTexture(&GlobalBackbuffer, Renderer, Dimension.Width, Dimension.Height); + SDLResizeTexture(&GlobalBackbuffer, Renderer, RESOLUTION_WIDTH, RESOLUTION_HEIGHT); sdl_sound_output SoundOutput; memset(&SoundOutput, 0, sizeof(SoundOutput));