Hi!
I wanted to use glfw functions, but they don’t seemed to be working. Here’s what I did: I have a class inherited from cocos2d::Node, I’ve overridden the visit function and called glfwGetWindowSize, but it returs 0 for width and height. I’ve tried other glfw functions as well and they behave the same.
When I run this, isVisible , width and height are all 0. But if I put that glfw part in the base Node class’s visit funcion, inside CCNode.cpp , then glfw works fine ( isVisible , width and height are all set).
Am I doing something wrong or I’m not supposed to use glfw functions at all?
I’m on windows using cocos2d-x 3.17.1 with Visual Studio 2017
I don’t know if you are trying to create a wraper for something or to extend some functionality so i apologize if my answer is dumb, but to develop a game there is no need to do that.
There is a singleton class called Director. You can get it using:
auto director = Director::getInstance();
you can also ask for that information like this:
auto visibleSize = Director::getInstance()->getVisibleSize();
auto winSize = Director::getInstance()->getWinSize();
auto winSizeInPixels = Director::getInstance()->getWinSizeInPixels();
auto origin = Director::getInstance()->getVisibleOrigin();
What I really wanted is to integrate ImGui ( https://github.com/ocornut/imgui ) into cocos2d-x and to do that I need direct access to glfw. But unfortunately glfw functions don’t work (at least for me it didn’t work) in my classes/files (not even in classes derived from cocos2d-x base classes).
What I ended up doing is I added some helper functions in the GLViewImpl class for each glfw function that I need (in the CCGLViewImpl-desktop.h and .cpp files).
So, instead of this:
When I coded for usb Joystick, i need to do this way only. Something its related to glfw thread, there was one article related to this. Dont remember now. May be @zhangxm can tell us why is it so?
I have it working on Windows 10, using Cocos2d-x 3.17.x (latest github code), but I may have updated ImGui to a newer release, and adapted the Cocos2d-x integration code from https://github.com/c0i/imguix to work with it.
I’ve attached it to this post, so try it out if you want to see if it works. imgui.zip (476.5 KB)
This is how I link it in the game root CMakeLists.txt:
For my projects it is in the [gameproject]/external/imgui path, so you will need to adjust the above CMakeLists.txt sample if you put it anywhere else.