1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
class MyGLWidget: public QWidget
{
public:
MyGLWidget(QWidget* parent) :
QWidget(parent)
{
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_NoSystemBackground);
}
QPaintEngine* paintEngine() const
{
return 0;
}
void initializeGL()
{
HWND window = winId();
BOGART_ASSERT(window);
PIXELFORMATDESCRIPTOR format = {
sizeof (PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
24,
0,0,0,0,0,0, //RGB bits/shift, not used
0,
0,
0,
0,0,0,0, //accum RGBA bits, not used
32,
0,//stencil
0,
PFD_MAIN_PLANE,
0,0,0,0//not used
};
HDC dc = GetDC(window);
int pixelFormatIndex = ChoosePixelFormat(dc,&format);
BOGART_ASSERT(pixelFormatIndex)
BOOL success = SetPixelFormat(dc,pixelFormatIndex,&format);
BOGART_ASSERT(success != FALSE);
HGLRC renderContext = wglCreateContext(dc);
BOGART_ASSERT(renderContext);
wglMakeCurrent(dc,renderContext);
ReleaseDC(window,dc);
}
bool event(QEvent* event)
{
switch (event->type())
{
case QEvent::ParentChange:
BOGART_FAIL(); //not an issue yet
break;
case QEvent::Paint:
{
glClearColor(1.0f,1.0f,0.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
HDC dc = GetDC(winId());
BOOL success = SwapBuffers(dc);
BOGART_ASSERT(success != FALSE);
ReleaseDC(winId(),dc);
}
return true;
case QEvent::Resize:
QResizeEvent* re = (QResizeEvent*)event;
glViewport(0,0,re->size().width(),re->size().height());
break;
}
return QWidget::event(event);
}
};
INT WINAPI WinMain(HINSTANCE instance, HINSTANCE previousInstance, LPSTR commandLine, INT commandAmount)
{
int argc = 0;
QApplication app(argc,0);
QMainWindow* mainWindow = new QMainWindow();
mainWindow->showNormal();
MyGLWidget* gl = new MyGLWidget(mainWindow);
mainWindow->setCentralWidget(gl);
gl->initializeGL();
app.exec();
}
|