Day 36 complete.
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 2.3 MiB |
+42
@@ -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)
|
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;
|
GameState = (game_state *)Memory->PermanentStorage;
|
||||||
if(!Memory->IsInitialized) {
|
if(!Memory->IsInitialized) {
|
||||||
|
GameState->PixelPointer = LoadBMP(Thread, Memory->DEBUGPlatformReadEntireFile, "data/test_background.bmp");
|
||||||
|
|
||||||
GameState->PlayerP.AbsTileX = 2;
|
GameState->PlayerP.AbsTileX = 2;
|
||||||
GameState->PlayerP.AbsTileY = 3;
|
GameState->PlayerP.AbsTileY = 3;
|
||||||
GameState->PlayerP.OffsetX = 5.0f;
|
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;
|
F32 PlayerTop = ScreenCenterY - MetersToPixels*PlayerHeight;
|
||||||
DrawRectangle(Buffer, PlayerLeft, PlayerTop, PlayerLeft + MetersToPixels*PlayerWidth, PlayerTop + MetersToPixels*PlayerHeight, PlayerR, PlayerG, PlayerB);
|
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);
|
GameOutputSound(GameState, SoundBuffer, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -168,7 +168,9 @@ typedef struct world {
|
|||||||
typedef struct game_state {
|
typedef struct game_state {
|
||||||
memory_arena WorldArena;
|
memory_arena WorldArena;
|
||||||
world *World;
|
world *World;
|
||||||
|
|
||||||
tile_map_position PlayerP;
|
tile_map_position PlayerP;
|
||||||
|
U32 *PixelPointer;
|
||||||
} game_state;
|
} game_state;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+8
-3
@@ -548,7 +548,7 @@ S32 main(S32 argc, char *argv[])
|
|||||||
/* NOTE: Floating windows are not supported oficially by Wayland
|
/* NOTE: Floating windows are not supported oficially by Wayland
|
||||||
* protocol. However, SDL_WINDOW_ALWAYS_ON_TOP does work on KDE
|
* protocol. However, SDL_WINDOW_ALWAYS_ON_TOP does work on KDE
|
||||||
* under Wayland. I have not tested GNOME. */
|
* 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_RESIZABLE |
|
||||||
SDL_WINDOW_ALWAYS_ON_TOP);*/
|
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_Renderer *Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER_PRESENTVSYNC);
|
||||||
SDL_SetWindowPosition(Window, (display_mode.w - RESOLUTION_WIDTH), (display_mode.h - RESOLUTION_HEIGHT));
|
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."
|
/* "Wayland needs an event loop and rendering or it won't function."
|
||||||
* https://github.com/libsdl-org/SDL/issues/7699#issuecomment-1545684792 */
|
* https://github.com/libsdl-org/SDL/issues/7699#issuecomment-1545684792 */
|
||||||
/* NOTE: This means that we need to readraw to even resize the
|
/* NOTE: This means that we need to readraw to even resize the
|
||||||
@@ -581,8 +585,9 @@ S32 main(S32 argc, char *argv[])
|
|||||||
|
|
||||||
GlobalRunning = TRUE;
|
GlobalRunning = TRUE;
|
||||||
|
|
||||||
sdl_window_dimension Dimension = SDLGetWindowDimension(Window);
|
//sdl_window_dimension Dimension = SDLGetWindowDimension(Window);
|
||||||
SDLResizeTexture(&GlobalBackbuffer, Renderer, Dimension.Width, Dimension.Height);
|
//SDLResizeTexture(&GlobalBackbuffer, Renderer, Dimension.Width, Dimension.Height);
|
||||||
|
SDLResizeTexture(&GlobalBackbuffer, Renderer, RESOLUTION_WIDTH, RESOLUTION_HEIGHT);
|
||||||
|
|
||||||
sdl_sound_output SoundOutput;
|
sdl_sound_output SoundOutput;
|
||||||
memset(&SoundOutput, 0, sizeof(SoundOutput));
|
memset(&SoundOutput, 0, sizeof(SoundOutput));
|
||||||
|
|||||||
Reference in New Issue
Block a user