| 1 | /*
|
|---|
| 2 | * Copyright (C) 2017 The Contributors
|
|---|
| 3 | *
|
|---|
| 4 | * This program is free software: you can redistribute it and/or modify
|
|---|
| 5 | * it under the terms of the GNU General Public License as published by
|
|---|
| 6 | * the Free Software Foundation, either version 3 of the License, or (at
|
|---|
| 7 | * your option) any later version.
|
|---|
| 8 | *
|
|---|
| 9 | * This program is distributed in the hope that it will be useful, but
|
|---|
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 12 | * General Public License for more details.
|
|---|
| 13 | *
|
|---|
| 14 | * A copy of the GNU General Public License can be found in the file
|
|---|
| 15 | * "gpl.txt" in the top directory of this repository.
|
|---|
| 16 | */
|
|---|
| 17 |
|
|---|
| 18 | #include <all.h>
|
|---|
| 19 |
|
|---|
| 20 | int32_t sdl_verbose = false;
|
|---|
| 21 |
|
|---|
| 22 | #define ver(...) _ver(sdl_verbose, 0, __VA_ARGS__)
|
|---|
| 23 | #define ver2(...) _ver(sdl_verbose, 1, __VA_ARGS__)
|
|---|
| 24 | #define ver3(...) _ver(sdl_verbose, 2, __VA_ARGS__)
|
|---|
| 25 |
|
|---|
| 26 | SDL_Window *sdl_win;
|
|---|
| 27 | SDL_Renderer *sdl_ren;
|
|---|
| 28 |
|
|---|
| 29 | void sdl_init(void)
|
|---|
| 30 | {
|
|---|
| 31 | if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) < 0) {
|
|---|
| 32 | fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
|
|---|
| 33 | exit(1);
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_VERBOSE);
|
|---|
| 37 |
|
|---|
| 38 | if (TTF_Init() < 0) {
|
|---|
| 39 | fail("TTF_Init() failed: %s", TTF_GetError());
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1");
|
|---|
| 43 |
|
|---|
| 44 | sdl_win = SDL_CreateWindow("Emu", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
|---|
| 45 | WIN_W, WIN_H, 0);
|
|---|
| 46 |
|
|---|
| 47 | if (sdl_win == NULL) {
|
|---|
| 48 | fail("SDL_CreateWindow() failed: %s", SDL_GetError());
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | sdl_ren = SDL_CreateRenderer(sdl_win, -1, 0);
|
|---|
| 52 |
|
|---|
| 53 | if (sdl_ren == NULL) {
|
|---|
| 54 | fail("SDL_CreateRenderer() failed: %s", SDL_GetError());
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | SDL_StartTextInput();
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | void sdl_quit(void)
|
|---|
| 61 | {
|
|---|
| 62 | SDL_DestroyRenderer(sdl_ren);
|
|---|
| 63 | SDL_DestroyWindow(sdl_win);
|
|---|
| 64 | TTF_Quit();
|
|---|
| 65 | SDL_Quit();
|
|---|
| 66 | }
|
|---|