码迷,mamicode.com
首页 > 其他好文 > 详细

5.5 编程实例-红蓝三角形

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

标签:style   blog   http   color   com   width   

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 编程实例-红蓝三角形

标签:style   blog   http   color   com   width   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!