您的位置:首页 > 运维架构

使用OpenGL渲染线程

2012-09-04 10:12 218 查看
关键代码段

DWORD WINAPI GLThread(LPVOID lpParams) {
   PIXELFORMATDESCRIPTOR pfd = {0};
   HDC hDC = GetDC(hwndTest);
   HGLRC hRC = 0;
   
   /* Set absolute minimum format attributes; i.e. select default mode */
   pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
   pfd.nVersion = 1;
   pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
   pfd.iPixelType = PFD_TYPE_RGBA;
	
   SetPixelFormat(hDC, ChoosePixelFormat(hDC, &pfd), &pfd);
	hRC = wglCreateContext(hDC);
	wglMakeCurrent(hDC, hRC);

	float color[3][3]={1.0f, 1.0f, 0.0f,
								0.0f, 1.0f, 1.0f,
								1.0f, 0.0f, 1.0f};
	int nSwitch = 0;
	while (!done)
	{
		nSwitch++;
		if (nSwitch>2)
			nSwitch = 0;
		glClearColor(color[nSwitch][0], color[nSwitch][1], color[nSwitch][2], 0.0f);
		glClear(GL_COLOR_BUFFER_BIT);
		SwapBuffers(hDC);
		Sleep(500);
   }
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: