首页 > 其他 > 详细

5.5 编程实例-红蓝三角形

时间:2014-06-18 21:02:51      阅读:424      评论:0      收藏:0      [点我收藏+]

bubuko.com,布布扣

#include <GL/glut.h>

typedef GLfloat point2d[2]; // a point data type

void triangle( point2d a, point2d b, point2d c) // display a triangle

{

glBegin(GL_TRIANGLES);

glVertex2fv(a);

glVertex2fv(b);

glVertex2fv(c);

glEnd();

}

void display(void)

{

point2d v[3] = {{-1.0, -0.58}, {1.0, -0.58}, {0.0, 1.15}}; //initial triangle vertices

glClear(GL_COLOR_BUFFER_BIT); // Clear display window

glColor3f(0.0,0.0,1.0); // Set fill color to blue

glViewport(0, 0, 300, 400); // Set left viewport

triangle(v[0], v[1], v[2]);

glColor3f(1.0,0.0,0.0); // Set fill color to red

glViewport(300, 0, 300, 400); // Set right viewport

glRotatef(90.0, 0.0, 0.0, 1.0); // Rotate about z axis

triangle(v[0], v[1], v[2]); // Display blue triangle

glFlush();

}

void init()

{

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluOrtho2D(-2.0, 2.0, -2.0, 2.0);

glMatrixMode(GL_MODELVIEW);

glClearColor(1.0, 1.0, 1.0,1.0);

}

void main(int argc, char **argv)

{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

glutInitWindowSize(600, 400);

glutCreateWindow("Triangle");

glutDisplayFunc(display);

init();

glutMainLoop();

}

5.5 编程实例-红蓝三角形,布布扣,bubuko.com

5.5 编程实例-红蓝三角形

原文:http://www.cnblogs.com/opengl/p/3790445.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!