rev: 3827f53bae88e48a594610914ba74b9512ead6dd tukan/testing/test_sdl.sc -rw-r--r-- 2.2 KiB View raw Log this file
3827f53bae88 — Leonard Ritter * more work on module system 3 months 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
using import ..tukan.sdl
using import ..tukan.gl

fn main ()
    global context = (nullof SDL_GLContext)
    global window = (nullof (mutable pointer SDL_Window))

    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 = (va-option resizable opts... false)

        window =
            SDL_CreateWindow
                va-option title opts... "OpenGL"
                SDL_WINDOWPOS_UNDEFINED
                SDL_WINDOWPOS_UNDEFINED
                va-option width opts... 640
                va-option height opts... 480
                | 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 ()
        local w = 0
        local h = 0
        SDL_GetWindowSize window &w &h
        return (deref w) (deref h)

    fn shutdown ()
        SDL_GL_DeleteContext context
        SDL_DestroyWindow window

        SDL_Quit;

    fn swap ()
        SDL_GL_SwapWindow window

    global quit = false
    fn handle_events ()
        local 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

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