0
votes

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;
    }
}
1
Not sure if this relates to your problem, but you should try using 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
I'll try it this afternoon when I get home. I'll let you know if it helps!Julian
That worked! I changed the flag to -1 and all is well.Julian
@Leonardo, if you put that in as an answer, I'll mark it as accepted since you technically did fix my problem.Julian
thanks! I'm glad it helped!Leonardo

1 Answers

1
votes

According to SDL_CreateRenderer documentation, you should specify -1 to its second parameter to ask for the first rendering driver supporting your requested flags. The one at index 0 might not be the correct one.