Przeglądaj źródła

Add some more comments

Luna Stadler 4 lat temu
rodzic
commit
63e774b2f6
1 zmienionych plików z 7 dodań i 0 usunięć
  1. 7 0
      c/sdl/hello_sdl.zig

+ 7 - 0
c/sdl/hello_sdl.zig

5
// Resources:
5
// Resources:
6
// - http://wiki.libsdl.org/CategoryAPI
6
// - http://wiki.libsdl.org/CategoryAPI
7
// - https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html
7
// - https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html
8
//
9
// Unrelatedly, https://ziglang.org/learn/samples/ lead me to
10
// raylib, which looks like a really neat library to get started with
11
// game programming without Godot or Unity:
12
// https://github.com/raysan5/raylib
8
const c = @cImport({
13
const c = @cImport({
9
    @cInclude("SDL2/SDL.h");
14
    @cInclude("SDL2/SDL.h");
10
    @cInclude("SDL2/SDL_ttf.h");
15
    @cInclude("SDL2/SDL_ttf.h");
71
        // thanks to https://stackoverflow.com/questions/22886500/how-to-render-text-in-sdl2 for some actually useful code here
76
        // thanks to https://stackoverflow.com/questions/22886500/how-to-render-text-in-sdl2 for some actually useful code here
72
        const white: c.SDL_Color = c.SDL_Color{ .r = 255, .g = 255, .b = 255, .a = 255 };
77
        const white: c.SDL_Color = c.SDL_Color{ .r = 255, .g = 255, .b = 255, .a = 255 };
73
        const black: c.SDL_Color = c.SDL_Color{ .r = 0, .g = 0, .b = 0, .a = 255 };
78
        const black: c.SDL_Color = c.SDL_Color{ .r = 0, .g = 0, .b = 0, .a = 255 };
79
        // Shaded vs Solid gives a nicer output, with solid the output
80
        // was squiggly and not aligned with a baseline.
74
        const text = c.TTF_RenderUTF8_Shaded(font, msg, white, black);
81
        const text = c.TTF_RenderUTF8_Shaded(font, msg, white, black);
75
        _ = c.SDL_BlitSurface(text, null, surface, null);
82
        _ = c.SDL_BlitSurface(text, null, surface, null);
76
83