本文整理汇总了C++中GLWindow::createContext方法的典型用法代码示例。如果您正苦于以下问题:C++ GLWindow::createContext方法的具体用法?C++ GLWindow::createContext怎么用?C++ GLWindow::createContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GLWindow
的用法示例。
在下文中一共展示了GLWindow::createContext方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv) {
auto glversion = gl::getAvailableVersion();
auto major = GL_GET_MAJOR_VERSION(glversion);
auto minor = GL_GET_MINOR_VERSION(glversion);
if (glversion < GL_MAKE_VERSION(4, 1)) {
MessageBoxA(nullptr, "Interface requires OpenGL 4.1 or higher", "Unsupported", MB_OK);
return 0;
}
QGuiApplication app(argc, argv);
bool quitting = false;
// FIXME need to handle window closing message so that we can stop the timer
GLWindow* window = new GLWindow();
window->create();
window->show();
window->setSurfaceType(QSurface::OpenGLSurface);
window->setFormat(getDefaultOpenGLSurfaceFormat());
bool contextCreated = false;
QTimer* timer = new QTimer();
QObject::connect(timer, &QTimer::timeout, [&] {
if (quitting) {
return;
}
if (!contextCreated) {
window->createContext();
contextCreated = true;
}
if (!window->makeCurrent()) {
throw std::runtime_error("Failed");
}
glClearColor(1.0f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
window->swapBuffers();
window->doneCurrent();
});
// FIXME need to handle window closing message so that we can stop the timer
QObject::connect(&app, &QCoreApplication::aboutToQuit, [&] {
quitting = true;
QObject::disconnect(timer, &QTimer::timeout, nullptr, nullptr);
timer->stop();
timer->deleteLater();
});
timer->setInterval(15);
timer->setSingleShot(false);
timer->start();
app.exec();
return 0;
}
示例2: threadLoop
DWORD CDOPPEngineDlg::threadLoop()
{
bool bCapture = false;
bCapture = (m_pShowWinCheckBox->GetCheck() == BST_CHECKED);
// Create window with ogl context to load extensions
WNDCLASSEX wndclass;
const LPCWSTR cClassName = _T("OGL");
const LPCWSTR cWindowName = _T("DOPP Capture");
// Register WindowClass for GL window
wndclass.cbSize = sizeof(WNDCLASSEX);
wndclass.style = CS_OWNDC;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = (HINSTANCE)GetModuleHandle(NULL);
wndclass.hIcon = (HICON)LoadImage((HINSTANCE)AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME), IMAGE_ICON, LR_DEFAULTSIZE, LR_DEFAULTSIZE, NULL);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = NULL;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = cClassName;
wndclass.hIconSm = (HICON)LoadImage((HINSTANCE)AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME), IMAGE_ICON, LR_DEFAULTSIZE, LR_DEFAULTSIZE, NULL);
if (!RegisterClassEx(&wndclass))
return FALSE;
GLWindow* pWin = new GLWindow("DOPP Capture", "OGL");
pWin->create(g_uiWindowWidth, g_uiWindowHeight, false, false, false, true);
// GLWindow::create context will destroy the initial window and create a new one. To avoid that
// WndProc emits a PostQuitMessage a pointer to the initial window is passed. If this pointer is
// valid we know that it is the temporary window and should not emit PostQuitMessage.
SetWindowLongPtr(pWin->getWnd(), GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pWin));
pWin->createContext(0);
GLDOPPEngine* pEngine = NULL;
switch (m_uiEffectSelection)
{
case COLOR_INVERT:
pEngine = new GLDOPPColorInvert;
break;
case EDGE_FILTER:
pEngine = new GLDOPPEdgeFilter;
break;
case DISTORT_EFFECT:
pEngine = new GLDOPPDistort;
break;
case ROTATE_DESKTOP:
pEngine = new GLDOPPRotate;
break;
default:
pEngine = new GLDOPPEngine;
break;
}
// m_uiDesktopSelection is the id of the selected element in the Combo Box
// Need to add 1 to get the desktop id as shown in CCC
if (!pEngine->initDOPP(m_uiDesktopSelection + 1))
{
// prevent thread loop to start due to error
m_bEngineRunning = false;
}
if (!pEngine->initEffect())
{
// prevent thread loop to start due to error
m_bEngineRunning = false;
}
if (m_bEngineRunning && m_uiEffectSelection == ROTATE_DESKTOP)
{
GLDOPPRotate* pRot = dynamic_cast<GLDOPPRotate*>(pEngine);
pRot->setRotation((float)m_uiRotationAngle);
}
if (bCapture && m_bEngineRunning)
{
// Open window only if this option was checked in the GUI
pWin->open();
}
// Enable SW mouse
SystemParametersInfo(SPI_SETMOUSETRAILS, 2, 0, 0);
MSG mMsg;
//.........这里部分代码省略.........