OpenGL 4.1 on Macbook pro

I can not seem to figure out what I’m doing wrong in trying to get an OpenGL 3.3 context. It returns a 2.1 compatibility context. I’ve searched google and these forums for the past two days but since I’m new to SDL, OpenGL, and C++ I’m having a real hard time. Any help would be greatly appreciated.

I get the following output for the code below: “2.1 NVIDIA-8.24.9 310.40.25f01”

#include
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>

SDL_Window *win;
SDL_Renderer *renderer;

int main(int argc, char* argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
win = SDL_CreateWindow(“test”, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
std::cout << glGetString (GL_VERSION) << std::endl;
}

Found my problem. I was creating an SDL renderer instead of the OpenGL context.

The following helped me: http://www.opengl.org/wiki/Tutorial1%3A_Creating_a_Cross_Platform_OpenGL_3.2_Context_in_SDL_(C_/_SDL)

  1. The headers are different for SDL2
  2. Need to set the SDL_GL_CONTEXT_PROFILE_MASK to SDL_GL_CONTEXT_PROFILE_CORE

The SDL_Renderer uses the older OpenGL and puts the driver into compatibility mode. Here is the minimal code to get a 3.3 OpenGL context using SDL. It doesn’t clean up after itself but this shows the steps required to get an OpenGL 3.3 context on 10.9/Mavericks. I also haven’t tried actually using any GL 3.3 calls. I suspect I may have to include OpenGL/gl3.h (for mac) instead of SDL_opengl.h. but the following code compiles and creates a 3.3 OpenGL context on my MacBook Pro retina.

#include
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>

SDL_Window *win;

int main(int argc, char* argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
win = SDL_CreateWindow(“test”, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
SDL_GLContext maincontext = SDL_GL_CreateContext(win);
std::cout << glGetString (GL_VERSION) << std::endl;
}