c语言在qt环境下调用opengl es 2.0 api创建机器人手臂
2013-08-14 23:05
597 查看
#include <QtCore/QCoreApplication> #include <windows.h> #include <GL/GL.h> #include <GL/GLU.h> #include <GL/glut.h> static int shoulder = 0, elbow = 0; void init() { glClearColor(0.0,0.0,0.0,0.0); glShadeModel(GL_FLAT); } void display() { glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glTranslatef(-1.0,0.0,0.0); glRotatef((GLfloat)shoulder,0.0,0.0,1.0); glTranslatef(1.0,0.0,0.0); glPushMatrix(); glScalef(2.0,0.4,1.0); glutWireCube(1.0); glPopMatrix(); glTranslatef(1.0,0.0,0.0); glRotatef((GLfloat)elbow,0.0,0.0,1.0); glTranslatef(1.0,0.0,0.0); glPushMatrix(); glScalef(2.0,0.4,1.0); glutWireCube(1.0); glPopMatrix(); glPopMatrix(); glutSwapBuffers(); } void reshape(int w,int h) { glViewport(0,0,(GLsizei)w,(GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(65.0,(GLfloat)w/(GLfloat)h,1.0,20.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0,0.0,-5.0); } void keyboard(unsigned char key,int x,int y) { switch(key) { case 's': shoulder = (shoulder+5)%360; glutPostRedisplay(); break; case 'S': shoulder = (shoulder-5)%360; glutPostRedisplay(); break; case 'e': elbow = (elbow+5)%360; glutPostRedisplay(); break; case 'E': elbow = (elbow-5)%360; glutPostRedisplay(); break; default: break; } } int main(int argc, char *argv[]) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(100,100); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; }
相关文章推荐
- C语言创建动态dll,并调用该dll(visual studio 2013环境下)
- C语言创建动态dll和调用dll(visual studio 2013环境下)
- ubuntu环境中操作MySQL,使用C语言API调用MySQL
- qt 调用百度api 之 Qt 与 Html交互
- tensorflow r1.4 ubuntu14.04 C++ API调用 环境配置教程
- C语言创建文件夹【linux环境】
- QT5 配置交叉编译环境完毕后,无法调用C库的原因?
- openGL es2.0 创建颜色平面和文理平面
- java 调用hbase api创建hbase分区表
- 初学Qt之--在Qt中调用外部C语言模块
- 用java的jni调用C语言的API,实现带图形界面的一元稀疏多项式计算器
- 在VS2008环境下编写C语言DLL,并在C++和C#项目下调用
- 在Qt环境里调用VS2008编译器编译Qt Creator编写的程序
- c语言调用libvirt库函数创建资源池Pool
- QTCreator + QTEmbedded 在Ubuntu上创建嵌入式ARM开发环境
- openGL es2.0 创建灯光颜色球
- 用C++编程调用libvirt的API来创建KVM虚拟机
- Mac上使用PowerVR_SDK搭建OpenGL ES2.0 开发环境
- Qt WebChannel JavaScript API.javascript调用有返回值的C++函数官方教程
- PlayBook NDK 2.0 + Qt 开发环境 on Windows 7