OpenGL的图形绘制






上述就是我们这次绘制的图形。
在工程中,main函数为我们程序的主要入口

下面主要解释下调用的函数
ChangeSize函数:主要是设置视口及投影方式(窗口更改大小,或刚刚创建时调用)
KeyPressFunc:针对除了特殊键(F1、F2.... 上、下、左、右...)的键的回调处理
SpecialKeys函数:对特殊键(F1、F2.... 上、下、左、右...)的回调处理
RenderScene函数:主要用于图形的绘制,可以系统触发,也可以开发者手动触发(glutPostRedisplay)
SetupRC函数:图形数据配置,类似于viewdidLoad中的配置等
函数调用流程:

ChangeSize函数:

//参数1:视角角度
//参数2:纵横比 = w/h
//参数3:近裁剪面距离
//参数4:远裁剪面距离
viewFrustum.SetPerspective(35.0f,float(w)/float(h),1.0f,500.0f);
RenderScene函数:

//压栈
modelViewMatrix.PushMatrix();
//还原到以前的模型视图矩阵(单位矩阵)
modelViewMatrix.PopMatrix();
上述两个函数需要成对出现,即压栈后必须有出栈
M3DMatrix44f mCamera;
cameraFrame.GetCameraMatrix(mCamera);
//矩阵乘以矩阵堆栈的顶部矩阵,相乘的结果随后简存储在堆栈的顶部
modelViewMatrix.MultMatrix(mCamera);
M3DMatrix44fmObjectFrame;
//只要使用 GetMatrix 函数就可以获取矩阵堆栈顶部的值,这个函数可以进行2次重载。用来使用GLShaderManager 的使用。或者是获取顶部矩阵的顶点副本数据
objectFrame.GetMatrix(mObjectFrame);
//矩阵乘以矩阵堆栈的顶部矩阵,相乘的结果随后简存储在堆栈的顶部
modelViewMatrix.MultMatrix(mObjectFrame);
/* GLShaderManager 中的Uniform 值——平面着色器
参数1:平面着色器
参数2:运行为几何图形变换指定一个 4 * 4变换矩阵
--transformPipeline.GetModelViewProjectionMatrix() 获取的
GetMatrix函数就可以获得矩阵堆栈顶部的值
参数3:颜色值(黑色)
*/
shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vBlack);