Page 1 of 2 12 LastLast
Results 1 to 20 of 29

Thread: Switching to fullscreen on the fly

  1. #1
    Lesser Knight
    Join Date
    Jul 2011
    Posts
    57

    Default Switching to fullscreen on the fly

    Hello,
    Is there any way to switch to fullscreen mode and back to windowed mode on the fly?
    I couldn't find any methods in the current implementation. And ClanLib doesn't allow me to destroy and recreate window.

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Tests/Display/FullScreen does this

    The trick is to create the new window whilst the old one exists, that way any loaded graphics are still valid.

    http://clanlib.org/wiki/MainDocs:Por...lanLib_1.0_API <--- is helpful for fullscreen mode

  3. #3
    Lesser Knight
    Join Date
    Jul 2011
    Posts
    57

    Default

    I've tried to do it as in Tests/Display/FullScreen but every time I try to use new window's gc I get an exception thrown that Object was disposed.
    I don't quite understand what does it means and what to do to prevent it.

  4. #4
    Lesser Knight
    Join Date
    Jul 2011
    Posts
    57

    Default

    I think the question now - how to get a correct gc from newly created window?

  5. #5
    Lesser Knight
    Join Date
    Jul 2011
    Posts
    57

    Default

    I've got it working, at last.
    Strange ,when I create window like this:

    Code:
    app.h:
    CL_DisplayWindow window;
    Code:
    app.cpp:
    window = CL_DisplayWindow(desc);
    SwitchFullscreen();
    
    ...
    
    App::SwitchFullscreen()
    {
    desc.set_fullscreen(true);
    window = CL_DisplayWindow(desc);
    }
    It is working until I try to get gc from window. After that I get disposable object exception.
    But if I create window like this:
    Code:
    app.cpp:
    CL_DisplayWindow window(desc);
    SwitchFullscreen(window);
    
    ...
    
    App::SwitchFullscreen(CL_DisplayWindow &win)
    {
    desc.set_fullscreen(true);
    win = CL_DisplayWindow(desc);
    }
    All working perfectly. I can get correct gc after every fullscreen/window mode switch.

  6. #6
    Lesser Knight
    Join Date
    Jul 2011
    Posts
    57

    Default

    Damn, I was too fast, it's still not working. Only worked at the very beginning with no graphic objects.
    When triying to reset window in the midst of the rendering process it is crashing with unhandled exception.
    Seems like there is no way to make fullscreen change on the fly at the current moment, after all.

  7. #7
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    ClanLib roughly has two different types of classes: normal classes that copy themselves with the copy constructor and then handle objects.

    The handle objects are used for resources that aren't trivially copied (files, textures, buffer objects, XML DOM objects). You can recognize the handle classes when they only contain a CL_SharedPtr member. A handle object can become disposed if the resource it uses has been destroyed (CL_DisposableObject is the interface for this feature). An object typically becomes disposed when a "parent" object it depends upon gets destroyed. CL_DomDocument disposes all CL_DomElement children and when CL_DisplayWindow is destroyed any CL_GraphicContext rendering to it is disposed.

    What this means is that once you destroy the old CL_DisplayWindow, then any CL_GraphicContext object using it immediately becomes disposed and any calls to them raises an "object is disposed" exception (or in the less resilient parts of the library the thing just crashes).

    To make the fullscreen feature work you must first create the new display window and then destroy the old one. This ensures that all OpenGL shareable objects are transferred (textures, etc). However the original CL_GraphicContext for the old window is no longer valid and your code must now fetch a new graphic context from the new window and use it for any subsequent rendering.

  8. #8
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    I do it as follows:

    CL_DisplayWindow window(...);

    CL_DisplayWindow window_new(...);

    (so both windows exist at the same time)

    window = window_new;

    (the old window is destroyed after the new window was created)

    That way a CL_GraphicContext will be valid at all times, thus will not be disposed.

    Try the fullscreen test in ClanLib/Tests/Display/FullScreen

  9. #9
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    The graphic context will still be disposed with that method. But textures, sprites, buffer objects and so on will not. The graphic context itself will always be disposed because it renders to the OpenGL context of the old window.

  10. #10
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Ah yes, of course

  11. #11
    Lesser Knight
    Join Date
    Jul 2011
    Posts
    57

    Default

    Now I really did it
    My error was that I'm using a predefined handle for gc and I was getting a new handle from new window for it after destroying old window. I just had to put graphic and input context fetching after creating new window and before destroying old one. Now switching between window/fullscreen modes working on the fly. (I'm still getting exception when closing program thought, must have left a handle from destroyed window hanging somewhere. Have to recheck all code.)
    Thank you for your help.

  12. #12
    Lesser Knight
    Join Date
    Jul 2011
    Posts
    57

    Default

    btw I still get crashes in ClanGL and ClanGL1 when recreating window, still can't figure why. ClanSWR works perfectly fine though.
    Fullscreen example crashes too when working via GL.

  13. #13
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    I would blame your graphics card

    It works here.

    Try to debug ClanLib to find out what's wrong

  14. #14
    Lesser Knight
    Join Date
    Jul 2011
    Posts
    57

    Default

    I don't know if it is my video card. I tried it on about dozen of computers with different videocards(thanks to our test stand at my workplace), and several of my friends tried it on their computers - all with the same results: program always crashes on exit after switching screen modes and sometimes crashes while switching them on the fly. These results applies to both my program and the fullscreen example as well.
    I tried to debug it on my system, of course, and got a "heap free" error upon destroying OpenGL context.
    Crashing happens in opengl_texture_provider.cpp in void CL_OpenGLTextureProvider:n_dispose() at line "glDeleteTextures(1, &handle);"
    It is happening constantly as I said, the only device fullscreen is working with is software renderer.
    I tried to figure it out by my own and fix it but I have too little knowledge of OpenGL and ClanLib internals for that

  15. #15
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Do you know the GPU chipsets that crash (Intel/AMD/NVIDIA)

    It sounds like when an OpenGL graphic context is destroyed, the OpenGL texture is also automatically destroyed, even though it should not be (because it is a shared context).

    There is one way to test this theory:

    (From memory, I have not tested this)

    In the FullScreen example:

    Code:
    int FullScreen::start(const std::vector<CL_String> &args)
    {
    	quit = false;
    
    	fullscreen_requested = false;
    	is_fullscreen = false;
    
    	CL_DisplayWindowDescription window_hidden_description;
    	window_hidden_description.set_title("test");
    	window_hidden_description.set_size(CL_Size(700, 600), true);
    	window_hidden_description.set_visible(false);
    
    	CL_DisplayWindow main_hidden_window = CL_DisplayWindow(window_hidden_description);
    
    	create_window();
    
    	CL_GraphicContext gc = main_hidden_window.get_gc();
    
    	const float virtual_screen_width = 800.0f;
    	const float virtual_screen_height = 600.0f;
    
    	CL_Sprite spr_logo(gc, "../Basic2D/Resources/logo.png");
    	CL_Sprite spr_background(gc, "../../Game/DiceWar/Resources/lobby_background2.png");
    
    	float sin_count = 0.0f;
    
    	unsigned int last_time = CL_System::get_time();
    
    	//CL_FontDescription desc;
    	//desc.set_typeface_name("tahoma");
    	//desc.set_height(32);
    	//desc.set_subpixel(true);
    	//CL_Font font(gc, desc);
    	...
    	<Everything else is the same - Except remove any reference to "font">
    If that works.

    Then I have a nasty feeling that the FullScreen example is wrong! (And CL_Font in general in multi-window environments)



    We need a ClanLib expert to comment!

  16. #16
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    The GameIDE project (and my MapEditor before that) both use extensive creation and destruction of windows and therefore OpenGL contexts. Both projects currently shut down without any known crash issues. They also both create lots of textures, program objects, frame buffers, vertex buffers and high level objects like sprites and images.

    Both projects have been succesfully run on both AMD, Nvidia and Intel chipsets (although only on OpenGL 3 cards) and in the GameIDE case also under both Windows and Linux. To my knowledge they do not crash on shutdown in any of these environments.

    So what could cause your program to crash while they do not? The most likely explanation is shutdown order. Although ClanLib *should* be able survive destroying CL_Texture after all OpenGL context have been destroyed, there is always the possibility that this is broken. In both of my applications the resources are always destroyed before the last window is destroyed and it is possible that if this is not the case then you get the crash you are seeing.

  17. #17
    Lesser Knight
    Join Date
    Jul 2011
    Posts
    57

    Default

    >rombust
    Yep, that worked. No more crashes.
    Tried it in my application too - works as well when there is another window hanging in system, no more crashes.

  18. #18
    Lesser Knight
    Join Date
    Jul 2011
    Posts
    57

    Default

    oops, I was too quick, I have now exception in "void CL_OpenGLGraphicContextProvider::set_frame_buffer( const CL_FrameBuffer &draw_buffer, const CL_FrameBuffer &read_buffer)" in my program.
    But that heap allocation crash in OpenGL is gone.

  19. #19
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    OpenGL 4.2 Specification:

    The share list is the group of all contexts which share objects. If a shared object is not explicitly deleted, then destruction of any individual context has no effect on that object unless it is the only remaining context in the share list. Once the last context on the share list is destroyed, all shared objects, and all other resources
    allocated for that context or share list, will be deleted and reclaimed by the imple-mentation as soon as possible.
    I cannot find anywhere else what should happen in this specific instance (in OpenGL 3.2 and below).

    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx "wglShareLists function"

    Which may explain why certain drivers are buggy

    Hope you find the problem
    Last edited by rombust; 12-08-2011 at 01:02 PM.

  20. #20
    Lesser Knight
    Join Date
    Jul 2011
    Posts
    57

    Default

    Sometimes the lack of documentation in ClanLib is killing me
    Now I can't make a framebuffers work with changing windows and graphic contexts and I can't find any reference to properly learn how I should do it. More than half of my ClanLib's understandings came from trial-and-error.
    Being ClanLib developer is suffering.

Similar Threads

  1. GUI switching windows example
    By rombust in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 03-17-2011, 03:33 PM
  2. Res switching
    By Uhfgood in forum Novashell Game Creation System
    Replies: 2
    Last Post: 07-02-2008, 10:28 PM
  3. Fullscreen problems
    By Veitikka in forum Official ClanLib SDK Forums
    Replies: 5
    Last Post: 03-27-2008, 11:02 AM
  4. Fix for Fullscreen mode
    By glorified_ameba in forum Official ClanLib SDK Forums
    Replies: 5
    Last Post: 07-27-2007, 04:22 PM
  5. make fullscreen 1280x1024
    By gmatt in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 07-25-2007, 08:34 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •