-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Milestone
Description
Tools:
- Windows 10
- MinGW GCC 11.2
- Asus K53SV (2011) - It has two video cards: Intel 3000 (OpenGL 3.1) and GeForce 540M (OpenGL 4.6)
- SDL 3.3.6
The following example works well with SDL 3.2.28 but does not work with SDL 3.3.6:
main.c
#define SDL_MAIN_USE_CALLBACKS 1
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <stdio.h>
#include <glad/glad.h>
static SDL_Window *window = NULL;
static SDL_GLContext glContext = NULL;
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
{
(void)appstate; (void)argc; (void)argv;
if (!SDL_Init(SDL_INIT_VIDEO))
{
SDL_Log("SDL_Init failed: %s", SDL_GetError());
return SDL_APP_FAILURE;
}
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); // Enable MULTISAMPLE
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2); // Can be 2, 4, 8 or 16
window = SDL_CreateWindow("OpenGL Version", 250, 250, SDL_WINDOW_OPENGL);
if (!window)
{
SDL_Log("SDL_CreateWindow failed: %s", SDL_GetError());
SDL_Quit();
return SDL_APP_FAILURE;
}
glContext = SDL_GL_CreateContext(window);
if (!glContext)
{
SDL_Log("SDL_GL_CreateContext failed: %s", SDL_GetError());
SDL_DestroyWindow(window);
SDL_Quit();
return SDL_APP_FAILURE;
}
SDL_GL_SetSwapInterval(1); // Turn on vertical sync
if (!gladLoadGL())
{
SDL_Log("Failed to initialize OpenGL function pointers");
return SDL_APP_FAILURE;
}
glClearColor(0.2f, 0.5f, 0.3f, 1.0f);
// Print SDL versions
printf("Compiled SDL3 version: %d.%d.%d\n",
SDL_MAJOR_VERSION,
SDL_MINOR_VERSION,
SDL_MICRO_VERSION);
// Get the version of the SDL library linked at runtime
int v = SDL_GetVersion();
printf("Linked SDL3 version: %d.%d.%d\n", SDL_VERSIONNUM_MAJOR(v),
SDL_VERSIONNUM_MINOR(v), SDL_VERSIONNUM_MICRO(v));
const char *glVersion = (const char *)glGetString(GL_VERSION);
printf("OpenGL version: %s\n", glVersion);
return SDL_APP_CONTINUE;
}
SDL_AppResult SDL_AppIterate(void *appstate)
{
(void)appstate;
glClear(GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow(window);
return SDL_APP_CONTINUE;
}
SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
{
(void)appstate;
if (!event)
return SDL_APP_CONTINUE;
if (event->type == SDL_EVENT_QUIT)
return SDL_APP_SUCCESS;
return SDL_APP_CONTINUE;
}
void SDL_AppQuit(void *appstate, SDL_AppResult result)
{
(void)appstate; (void)result;
if (glContext)
SDL_GL_DestroyContext(glContext);
if (window)
SDL_DestroyWindow(window);
SDL_Quit();
}I have built EXE with SDL 3.3.6 and replaced SDL3.dll (3.2.28 and 3.3.6) for testing. If you have an old laptop with two video cards (integrated and discrete) you can test it:
3.2.28
It works as expected with SDL3.dll v3.2.28:
opengl-version-sdl-3.2.28-c-exe.zip
3.3.6
It does not work as expected with SDL3.dll v3.3.6:
opengl-version-sdl-3.3.6-c-exe.zip
How to run the SDL 3.3.6 version on a laptop with two video cards:
1. Use this option:
2. Or add this code at the beginning of the main.c file:
__declspec(dllexport) unsigned long NvOptimusEnablement = 1;
__declspec(dllexport) unsigned long AmdPowerXpressRequestHighPerformance = 1;Note. The first line is for GeForce. The second line is for Radeon. You can copy both - one of them will be ignored.
Metadata
Metadata
Assignees
Labels
No labels