Cocos2dx 3.4 how to create toggle fullscreen at runtime? (Mac,Win32)

How to create toggle fullscreen at runtime in Cocos2dx 3.4 for Mac and Win32?

Surely no one knows, and never made it? )

I wrote a test function that makes fullscreen black. I can not close the window and I have to restart my Mac. I think it loses context.

void GLViewImpl::setFullScreen ( bool bFullScreen ) {

    bFullScreen = true;//TODO: for test
    
    int width = 1024;
    int height = 768;
    
    if (bFullScreen)
    {
        _monitor = glfwGetPrimaryMonitor();
        if (nullptr == _monitor) {
            return;
        }
        
        const GLFWvidmode* videoMode = glfwGetVideoMode(_monitor);

        width = videoMode->width;
        height = videoMode->height;
        
        glfwWindowHint(GLFW_REFRESH_RATE, videoMode->refreshRate);
        glfwWindowHint(GLFW_RED_BITS, videoMode->redBits);
        glfwWindowHint(GLFW_BLUE_BITS, videoMode->blueBits);
        glfwWindowHint(GLFW_GREEN_BITS, videoMode->greenBits);
    }


    GLFWwindow* newWindow = glfwCreateWindow(width, height, _viewName.c_str(), bFullScreen ? _monitor : nullptr, _mainWindow );
    glfwDestroyWindow(_mainWindow);
    _mainWindow = newWindow;
    
    glfwMakeContextCurrent(_mainWindow);
    glfwSwapInterval(1);
    
}

Did you try CMD+Q as that should still work.

I believe there’s a number of posts on this issue. You can create the game to startup in full screen mode. The problems I see by default (on OS X) is that the app takes full control of mouse/keyboard and so hovering at top of screen doesn’t reveal the main menu. The issue is with toggling in and out of full screen mode.

glview = GLViewImpl::createWithFullScreen(viewName, [vidmode], [monitor]);

You should check github issues and add a feature request if there’s not one already.

i’m find answer. Cocos2dx can’t use switch between fullscreen and window, because it use glfw 3.0. This version does not support this feature.
http://www.cocos2d-x.org/issues/3798

Already there is a new version 3.1.1. I will try to implement it.

Great! a pull request would be welcomed I’m sure. This one however will require an engine update before its in the codebase so probably won’t be officially supported until 3.5 or 3.6.

Is this fixed somewhere?

Can this support normal fullscreen/screen features of OS X? Like we flip back and forth between screens with three fingers on trackpad etc…

Is this feature already implemented in new Cocos2d-x version?

I’m curious, too. I’m on cocos2d-x 3.10. I’ve updated my Windows version of glfw, but I don’t see how to update the Mac version. Would the updated version offer the full screen toggle?

hey All,

I implemented this in my branch of 3.4:

Here’s the first couple commits if you need a starting point (or you can look at CCGLViewImpl-desktop where most of the code changes are):


It would be cool if this feature is added to the latest cocos2d-x.

1 Like

My cocos modifications are similar to @Shaedo’s. This is great starting place for desktop games using cocos2d-x.

@Rusty A better place would be having a PR that can be merged :smiley:
I’ll eventually get around to it if no one else does, but not in the next few weeks.

In GLFW 3.2, they added function that switches window between fullscreen and windowed without losing context.

I think cocos2d 3.13 updated GLFW to 3.2, so check that out too.

cpp-tests (3.13) seems to work just fine on Mac. Haven’t tested Win32 yet.

Excellent! Um, I’m going to have to embarrass myself here and ask how to get those changes into my project. I use git all the time, but so far only within a project, so I don’t know the best way to pull this into my 3.10 project.

My Windows version is ready to release (already approved by Steam), and I’m targeting 9/6, since that’s the first week of pro football. My iOS version is being reviewed by Apple.

So, with that in mind (and the fact that my project history is all in git), would it be better to create a new project with 3.13 and copy all my files over or is there some good way to update a project to 3.13?

Thanks again, Steve and everyone, this is really good news!

So you will have to test this out yourself if you’re interested to make sure the scaling/resizing is as you desire. You may want to follow @Sheado’s implementation instead? Or even try that first, then upgrade to 3.13 if it’s not working in an hour or two.


How I’d upgrade (others may have better system)
Download the 3.13 zip file package on the topic announcing its release (or download section of the site).
Run download-deps.py and setup.py.

3.10 to 3.13 shouldn’t be too much work unless you’ve modified the engine files.

  • Backup your current project by either creating a new branch or physical copy.
  • Replace your project’s /cocos/ folder with the one in the extracted zip file.
  • Test.
  • If fails you may have to create a new Mac project so that you can examine the XCode project in order to update links to - the various 3rd party libraries.

If you haven’t modified the XCode project much beyond provisioning profile settings.

  • You can alternatively create a new project using the 3.13 cocos console.
  • Copy or reference all your game files and resources into your XCode project.
  • Test

Thanks very much, Steve. I’m looking over @Sheado’s commits now, and I was thinking the same thing, that maybe I would copy his external folder over, but I also like the option of copying the whole cocos folder over, since I haven’t modified it. I’ll let you know. Thanks!

@dogwalker Since you’re using 3.10, it’s probably better that you take the leap to 3.13 rather than using my branch which is branched from 3.4

Thanks, Sheado, will do!

(I posted this on my other thread, but frankly, it’s worth a double post).

Whoa, I realize it’s early, and I have to do a lot more testing, but … this is working great!!!

I downloaded cocos2d-x 3.13 and created a temporary project, then backed up my existing cocos2d folder and copied the 3.13 folder over in its place (replacing it, not copying over it), and built my Mac version, and … this is beautiful!

I did not update any of the proj.<> folders, and I hope that’s ok. I also haven’t tested this over on my Windows machine yet, or even really tested the iOS version, but this is really exciting! I’m going to break a rule and double post my thanks on that other thread as well, because I think this really rocks!

Thanks, Steve!