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
|
// SPDX-License-Identifier: GPL-2.0-or-later
/* SPDX-FileCopyrightText: 2004-2015 Simon Wunderlich <sw@simonwunderlich.de>
*/
#include "global.h"
int aa_level = 4;
#include <SDL3/SDL.h>
#include <GL/gl.h>
int SDLFlags = 0; /* some flags for SDL */
SDL_Window *sdl_window;
int graphics_init_sdl(void)
{
SDL_GLContext glcontext;
int buffers, samples;
s3dprintf(MED, "Using SDL driver ...");
if (!SDL_Init(SDL_INIT_VIDEO))
errsf("SDL_Init()", SDL_GetError());
SDLFlags = SDL_WINDOW_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_WINDOW_RESIZABLE;
sdl_window = NULL;
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
do {
if (sdl_window)
SDL_DestroyWindow(sdl_window);
if (aa_level > 0) {
if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1))
s3dprintf(VHIGH, "error initializing multisampling");
if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, aa_level))
s3dprintf(VHIGH, "no multisampling available");
}
sdl_window = SDL_CreateWindow("S3D", X_RES, Y_RES,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
if (!sdl_window)
errs("SDL_CreateWindow()", SDL_GetError());
/* more opengl-init-stuff */
glcontext = SDL_GL_CreateContext(sdl_window);
if (!glcontext) {
if (aa_level > 0) {
s3dprintf(MED, "retry without multisampling");
aa_level = 0;
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
} else {
errsf("SDL_GL_CreateContext()", SDL_GetError());
}
}
} while (!glcontext);
if (aa_level > 0) {
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &buffers);
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &samples);
s3dprintf(LOW, "Buffers: %d Samples: %d", buffers, samples);
}
/* print some information */
s3dprintf(VLOW, "Vendor : %s", glGetString(GL_VENDOR));
s3dprintf(VLOW, "Renderer : %s", glGetString(GL_RENDERER));
s3dprintf(VLOW, "Version : %s", glGetString(GL_VERSION));
s3dprintf(VLOW, "Extensions : %s", glGetString(GL_EXTENSIONS));
graphics_reshape(X_RES, Y_RES);
return 0;
}
int graphics_quit_sdl(void)
{
SDL_Quit();
return 0;
}
|