Added background image, TTF loading, rgb color struct
This commit is contained in:
+17
-9
@@ -6,6 +6,8 @@ const assert = std.debug.assert;
|
||||
const SCREEN_WIDTH = 640;
|
||||
const SCREEN_HEIGHT = 480;
|
||||
const log = sdl.SDL_Log;
|
||||
const GameText = @import("./text.zig").GameText;
|
||||
const RGBAColor = @import("./utils/rgb_color.zig").RGBAColor;
|
||||
|
||||
var window: *sdl.struct_SDL_Window = undefined;
|
||||
// var screen_surface: *sdl.struct_SDL_Surface = undefined;
|
||||
@@ -24,8 +26,11 @@ pub fn main() !void {
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
const texture = try atils.loadTexture(renderer, "assets/png_test.png");
|
||||
defer sdl.SDL_DestroyTexture(texture);
|
||||
const bg_texture = try atils.loadTexture(renderer, "assets/background.png");
|
||||
defer sdl.SDL_DestroyTexture(bg_texture);
|
||||
|
||||
try GameText.initFont();
|
||||
defer GameText.deinitFont();
|
||||
|
||||
// var slime_factory = try sf.SlimeFactory.init(allocator, renderer);
|
||||
// defer slime_factory.deinit();
|
||||
@@ -86,13 +91,10 @@ pub fn main() !void {
|
||||
}
|
||||
_ = sdl.SDL_SetRenderDrawColor(renderer, 0xff, 0xff, 0xff, 0xff);
|
||||
_ = sdl.SDL_RenderClear(renderer);
|
||||
std.debug.print("r:{x} g:{x} b:{x}\n", .{
|
||||
game_state.r,
|
||||
game_state.g,
|
||||
game_state.b,
|
||||
});
|
||||
|
||||
_ = sdl.SDL_RenderCopy(renderer, bg_texture, null, null);
|
||||
game_state.update_tick();
|
||||
var text = try GameText.loadFromRenderedText("Test 123", RGBAColor.whiteSmoke().tosdl());
|
||||
try text.render(&game_state);
|
||||
|
||||
// Render red rect
|
||||
// const fill_rect: sdl.struct_SDL_Rect = sdl.SDL_Rect{ .x = SCREEN_WIDTH / 4, .y = SCREEN_HEIGHT / 4, .w = SCREEN_WIDTH / 2 + img_pos.x, .h = SCREEN_HEIGHT / 2 + img_pos.y };
|
||||
@@ -105,7 +107,7 @@ pub fn main() !void {
|
||||
// _ = sdl.SDL_BlitScaled(zig_image, &src_rect, screen_surface, &dest_rect);
|
||||
|
||||
// _ = sdl.SDL_UpdateWindowSurface(window);
|
||||
sdl.SDL_Delay(117);
|
||||
sdl.SDL_Delay(100);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -138,11 +140,17 @@ fn init() !void {
|
||||
log("Unable to initialize SDL Image: %s\n", sdl.IMG_GetError());
|
||||
return error.SDLInitializationFailed;
|
||||
}
|
||||
|
||||
if (sdl.TTF_Init() < 0) {
|
||||
log("Unable to initialize SDL TTF: %s\n", sdl.TTF_GetError());
|
||||
return error.SDLInitializationFailed;
|
||||
}
|
||||
}
|
||||
|
||||
fn close() void {
|
||||
sdl.SDL_DestroyRenderer(renderer);
|
||||
sdl.SDL_DestroyWindow(window);
|
||||
sdl.IMG_Quit();
|
||||
sdl.TTF_Quit();
|
||||
sdl.SDL_Quit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user