Question

I am fairly new to SDL and I am trying to only use version 2.0. I believe that in previouse versions of SDL (1.2 and 1.3) creating a window was done with SDL_SetVideoMode, however that has since been droped source. So how do you create a window for rendering 3D OpenGL 3.0+ with SDL 2.0? (with a programmable pipeline of course)

My first gess was SDL_CreatWindow then SDL_GetWindowSurface then SDL_CreateRenderer as the code below:

    SDL_Window*   window   = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
    SDL_Surface*  s        = SDL_GetWindowSurface(window);
    SDL_Renderer* renderer = SDL_CreateRenderer(window,  -1, flags);
    SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);

However, the documentation on SDL_GetWindowSurface says that it cannot be used for "3D or the rendering API on this window" source.

Is there some other way to render 3D OpenGL 3.0+ in SDL 2.0, or should I just use SDL 1.2 because SDL 2.0 is only in Release Candidate status?

Was it helpful?

Solution

Try using SDL_GL_SetAttribute() before you create your window:

SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 3 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 2 );
//SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE ); 
SDL_Window* window = SDL_CreateWindow( ... );
SDL_GLContext ctx = SDL_GL_CreateContext( window );
SDL_GL_MakeCurrent( window, ctx );
glewExperimental = true;
glewInit();
...

Though I wouldn't use the SDL_Renderer stuff if you create a Core context.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top