要交关于openGL的作业了,所以就在网上找了一些教程,发现非常麻烦,就找了一本书看一看,顺便记录一些基本操作。
void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far);创建正投影裁剪区域。
在使用glOrtho之前,需要先对坐标系进行设置,将其调整为投影坐标系
glMatrixMode(GL_PROJECTED);
glLoadIdentity();
绘制正方形,并且在改变窗口大小时,维持形状不变
//first one
#include <GL\glut.h>
#include <GL\GL.h>
#include <iostream>
void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f, 0.0f, 0.0f);
glRectf(-25.0f, 25.0f, 25.0f, -25.0f);
glFlush();
}
void setUpRC(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
void ChangeSize(GLsizei w, GLsizei h)
{
GLfloat aspectRatio;
if (h == 0)h = 1;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);//重置坐标系统
glLoadIdentity();
aspectRatio = (GLfloat)w / (GLfloat)h;
if (w <= h)
glOrtho(-100.0, 100.0,
-100.0 / aspectRatio, 100.0 / aspectRatio, 1.0, -1.0);
//重新定义裁剪的区域,保持纵横比不变
else
glOrtho( -100.0 * aspectRatio, 100.0 * aspectRatio,
-100.0, 100.0, 1.0, -1.0);
std::cout << "w = " << w << "\th = " << h << std::endl;
glMatrixMode(GL_MODELVIEW); //以后的变换都将影响这个模型
glLoadIdentity();
}


5993

被折叠的 条评论
为什么被折叠?



