OpenGL中有多个窗口? [英] Multiple windows in OpenGL?

查看:241
本文介绍了OpenGL中有多个窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在2个窗口中使用openGL?就像在2个不同的窗口(假设第一个是640x480,另一个是1024x768)中呈现不同的内容(假设一个窗口是编辑器,另一个窗口是主/普通窗口显示)

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)

推荐答案

如果使用的是GLUT,则可以使用glutSetWindow()/glutGetWindow()调用来选择正确的窗口(在使用glutCreateSubWindow()创建它们之后).但是,有时候GLUT可能不是适合该工作的工具.

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.

如果您使用的是Windows,则需要查看wglMakeCurrent()和wglCreateContext().在OS X上存在aglSetCurrentContext()等,而X11需要glXMakeCurrent().

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().

这些功能激活了您可以渲染到的当前OpenGL上下文.每个平台特定的库都有其自己的创建窗口并将OpenGL上下文绑定到它的方式.

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.

在Windows上,在为窗口获取HWND和HDC之后(在CreateWindow和GetDC调用之后).通常,您可以执行以下操作来设置OpenGL:

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:

GLuint l_PixelFormat = 0;

// some pixel format descriptor that I generally use:
static PIXELFORMATDESCRIPTOR l_Pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, 
    PFD_DRAW_TO_WINDOW + PFD_SUPPORT_OPENGL + PFD_DOUBLEBUFFER, 
    PFD_TYPE_RGBA, m_BitsPerPixel, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0};

if(!(l_PixelFormat = ChoosePixelFormat(m_hDC, &l_Pfd))){
    throw std::runtime_error("No matching pixel format descriptor");
}

if(!SetPixelFormat(m_hDC, l_PixelFormat, &l_Pfd)){
    throw std::runtime_error("Can't set the pixel format");
}

if(!(m_hRC = wglCreateContext(m_hDC))){
    throw std::runtime_error("Can't create rendering context");
}

wglMakeCurrent(m_hDC, m_hRC);

您使用该代码创建多个窗口并将OpenGL绑定到该窗口,然后每次要绘制到特定窗口时,都必须调用wglMakeCurrent ,然后执行任何操作并传入参数对应于该窗口.

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.

作为一个附带说明,OpenGL允许您在不同的上下文之间共享某些数据,但是根据规范,可以共享的数据非常有限.但是,大多数操作系统都允许您共享比规范中指定的数据更多的数据.

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.

这篇关于OpenGL中有多个窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆