I set up SDL2 on the raspberry pi using the resources from this tutorial: https://www.youtube.com/watch?v=Yo7hO7GZ-ug I got it to compile and run. But when it reaches the point where it needs to setup the renderer, I get a NULL return value.
The accepted answer on this question suggests that the error "OpenGL context already created" is deceiving and that the OpenGL context hasn't been created at all. This would mean that my OpenGL is broken. The Raspberry Pi uses OpenGL ES and from what I understand, SDL is smart enough to use GLES instead of GL? I'm wondering if anyone else has had this kind of issue and if there's a known way to fix it.
This is my code:
#include <SDL2/SDL.h>
const char* WINDOW_TITLE = "steel";
int main(int argc, char** argv) {
SDL_Window* window = NULL;
SDL_Renderer* renderer = NULL;
SDL_Init(SDL_INIT_EVERYTHING);
// Setup window
window = SDL_CreateWindow(
WINDOW_TITLE, //Title
SDL_WINDOWPOS_CENTERED, // x pos
SDL_WINDOWPOS_CENTERED, // y pos
0, //width
0, //height
SDL_WINDOW_FULLSCREEN_DESKTOP);
if (window == NULL) {
printf("Could not create window %s\n", SDL_GetError());
return 1;
}
// Setup renderer
renderer = SDL_CreateRenderer(window, 0, 0);
if (renderer == NULL) {
printf("Could not create renderer %s\n", SDL_GetError());
return 1;
}
}
SDL_CreateRenderer(window, -1, 0)
, as the doc states if you pass -1 it will try the first rendering driver which supports your requested flags. The one at index 0 might not be the correct one. This comment is just a longshot :P I dont have a Pi to actually test it. – Leonardo