#include <windows.h> //此头文件一定要放在最前 #include <GL/gl.h> #include <GL/glu.h> #include <GL/glaux.h> #include <stdio.h> #include <stdlib.h> #include <math.h> #include <iostream> #include <conio.h> using namespace std; //添加这3条语句 #pragma comment (lib, "opengl32.lib") #pragma comment (lib, "glu32.lib") #pragma comment (lib, "glaux.lib") #pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" ) //这句是不让控制台窗体出现,如果想要出现,去掉即可。 float root2 = sqrt(2); float base = 2*3.14159/10; void drawangle(int x0,int y0,int x1,int y1,int x2,int y2) { glBegin(GL_TRIANGLES); glVertex2i(x0,y0); glVertex2i(x1,y1); glVertex2i(x2,y2); glEnd(); } void drawfive(int R1,int R2,int angle,int x,int y) { int i; int x0,y0,x1,y1; float a1 = cos(angle-0.01); float a2 = sin(angle-0.01); x0 = x + R1*a1; y0 = y + R1*a2; for(i=1;i<=10;i++) { float b1 = cos(angle+base*i); float b2 = sin(angle+base*i); if(i%2==1) { glColor3f(1,0,0); x1 = x+R2*b1; y1 = y+R2*b2; } else { glColor3f(1,1,0); x1 = x+R1*b1; y1 = y+R1*b2; } drawangle(x,y,x0,y0,x1,y1); x0 = x1; y0 = y1; } } void CALLBACK draw() { glClear(GL_COLOR_BUFFER_BIT); drawfive(75,36,0,200,200); glFinish(); } void init() { glClearColor(0.0,0.0,0.0,1.0);//黑色背景 } int main(int argc, char* argv[]) { auxInitDisplayMode(AUX_SINGLE|AUX_RGBA); auxInitPosition(0,0,500,500); auxInitWindow("Project 3"); init(); auxMainLoop(draw); return 0; }
图形学第三次作业
猜你喜欢
转载自blog.csdn.net/baidu_38370610/article/details/80567822
今日推荐
周排行