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

opengl 矩阵变换

时间:2014-08-11 17:50:02      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:blog   http   color   os   io   2014   ar   cti   

#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);


}


bubuko.com,布布扣

 

 

opengl 矩阵变换,布布扣,bubuko.com

opengl 矩阵变换

标签:blog   http   color   os   io   2014   ar   cti   

原文地址:http://blog.csdn.net/u010296979/article/details/38495641

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