這次計圖考試: 有兩題
poly函式畫的是五角型加上五芒星
#include "windows.h"
#include "gl/gl.h"
#include "gl/glut.h"
#include "gl/glu.h"
void init(void)
{
glClearColor(1.0,1.0,1.0,0.0); //背景顏色:白
glMatrixMode(GL_PROJECTION); //投影模式
gluOrtho2D(0.0,300.0,0.0,150.0); //宣告視窗內可見座標系bonder
}
void rect(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.4,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(0.0,0.0);
glVertex2f(0.0,150.0);
glVertex2f(300.0,150.0);
glEnd();
glColor3f(1.0,1.0,0.0);
glBegin(GL_POLYGON);
glVertex2f(0.0,0.0);
glVertex2f(300.0,0.0);
glVertex2f(300.0,150.0);
glColor3f(1.0,0.0,0.0);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(150.0,150.0);
glVertex2f(300.0,75.0);
glVertex2f(150.0,0.0);
glVertex2f(0.0,75.0);
glEnd();
glFlush();
}
void poly(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.4,0.4);
glBegin(GL_POLYGON);
glVertex2f(50.0,0.0);
glVertex2f(150.0,0.0);
glVertex2f(200.0,100.0);
glVertex2f(100.0,200.0);
glVertex2f(0.0,100.0);
glEnd();
glColor3f(0.4,1.0,0.4);
glBegin(GL_LINE_STRIP);
glVertex2f(50.0,0.0);
glVertex2f(100.0,200.0);
glVertex2f(150.0,0.0);
glVertex2f(0.0,100.0);
glVertex2f(200.0,100.0);
glVertex2f(50.0,0.0);
glEnd();
glFlush();
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);//初始GLUT
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);//設定顯示模式
glutInitWindowPosition(100,100);
glutInitWindowSize(300,150);
glutCreateWindow("OpenGL Test");
init();
glutDisplayFunc(rect);
glutMainLoop();
}
沒有留言:
張貼留言