Jump to content
  • Advertisement
Sign in to follow this  
tristam92

OpenGL glfw call fails

This topic is 980 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, everyone. I'm not professional in opengl. So I need your help.

So, currently I've started new iteration of game engine(I'm working in game company). We decide to use as base for engine cocos2dx 3.7 and write some wrappers for our script system and etc.

Now I want to add background loading of assets(texture and so on) using multi thread context of glfw.

I added some changes to GLViewImpl::initWithRect. Now I passing callback that should get main context and from that context new one as shared.

 
if (beforeFinalInitCallback) 
{ 
     (*beforeFinalInitCallback)(_mainWindow); 
}
glfwMakeContextCurrent(_mainWindow);

and callback looks like this

[](void* glWindow)
{
  std::thread thread([glWindow]()
  { 
           auto context = glfwCreateWindow(1, 1, "", 0, static_cast<GLFWwindow*>(glWindow)); 
           glfwMakeContextCurrent(context); 
           context = glfwGetCurrentContext(); 

  });
};

Even if I remove thread wrapping(it will be the same thread as in initWithRect here), I still can't create context(return null pointer).

But if I move that code to inside of initWithRect and get this

std::function<void(void*)> pFunc = [](void* glWindow)
    {

        std::thread thread([glWindow]()
        {
        auto context = glfwCreateWindow(1, 1, "", 0, static_cast<GLFWwindow*>(glWindow));
        glfwMakeContextCurrent(context);
        context = glfwGetCurrentContext();

        });
    };
    pFunc(_mainWindow);
    glfwMakeContextCurrent(_mainWindow);

it's start working. Context creating and set as current normaly.

 

It's frustrating me. I can't get where is error or something like that. I checked all params(getting all pointers valid and right).

 

Can please someone help me. I fighting with that thing 3 days already. I can't use TextureCache async methods cause I need render my scene with animation while another scene loading in background.


Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!