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("ccz");
	glutDisplayFunc(&myDisplay);
	glutMainLoop();
	return 0;
}
posted @ 2022-03-18 20:52  ccz9729  阅读(54)  评论(0编辑  收藏  举报