openGL学习笔记3

三、视口变换


相关函数

glLoadIdentity();
将当前的用户坐标系的原点移到了屏幕中心:类似于一个复位操作。

void gluLookAt(GLdouble eyex,GLdouble eyey,GLdouble eyez,GLdouble centerx,GLdouble centery,GLdouble centerz,GLdouble upx,GLdouble upy,GLdouble upz)
视点转换

glScalef(x,y,z)
对模型进行xyz方向上的压缩拉伸 

glViewport(0,0,GLsizei(w),GLsizei(h))
以左下角为原点选择绘图区域

glMatrixMode(GL_PROJECTION)
设置当前操作的矩阵 GL_PROJECTION为投影矩阵  GL_MODELVIEW 模型视图矩阵 


#include<Windows.h>
#include<gl\glut.h>
#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")

void init(void)
{
	glClearColor(0.0,0.0,0.0,0.0);
	glShadeModel(GL_FLAT);
}

void disply()
{

	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0,1.0,1.0);
	glLoadIdentity();//坐标系复位
	gluLookAt(0.0,0.0,5.0,0.0,0.0,0.0,0.0,1.0,0.0);//视点转换 
	glScalef(1.0,1.0,1.0);//模型在Y方向拉伸为原来的2倍
	glutWireCube(1.0);//绘制边长为1的线框立方体
	glFlush();
}

void reshape(int w,int h)
{
	glViewport(0,0,GLsizei(w),GLsizei(h));//以左下角为原点选择绘图区域
	glMatrixMode(GL_PROJECTION);//指定当前操作矩阵为投影矩阵
	glLoadIdentity();
	//glFrustum(-1.0,1.0,-1.0,1.0,1.5,20.0);//把当前矩阵转变成透视矩阵
	//gluPerspective(30,1.0,1.5,50);
	glOrtho(-1.0,1.0,-1.0,1.0,1.5,20);
	glMatrixMode(GL_MODELVIEW);//对模型视图矩阵进行操作
	 
}


int main(int argc, char** argv)
{
 glutInit(&argc,argv);
 glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);//指定显示模式
 glutInitWindowSize(500,500);//指定窗口大小
 glutInitWindowPosition(100,100);//指定窗口左上角位置
 glutCreateWindow("OpenGL");//创建窗口标题为OpenGL的窗口
 init();
 glutDisplayFunc(disply); 
 glutReshapeFunc(reshape);
 glutMainLoop();
 return 0;
}







你可能感兴趣的:(openGL学习笔记3)