MFC中使用GLUT

MFC中可以使用GLUT,但是因为GLUT的glutMainLoop会独占程序,影响MFC本身的执行,所以需要另外开辟一个线程来单独执行GLUT窗口。


void display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glPushMatrix();
	//glRotatef(0, 0.0, 1.0, 0.0);
	glutSolidTeapot(1.0);
	glPopMatrix();

	glutSwapBuffers();
}

void reshape(int x, int y)
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(60, (float)x/(float)y, 0.1, 100);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
}

void idle()
{
	glutPostRedisplay();
}

 UINT ThreadProc(LPVOID lpParameter)
{
	int argc=1;
	char* argv[]={"good"};
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
	glutCreateWindow("test");

	glutDisplayFunc(display);
	glutReshapeFunc(reshape);
	glutIdleFunc(idle);
	glutMainLoop();

	return 0;
}


void CRenderDlg::OnBnClickedOk()
{
	CWinThread* tr=AfxBeginThread(ThreadProc,GetSafeHwnd());
	tr->m_bAutoDelete=FALSE;

}



你可能感兴趣的:(MFC中使用GLUT)