OpenGL绘制的桌子---比较初级
来源:互联网 发布:西安全球程序员节直播 编辑:程序博客网 时间:2024/04/27 17:51
#include <GL/glut.h>#include <stdlib.h>float fTranslate;float fRotate;float fScale = 1.0f;void Draw_Table() {glPushMatrix();glScalef (5.0, 4.0, 1.0);glutWireCube(1.0);glPopMatrix();glPushMatrix();glTranslatef(0.0,0.0,-2.0);glPushMatrix();glTranslatef(1.5,1.0,0.0);glScalef (1.0, 1.0, 3.0);glutWireCube(1.0);glPopMatrix();glPushMatrix();glTranslatef(1.5,-1.0,0.0);glScalef (1.0, 1.0, 3.0);glutWireCube(1.0);glPopMatrix();glPushMatrix();glTranslatef(-1.5,-1.0,0.0);glScalef (1.0, 1.0, 3.0);glutWireCube(1.0);glPopMatrix();glPushMatrix();glTranslatef(-1.5,1.0,0.0);glScalef (1.0, 1.0, 3.0);glutWireCube(1.0);glPopMatrix();glPopMatrix();}void reshape(int width, int height){if (height==0){height=1;}glViewport(0,0,width,height);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(120.0f,(GLfloat)width/(GLfloat)height,0.1f,20.0f);glMatrixMode(GL_MODELVIEW);glLoadIdentity();}void idle(){glutPostRedisplay();}void redraw(){glClear(GL_COLOR_BUFFER_BIT);glLoadIdentity();glPushMatrix();glTranslatef(-11.0f, 0.0f,-6.0f);glTranslatef(0.0f, fTranslate, 0.0f);Draw_Table();glPopMatrix(); glPushMatrix();glTranslatef(0.0f, 0.0f,-6.0f);glRotatef(fRotate, 0, 1.0f, 0);Draw_Table();glPopMatrix();glPushMatrix();glTranslatef(11.0f,0.0f,-6.0f);glScalef(fScale, fScale, fScale);Draw_Table();glPopMatrix();fTranslate += 0.005f;fRotate += 0.5f;fScale -= 0.005f;if(fTranslate > 0.5f) fTranslate = 0.0f;if(fScale < 0.5f) fScale = 1.0f;glutSwapBuffers();}int main (int argc, char *argv[]){ glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);glutInitWindowSize(840,480); glutCreateWindow("Simple GLUT App");glutDisplayFunc(redraw);glutReshapeFunc(reshape);glutIdleFunc(idle); glutMainLoop(); return 0;}
#include <GL/glut.h>#include <stdlib.h>float fTranslate;float fRotate;float fScale = 1.0f;void Draw_Table() {glPushMatrix();glScalef (1.0, 1.0, 0.8);glutSolidCube(1.0);glPopMatrix();glPushMatrix();glTranslatef(0.0,0.0,-0.8);glPushMatrix();glScalef (2.0, 2.0, 0.8);glutSolidCube(1.0);glPopMatrix();glTranslatef(0.0,0.0,-0.8);glPushMatrix();glScalef (3.0, 3.0, 0.8);glutSolidCube(1.0);glPopMatrix();glTranslatef(0.0,0.0,-0.8);glPushMatrix();glScalef (4.0, 4.0, 0.8);glutSolidCube(1.0);glPopMatrix();glTranslatef(0.0,0.0,-0.8);glPushMatrix();glScalef (5.0, 5.0, 0.8);glutSolidCube(1.0);glPopMatrix();glTranslatef(0.0,0.0,-0.8);glPushMatrix();glScalef (6.0, 6.0, 0.8);glutSolidCube(1.0);glPopMatrix();glTranslatef(0.0,0.0,-3.0);glPushMatrix();glTranslatef(2.0,2.0,0.0);GLUquadricObj *cylinder_obj_1;cylinder_obj_1=gluNewQuadric();glPushMatrix();gluCylinder(cylinder_obj_1,0.5,0.5,3.0,20,20);glPopMatrix();glPopMatrix();glPushMatrix();glTranslatef(-2.0,2.0,0.0);GLUquadricObj *cylinder_obj_2;cylinder_obj_2=gluNewQuadric();glPushMatrix();gluCylinder(cylinder_obj_2,0.5,0.5,3.0,20,20);glPopMatrix();glPopMatrix();glPushMatrix();glTranslatef(-2.0,-2.0,0.0);GLUquadricObj *cylinder_obj_3;cylinder_obj_3=gluNewQuadric();glPushMatrix();gluCylinder(cylinder_obj_3,0.5,0.5,3.0,20,20);glPopMatrix();glPopMatrix();glPushMatrix();glTranslatef(2.0,-2.0,0.0);GLUquadricObj *cylinder_obj_4;cylinder_obj_4=gluNewQuadric();glPushMatrix();gluCylinder(cylinder_obj_4,0.5,0.5,3.0,20,20);glPopMatrix();glPopMatrix();glPopMatrix();}void reshape(int width, int height){if (height==0){height=1;}glViewport(0,0,width,height);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(120.0f,(GLfloat)width/(GLfloat)height,0.1f,20.0f);glMatrixMode(GL_MODELVIEW);glLoadIdentity();}void idle(){glutPostRedisplay();}void redraw(){glClear(GL_COLOR_BUFFER_BIT);glLoadIdentity();glPushMatrix();glTranslatef(-11.0f, 0.0f,-6.0f);glTranslatef(0.0f, fTranslate, 0.0f);Draw_Table();glPopMatrix(); glPushMatrix();glTranslatef(0.0f, 0.0f,-6.0f);glRotatef(fRotate, 0, 1.0f, 0);Draw_Table();glPopMatrix();glPushMatrix();glTranslatef(11.0f,0.0f,-6.0f);glScalef(fScale, fScale, fScale);Draw_Table();glPopMatrix();fTranslate += 0.005f;fRotate += 0.5f;fScale -= 0.005f;if(fTranslate > 0.5f) fTranslate = 0.0f;if(fScale < 0.5f) fScale = 1.0f;glutSwapBuffers();}int main (int argc, char *argv[]){ glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);glutInitWindowSize(840,480); glutCreateWindow("Simple GLUT App");glutDisplayFunc(redraw);glutReshapeFunc(reshape);glutIdleFunc(idle); glutMainLoop(); return 0;}
0 0
- OpenGL绘制的桌子---比较初级
- opengl绘制桌子(平移、旋转、缩放)
- [OpenGL] 桌子的平移、旋转和缩放
- openGL 基本绘制方式比较
- OpenGL实验(二)桌子的坐标系变换 矩阵 视图
- OpenGL实验(三)桌子的纹理 光照
- 图形学opengl实验二-桌子的矩阵变换
- OpenGL的数组绘制
- Opengl -- 五角星的绘制
- Opengl -- 五角星的绘制
- opengl点的绘制
- opengl圆环的绘制
- opengl使用现在比较常用的方法来绘制简单几何图元
- [OpenGL]用OpenGL图形的绘制--矩形
- OpenGL 可移动的桌子上可移动的茶壶瞄
- OpenGL中绘制的机场
- OpenGL中SolidCylinder的绘制
- 基于opengl的RoundBox绘制
- 不能任意改变它的大小
- 2014-04-19编程之美初赛题目及答案解析
- mysql事务,锁,sql注入,sql_mode学习日记
- 关于利用WebView访问Internet问题
- 们需要在风火轮的下面显示
- OpenGL绘制的桌子---比较初级
- linux线程调度策略
- Oracle 新建用户
- oralce imp导入报错imp-00013只有dba才能导入由其他dba导出的文件
- 三星:苹果“22亿美元赔偿”计算方法完全错误
- 【跟着贺老师做C++项目】学生成绩统计
- Windows下用gSOAP开发webservice程序
- XTU OJ
- Access System