opengl绘制多边形

#include "stdafx.h"  
#include <GL/glut.h>
#include <Windows.h>
void myDisplay(void)
{
	glClearColor(0.1,0.5,0.1,0);
	glClear(GL_COLOR_BUFFER_BIT);

	glBegin(GL_POLYGON);
	glColor3f(0.5,0,0);
	glVertex2f(0.01,0.3);
	glVertex2f(1,1);
	glVertex2f(-0.01,-0.3);
	glVertex2f(-1,-1);
	glEnd();
	glFlush(); 
}
void glutCenterWindow(int witdh,int height)  
{  
	int x = GetSystemMetrics(SM_CXFULLSCREEN);  
	int y = GetSystemMetrics(SM_CYFULLSCREEN);  
	glViewport(0,0,witdh,height);	
	glutInitWindowPosition((x-witdh)/2, (y-height)/2);  
	glutInitWindowSize(witdh, height);  
}  
int main(int argc, char *argv[])
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); //设置显示方式
    glutCenterWindow(800,600);
	glutCreateWindow("opengl_test"); 
	glutDisplayFunc(&myDisplay); 
	glutMainLoop(); 
	return 0;
}
相关文章
相关标签/搜索