Reputation: 13
I am trying to learn openGL with SDL. my program works fine on my computer at home, but on computers from my school it doesn't work. to be more specific, it doesn't work on a specific model of computer at my school, the OptiPlex 9030 AIO . when i call the function SDL_GL_CreateContext(), it returns null meaning that it failed. my question is why and how can i fix it? I have been trying to figure out for the last few days and I just don't get it. the only thing i think that could be causing this issues is that the computers it doesn't work for all use the intel hd 4000 gpu.
the output from SDL_GetError() is that the operation completed successfully.
i am using the latest version of SDL2 developer libs for visual studios and openGL 4.5.
here is my code
this->window = NULL;
// Initialize SDL
if (SDL_Init(SDL_INIT_VIDEO) < 0)
sdl_die("Couldn't initialize SDL");
atexit(SDL_Quit);
SDL_GL_LoadLibrary(NULL); // Default OpenGL is fine.
// Request an OpenGL 4.5 context (should be core)
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5);
// Also request a depth buffer
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
// Request a debug context.
SDL_GL_SetAttribute(
SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG
);
// Create the window
if (SCREEN_FULLSCREEN) {
this->window = SDL_CreateWindow(
caption,
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
0, 0, SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_OPENGL
);
}
else {
this->window = SDL_CreateWindow(
caption,
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL
);
}
if (this->window == NULL) sdl_die("Couldn't set video mode");
//not working code
this->maincontext = SDL_GL_CreateContext(this->window);
if (maincontext == NULL)
sdl_die("Failed to create OpenGL context");
// Check OpenGL properties
printf("OpenGL loaded\n");
gladLoadGLLoader(SDL_GL_GetProcAddress);
printf("Vendor: %s\n", glGetString(GL_VENDOR));
printf("Renderer: %s\n", glGetString(GL_RENDERER));
printf("Version: %s\n", glGetString(GL_VERSION));
// Enable the debug callback
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageCallback(this->openglCallbackFunction, nullptr);
glDebugMessageControl(
GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, true
);
// Use v-sync
SDL_GL_SetSwapInterval(1);
// Disable depth test and face culling.
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
int w, h;
SDL_GetWindowSize(this->window, &w, &h);
glViewport(0, 0, w, h);
glClearColor(0.0f, 0.5f, 1.0f, 0.0f);
my code for sdl_die() which also gives error info is
void sdl_die(const char * message)
{
fprintf(stderr, "%s: %s\n", message, SDL_GetError());
exit(2);
}
thanks in advance.
Upvotes: 1
Views: 3616
Reputation: 2833
The code looks ok for me so you should check if the current installed GPU supports your requetsed OpenGL-Version 4.5. You can use a Caps-Viewer to check this ( you can find one here for instance: [GL-CapsViewer 1 ). If not: make sure that the latest driver for the GPU is installed and check if the GPU provides support for your requested OpenGL-Version.
If this is not supported try to reduce the version for instance to 3.1.
Upvotes: 1