SDL + OpenGL mutual existence in same app.


PokeParadox

Founder of Pirate Games - Penjin Coder
Staff member
Joined
Dec 8, 2005
Messages
6,603
Age
41
Location
UK
Website
pokeparadox.itch.io
WEBSITE
https://github.com/pokeparadox
YOUTUBE
pokeparadox
Hi guys,


I've been finding some time to do some more PenjinTwo coding and I finally got a way to to switch between GL and SDL rendering via config file, rather than compile-time only...


There is one issue though, in that it doesn't bloody work!


Basically my initialisation path looks fine it takes the correct steps in initialising a GL window with SDL. I switch the config to SDL rendering only and that's when something is wrong, it creates a 0 pixel wide window... anyone have any ideas on what I could be missing? Not yet tried to extend this to GLES and Pandora, but this is the eventual goal.


EDIT: just to clarify... anyone know of any "gotchas" I may not be aware of, I know I haven't provided any source...
 
Last edited by a moderator:
Yeah that's why I'm looking for something strange or silly. I have a Renderer_SDL and RendererGL and the correct init of these classes get called and set the SDL_OPENGL correctly... the main problem I think is the window not being created properly... I guess it's rendering SDL stuff properly but hard to tell on a 0 pixel wide window...

I'm wondering if something is done in SDL_opengl.h or by linking the GL libs that needs working around?

 
Sticking to just OpenGL will probably make your life a lot easier. You can easily change from 2D to 3D rendering in OpenGL, without the overhead of tearing down and initializing a new window.
 
Well I don't really want to change the renderer mid run-time, basically at initialisation only.


But it seems it's not easily possible, this means I'll have to restructure my rendering hierarchy.
 
I suspect there is an issue with SDL or GLX if you cant get a window with adding SDL_OPENGL. I dont see how any restructing would change anything. It all comes down to the SetVideoMode call and either you get the window or you dont.
 
Pickle if I compile for SDL+GL I can open a GL window fine. The problem is when I set my config to initialise purely SDL with this GL enabled build.


It creates a 0 pixel wide window and I have no clue why. Debugging it step by step and it takes the same init path it would take if I hadn't allowed the possibility to switch to a GL renderer...


PS: Pickle you are a god... wave a magic wand and fix it with just pure awesomesauce :p
 
Last edited by a moderator:
Pickle if I compile for SDL+GL I can open a GL window fine. The problem is when I set my config to initialise purely SDL with this GL enabled build.


It creates a 0 pixel wide window and I have no clue why. Debugging it step by step and it takes the same init path it would take if I hadn't allowed the possibility to switch to a GL renderer...


PS: Pickle you are a god... wave a magic wand and fix it with just pure awesomesauce :p

Well even small mortals like me require source :p Is this public somewhere?
 
Ok i found pengin2 and im looking at


void RendererGL_2d::applyVideoSettings()



Code:
	    flags = SDL_OPENGL;

	    SDL_Surface* screen = NULL;


    if(fullScreen)

	    flags = flags | SDL_FULLSCREEN;

    if(bpp == 0 || !(bpp == 8 || bpp == 16 || bpp == 32))

	    bpp = info->vfmt->BitsPerPixel;


	    screen = SDL_SetVideoMode(resolution.x, resolution.y, bpp, flags);

	    if(screen  == NULL )

		    Penjin::ErrorMan::getInstance()->forceQuit(PENJIN_SDL_SETVIDEOMODE_FAILED, "RendererGL_2d::applyVideoSettings()");

	    else

	    {

		    resolution.x = screen->w;

		    resolution.y = screen->h;

	    }


Do you really want to let screen be local to the function? I know you dont really need the reference, but doesnt seem good to do.


Also based on some other code it appears you might let resolution.x and resolution.y be 0 for auto sizing. Are you sending 0 and maybe SDL_OPENGL doesnt support autosizing? Have you tried fixed numbers?
 
Well caught. I don't know if it will help my issues, but it doesn't hurt to get rid of issues like this.


Now the GL renderer uses the inherited screen variable form the SDL renderer.


And the 0 for auto size is working. I get a properly created OpenGL window. The problem is when I want to open an SDL window when I have built for dual-mode support!


I'm hoping that the screen variable was becoming confused and this is the root of the problem, thanks Pickle for taking some time to look into it! :)


Ok... now I have corrected the local variable and indeed I get a 320x240 window in SDL mode and a full desktop 1280x720 window for GL. Great so far, apart from the GL resolution is wrong, I can investigate it...


BUT! Nothing is rendering in either window... boo :(
 
Last edited by a moderator:
So it sounds like you have multiple calls to SetVideoModes? Like you call for SDL_SWSURFACE and then later call with SDL_OPENGL?


Or is it one call based on the config?
 
Back
Top