src/ascension/window.h

Wed, 01 Nov 2023 20:09:49 +0100

author
Mike Becker <universe@uap-core.de>
date
Wed, 01 Nov 2023 20:09:49 +0100
changeset 6
302971e8599b
parent 3
src/ascension/core.h@1efd6da2ad53
child 7
9dd76cbd6c90
permissions
-rw-r--r--

move window related stuff to its own unit

     1 /*
     2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3  * Copyright 2023 Mike Becker. All rights reserved.
     4  *
     5  * Redistribution and use in source and binary forms, with or without
     6  * modification, are permitted provided that the following conditions are met:
     7  *
     8  *   1. Redistributions of source code must retain the above copyright
     9  *      notice, this list of conditions and the following disclaimer.
    10  *
    11  *   2. Redistributions in binary form must reproduce the above copyright
    12  *      notice, this list of conditions and the following disclaimer in the
    13  *      documentation and/or other materials provided with the distribution.
    14  *
    15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    25  * POSSIBILITY OF SUCH DAMAGE.
    26  */
    28 #ifndef ASCENSION_WINDOW_H
    29 #define ASCENSION_WINDOW_H
    31 #include <SDL2/SDL.h>
    33 #include "core.h"
    35 #ifdef __cplusplus
    36 extern "C" {
    37 #endif
    39 typedef struct AscWindowSettings {
    40     int depth_size;
    41     int vsync;
    42     asc_vec2i dimensions;
    43     int fullscreen;
    44     int gl_major_version;
    45     int gl_minor_version;
    46     char const* title;
    47 } AscWindowSettings;
    49 typedef struct AscWindow {
    50     SDL_Window* window;
    51     SDL_GLContext glctx;
    52     Uint32 id;
    53     asc_vec2i dimensions;
    54 } AscWindow;
    57 /**
    58  * Dispatches events and synchronizes all initialized windows.
    59  *
    60  * @return false, if one of the events is a QUIT event, true otherwise
    61  */
    62 bool asc_loop_next(void);
    64 /**
    65  * Initializes the settings structure with default values.
    66  *
    67  * @param settings an uninitialized settings object
    68  */
    69 void asc_window_settings_init_defaults(AscWindowSettings* settings);
    71 /**
    72  * Creates and initializes a new window and a corresponding OpenGL context.
    73  *
    74  * @param window the window structure
    75  * @param settings the settings to be used for initialization
    76  */
    77 void asc_window_initialize(AscWindow* window, AscWindowSettings const* settings);
    79 /**
    80  * Destroys the window and its OpenGL context.
    81  *
    82  * Still alive windows will also be destroyed by asc_context_destroy()
    83  * automatically.
    84  *
    85  * @param window the window
    86  */
    87 void asc_window_destroy(AscWindow* window);
    89 /**
    90  * Swaps buffers and adjusts the viewport to the current window size.
    91  *
    92  * This function is automatically invoked for all initialized windows
    93  * by asc_loop_next(). You usually do not need to call this function manually.
    94  *
    95  * @param window the window
    96  */
    97 void asc_window_sync(AscWindow const *window);
    99 #ifdef __cplusplus
   100 } // extern "C"
   101 #endif
   103 #endif /* ASCENSION_WINDOW_H */

mercurial