Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


SDL2 Context with many windows.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 SteveDeFact0   Members   -  Reputation: 152

Like
0Likes
Like

Posted 25 May 2014 - 12:31 AM

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?



Sponsor:

#2 SteveDeFact0   Members   -  Reputation: 152

Like
0Likes
Like

Posted 28 May 2014 - 07:50 PM

Does anyone have an idea why this doesn't work?






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS