Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating multiple windows with separate contexts #379

Closed
medvednikov opened this issue Jun 14, 2017 · 4 comments
Closed

Creating multiple windows with separate contexts #379

medvednikov opened this issue Jun 14, 2017 · 4 comments

Comments

@medvednikov
Copy link

medvednikov commented Jun 14, 2017

Hi,

Thanks for this great library!

I'd like to have two different windows with different stuff drawn on them. I'm struggling with this. Is there a small example of how to handle multiple windows/multiple contexts?

I found this in a related project:

https://github.com/notlion/Cinder-NanoVG/blob/master/samples/MultiWindow/src/MultiWindowApp.cpp\

Here's what I'm trying to do looks like in pure OpenGL:

foreach w in windows:
    foreach ctx in w.contexts:
        ctx.make_current(w)
        do_opengl_stuff()
        glFlush()

Thanks

@itscool
Copy link

itscool commented Jun 14, 2017

I've done this. At first I used a separate NanoVG context and GLFW context per window. However, this leads to weird difficulties down the road. I ended up using shared context. Like so:

glfwShared = glfwCreateWindow(... , nullptr)
glfwMakeContextCurrent(glfwShared)
glExtensionLoader()  // I used GLAD
nvgShared = nvgCreateGL*()

Then for each window:

glfwWins[i] = glfwCreateWindow(... , glfwShared)

Then to render:

foreach w in glfwWins
    glfwMakeContextCurrent(w)
    nvgBeginFrame(nvgShared, ...)
    DO_NVG_RENDERING()
    nvgEndFrame(nvgShared)
    glfwSwapBuffers(w)

This way all resources loaded using NVG are shared between all windows as well.

@medvednikov
Copy link
Author

Thanks a lot @itscool. It worked!

@medvednikov
Copy link
Author

I actually managed to make it work without sharing the context, and just like @itscool I faced strange bugs (like text not being rendered correctly in the second window).

Shared context FTW!

@EriKWDev
Copy link

EriKWDev commented Apr 6, 2021

I actually managed to make it work without sharing the context

While a shared context is nice, I'm having troubles with retaining the transform state. Care to share how you got it to work with multiple contexts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants