You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Saturday, December 17th 2011, 8:12pm

Issues developing own GL solution (not QGL) on windows

Hey everyone,

I'm implementing my own GL widget derived from QWidget ( not from QGLWidget ), but I'm having an annoying glitch somewhere. Right now I'm only developing on vs2008, using Qt-4.7.3.

When my application start running, I don't get any output from GL, only the default "gray" background. When I resize the window, sometimes my output will show up, sometimes it won't. And occasionally my output will show up for part of the window from the top left to a position that was the bottom right some time in the past.

Yellow = My gl output (with glClearColor/glClear)



This is my repro case:

Source code

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();
}


Anyone know what I'm missing here?