Drawing OpenGL graphics on Cairo surface using SDL.

Hello everyone, I’m writting a GUI library in C++, I’m using Cairo to draw the graphics, and SDL2 for window creation and events handling.

To send the graphics to the window, I create a cairo surface with the data from the SDL window surface.

Here the related code:


SDL_Surface *win_surface = SDL_GetWindowSurface( window );

// surface creation
cairo_surface_t *cr_surface = cairo_image_surface_create_for_data
(
static_cast <unsigned char *> ( win_surface->pixels ),
CAIRO_FORMAT_RGB24,
win_surface->w,
win_surface->h,
win_surface->pitch
);

SDL_UpdateWindowSurface( window ); // In my render loop

I want to code a widget in my Cairo/SDL2 GUI to render 3D graphics using OpenGL. (I want create a 3D canvas widget, no to use Cairo with GPU acceleration).

Can someone help me with this? I have no idea how to proceed to create a drawing area for GL graphics and paint on it using GL functions.

Thanks,

Alberto.