OpenGL画四个三角形组成四面体,并进行旋转
2016-03-21 21:02
260 查看
#define GLUT_DISABLE_ATEXIT_HACK#include <GL/glut.h>#include <stdlib.h>#include <stdio.h>static float roangles;void init(void){glClearColor (0.0, 0.0, 0.0, 0.0);glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);glEnable(GL_DEPTH_TEST);}void display(void){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glPushMatrix();glRotatef( roangles, 0.0, 1.0, 0.0 );glBegin(GL_TRIANGLES);glVertex3f(1.0, 0.0, 0.0);glVertex3f(0.0, 1.0, 0.0);glVertex3f(0.0, 0.0, 1.0);glVertex3f(0.0, 0.0, 0.0);glVertex3f(0.0, 1.0, 0.0);glVertex3f(1.0, 0.0, 0.0);glVertex3f(0.0, 0.0, 0.0);glVertex3f(0.0, 0.0, 1.0);glVertex3f(0.0, 1.0, 0.0);glVertex3f(0.0, 0.0, 0.0);glVertex3f(0.0, 0.0, 1.0);glVertex3f(1.0, 0.0, 0.0);glEnd();glPopMatrix();glFlush();}void reshape(int w, int h){glViewport(0, 0, (GLsizei) w, (GLsizei) h);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 30.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();glTranslatef(0.0, 0.0, -3.6);glRotatef( 45, 1.0, 0.0, 0.0 );}void idle(){roangles += 0.01f;glutPostRedisplay();}/* ARGSUSED1 */void keyboard(unsigned char key, int x, int y){switch (key) {case 27:exit(0);break;}}int main(int argc, char** argv){glutInit(&argc, argv);glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);glutInitWindowSize(250, 250);glutInitWindowPosition(100, 100);glutCreateWindow(argv[0]);glutIdleFunc( idle );init();glutReshapeFunc(reshape);glutDisplayFunc(display);glutKeyboardFunc (keyboard);glutMainLoop();return 0;}
相关文章推荐
- centos下 json,ncurse安装测试
- 将Tomcat源码导入Eclipse的标准步骤
- linux系统支持中文
- 一些网站的推荐(长期更新)
- PopupWindow和AlertDialog区别
- 《Linux内核设计与实现》课本第五章学习笔记——20135203齐岳
- 【Data Algorithms_Recipes for Scaling up with Hadoop and Spark】Chapter 8 Common Friends
- 关于Linux系统编程的错误处理:errno、perror、strerror
- linux下的tar命令
- Linux 之 最常用的20条命令
- 卸载centos自带的jdk并安装新的
- 通过匹配绑定select option的文本值 模糊匹配
- Apache使用localhost可以访问但使用本机IP(局域网)不能访问
- scoped _ptr的模拟实现与解析
- Nginx反向代理配置
- Linux管道的实现机制
- Linux基础(三)
- 利用Apache commons pool2构建池应用
- linux idea14 maven 部署 tomcat. 遇到的问题
- linux screen 的基本使用