rev: 21c5e6d2f665d0e8b4ff917a51b664c895dab2ed tukan/testing/test_sdl.sc -rw-r--r-- 2.2 KiB View raw Log this file
21c5e6d2f665 — Leonard Ritter * renamed project from Liminal to Tukan 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using import ..tukan.sdl

fn main (argc argv)
    var context = (nullof SDL_GLContext)
    var window = (nullof (pointer SDL_Window 'mutable))

    fn option (default value)
        if (none? value) default
        else value

    fn init (opts...)
        SDL_Init SDL_INIT_AUDIO

        SDL_GL_SetAttribute SDL_GL_DOUBLEBUFFER 1

        SDL_GL_SetAttribute SDL_GL_STENCIL_SIZE 8
        SDL_GL_SetAttribute SDL_GL_DEPTH_SIZE 24

        SDL_GL_SetAttribute SDL_GL_CONTEXT_MAJOR_VERSION 4
        SDL_GL_SetAttribute SDL_GL_CONTEXT_MINOR_VERSION 5
        #if IS_OSX
            SDL_GL_SetAttribute
                SDL_GL_CONTEXT_PROFILE_MASK
                SDL_GL_CONTEXT_PROFILE_CORE

        let resizable = (option false (va@ 'resizable opts...))

        window =
            SDL_CreateWindow
                option "OpenGL" (va@ 'title opts...)
                SDL_WINDOWPOS_UNDEFINED
                SDL_WINDOWPOS_UNDEFINED
                option 640 (va@ 'width opts...)
                option 480 (va@ 'height opts...)
                | SDL_WINDOW_OPENGL
                    SDL_WINDOW_SHOWN
                    ? resizable (u32 SDL_WINDOW_RESIZABLE) 0:u32

        context = (SDL_GL_CreateContext window)
        SDL_GL_SetSwapInterval 1
        SDL_GL_MakeCurrent window context

    fn window-size ()
        var w = 0
        var h = 0
        SDL_GetWindowSize window w h
        return w h

    fn shutdown ()
        SDL_GL_DeleteContext context
        SDL_DestroyWindow window

        SDL_Quit;

    fn swap ()
        SDL_GL_SwapWindow window

    var quit = false
    fn handle_events ()
        var event = (SDL_Event)
        while ((SDL_PollEvent event) != 0)
            if (event.type == SDL_QUIT)
                quit = true

    fn loop ()
        while (not quit)
            handle_events;
            swap;

    init
        title = "Tukan"
        width = 800
        height = 600
        resizable = true

    loop;

    shutdown;
    return 0

if true
    main;
else
    let main = (typify main i32 (pointer rawstring))
    compile-object
        module-dir .. "/test_sdl.o"
        scopeof
            main = main
        'dump-module