首页 > 代码库 > opengl 矩阵变换
opengl 矩阵变换
#include <windows.h> #include <GL/gl.h> #include <GL/glaux.h> GLfloat step=0.0,s=0.1; void CALLBACK display(); void CALLBACK display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); s+=0.005; if(s>1.0)s=0.1; glPushMatrix(); glScalef(s,s,s); //glRotatef(step,0.0,1.0,0.0); //沿y轴旋转 glRotatef(step,0.0,0.0,-1.0);//沿z轴旋转(绕Z轴旋转时,大于0,表示逆时针旋转,小于0顺时针旋转) //glRotatef(step,1.0,0.0,0.0); //对物体进行数学描述 glBegin(GL_POLYGON); glColor3f(0.0,1.0,1.0); glVertex2f(-0.4,-0.4); glColor3f(1.0,0.0,0.0); glVertex2f(0.0,0.0); glColor3f(1.0,0.0,1.0); glVertex2f(-0.4,0.4); glEnd(); glBegin(GL_LINES); glColor3f(0.0,1.0,1.0); glVertex2f(0.0,-0.2); glColor3f(1.0,0.0,1.0); glVertex2f(0.0,0.2); glEnd(); glBegin(GL_POLYGON); glColor3f(0.0,1.0,1.0); glVertex2f(0.4,-0.4); glColor3f(1.0,0.0,0.0); glVertex2f(0.0,0.0); glColor3f(1.0,0.0,1.0); glVertex2f(0.4,0.4); glEnd(); glPopMatrix(); glFlush(); auxSwapBuffers(); } void CALLBACK stepDisplay (void) { step = step + 0.13; if (step >360.0) step = step -360.0; display(); } void main() { //初始化窗口(设置窗口的名称坐标尺寸和显示模式) auxInitDisplayMode(AUX_SINGLE|AUX_RGBA); auxInitPosition(0,0,600,600); auxInitWindow("openG"); glClearColor(0.0,0.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); auxIdleFunc (stepDisplay); auxMainLoop(display); }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。