首页 > 代码库 > 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);


}