Advertisement Jump to content
Sign in to follow this  
SteveDeFact0

OpenGL SDL2 Context with many windows.

This topic is 1698 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need to share resources between many different windows. This was relatively easy when I was using a beta version of SDL2 but they changed something that completely broke my graphics pipeline. No matter what I have tried I can't get it to work again.

I create my base context like this:

    // Initialize SDL
    SDL_Init(SDL_INIT_VIDEO);
    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
    SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );
    SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
    SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
    SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
    SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );
    SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 8 );
    SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 3 );
    SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 );
    contextWindow = SDL_CreateWindow( "ContextWindow", 0, 0, 0, 0, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN );
    glContext = SDL_GL_CreateContext( contextWindow );
    if(!glContext)
    {
        fprintf( stderr, "Error: %s\n", "Could not create GL Context." );
    }

I then create my windows like this:

    sdlWindow = SDL_CreateWindow( name.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,  width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE );
    SDL_GL_MakeCurrent(context->contextWindow, context->glContext);
    SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
    windowContext = SDL_GL_CreateContext(sdlWindow);
    SDL_GL_MakeCurrent(sdlWindow, windowContext);
    glDisable(GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable (GL_CULL_FACE);

I didn't have to create a context for each window when I was using an old beta version of SDL2 but I think the reason nothing is rendering is that I have to created contexts which share with the base context and were created with that window.

 

I create my textures and buffers by making current the base context with NULL for the window. The reason I use NULL is that when I use the base hidden window, it renders hash but if I use NULL it just render white as if the texture is empty(Not sure if that is better or worse...)

 

Then I render the scene by making current the child window and the child context. This allows me to render polygons with colors but all my textures are blank like the contexts are not really sharing with the base context. I don't know what else to do to get this working?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!