其他分享
首页 > 其他分享> > OPENGL实验二

OPENGL实验二

作者:互联网

 
//#include "stdafx.h"
#include<gl/glut.h>
#include<math.h>
#include <stdlib.h>
const double PI = 3.14159265357f;
 
 
void myDisplay(void)
{
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);
	//红色菱形
	glBegin(GL_POLYGON);
	glColor3f(1.0f, 1.0f, 1.0f); glVertex2f(0.0f, 0.0f);
	glColor3f(1.0f, 0.0f, 1.0f); glVertex2f(0.25f, tan(PI / 3) / 4);
	glColor3f(0.0f, 1.0f, 1.0f); glVertex2f(0.0f,  tan(PI / 3) / 2);
	glColor3f(1.0f, 1.0f, 0.0f); glVertex2f(-0.25f, tan(PI / 3) / 4);
	glEnd();
	
	glBegin(GL_POLYGON);
	glColor3f(1.0f, 0.0f, 1.0f); glVertex2f(0.0f, 0.0f);
	glColor3f(0.0f, 1.0f, 1.0f); glVertex2f(0.25f, tan(PI / 3) /4);
	glColor3f(1.0f, 1.0f, 0.0f); glVertex2f(0.75f, tan(PI/3) / 4);
	glColor3f(1.0f, 1.0f, 1.0f); glVertex2f(0.5f, 0.0f);
	glEnd();

	glBegin(GL_POLYGON);
	glColor3f(0.0f, 1.0f, 1.0f); glVertex2f(0.0f, 0.0f);
	glColor3f(1.0f, 1.0f, 0.0f); glVertex2f(0.5f, 0.0f);
	glColor3f(1.0f, 1.0f, 1.0f); glVertex2f(0.75f, -tan(PI/3) / 4);
	glColor3f(1.0f, 0.0f, 1.0f); glVertex2f(0.25f, -tan(PI / 3) / 4);
	glEnd();

	glBegin(GL_POLYGON);
	glColor3f(1.0f, 1.0f, 0.0f); glVertex2f(0.0f, 0.0f);
	glColor3f(1.0f, 1.0f, 1.0f); glVertex2f(0.25f, -tan(PI/3) / 4);
	glColor3f(1.0f, 0.0f, 1.0f); glVertex2f(0.0f, -tan(PI/3) / 2);
	glColor3f(0.0f, 1.0f, 1.0f); glVertex2f(-0.25f, -tan(PI/3) / 4);
	glEnd();

	glBegin(GL_POLYGON);
	glColor3f(1.0f, 1.0f, 1.0f); glVertex2f(0.0f, 0.0f);
	glColor3f(1.0f, 0.0f, 1.0f); glVertex2f(-0.5f, 0.0f);
	glColor3f(0.0f, 1.0f, 1.0f); glVertex2f(-0.75f, -tan(PI/3) / 4);
	glColor3f(1.0f, 1.0f, 0.0f); glVertex2f(-0.25f, -tan(PI / 3) / 4);
	glEnd();

	glBegin(GL_POLYGON);
	glColor3f(1.0f, 0.0f, 1.0f); glVertex2f(0.0f, 0.0f);
	glColor3f(0.0f, 1.0f, 1.0f); glVertex2f(-0.25f, tan(PI / 3) /4);
	glColor3f(1.0f, 1.0f, 0.0f); glVertex2f(-0.75f, tan(PI/3) / 4);
	glColor3f(1.0f, 1.0f, 1.0f); glVertex2f(-0.5f, 0.0f);
	glEnd();

	glFlush();
 
}
 
int main(int argc, char *argv[])
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
	glutInitWindowPosition(100, 100);
	glutInitWindowSize(500, 500);
	glutCreateWindow("2012020038-程崇正");
	glutDisplayFunc(&myDisplay);
	glutMainLoop();
	return 0;
}

标签:glVertex2f,1.0,OPENGL,0.0,实验,glColor3f,tan,PI
来源: https://www.cnblogs.com/c972937/p/16023535.html