Is it possible to have openGL in 2 windows? as in 2 different windows (lets say the first is 640x480 and the other is 1024x768) rendering different things (lets say one window is an editor and the other is the main/normal window display)
相关问题
- Is GLFW designed to use without LWJGL (in java)?
- glDrawElements only draws half a quad
- Scaling png font down
- OpenGL buffer update [duplicate]
- How does gl_ClipVertex work relative to gl_ClipDis
相关文章
- Converting glm::lookat matrix to quaternion and ba
- Behavior of uniforms after glUseProgram() and spee
- Keep constant number of visible circles in 3D anim
- GLEW and Qt5 redefinition of headers
- How do I remove axis from a rotation matrix?
- how to calculate field of view of the camera from
- Assimp model loading library install/linking troub
- anyone can explain the “field of view”
I've done multiple OpenGL windows in an MFC application before. Here's a class you might find useful: since there can only be one current render context in the UI thread at a time, I wrote a class wrapper to make managing it easier.
SaveRestoreRC.h
// this class helps to manage multiple RCs using an RAII design pattern
SaveRestoreRC.cpp:
Now derive a class from CWnd and add these member variables:
Then in every member function where you call ANY OpenGL commands, use CSaveRestoreRC so that your current render context doesn't get screwed up.
If you like using only glut library, please look a code by Eric Stringer.
I ran the sample code at Windows 7 but I had to replace one line of glutIntit to
Yes, this is possible. For each window you will need to create a unique device context and render context.
Before making GL calls to the window you must call wglMakeCurrent like this:
If you're using GLUT you can use the glutSetWindow() / glutGetWindow() calls to select the correct window (after creating them with glutCreateSubWindow()). However sometimes GLUT might not be the right tool for the job.
If you're working on Windows you'll want to look into the wglMakeCurrent() and wglCreateContext(). On OS X there is aglSetCurrentContext() et cetera, and X11 requires glXMakeCurrent().
Those functions activate the current OpenGL context to which you can render. Each platform specific library has it's own ways of creating a window and binding an OpenGL context to it.
On Windows, after you've acquired your HWND and HDC for a window (after a CreateWindow and GetDC call). You generally do something like this to set up OpenGL:
You use that code to create multiple windows and bind OpenGL to it, then each time you want to draw to a specific window you have to call wglMakeCurrent before you do anything and you pass in the parameters corresponding to that window.
As a side-note, OpenGL allows you to share certain data between different contexts, however as per spec the data that you can share is pretty limited. However, most OSes allow you to share more data than specified in the specification.
On Windows you can share OpenGL objects such as textures and shaders with wglShareLists(). It typically does share everything you'd care about, despite what MSDN says.