OpenGL ES 1.0与OpenGL ES 2.0投射和摄像视角代码区别
来源:互联网 发布:网络问卷调查技巧 编辑:程序博客网 时间:2024/05/16 16:58
OpenGL ES 1.0中的投射和摄像视角
1. 投射矩阵 - 使用几何学创建一个投射矩阵,用来计算对象的坐标,以便图像被以正确的比例绘制。下面的例子展示了如何基于屏幕尺寸比例创建一个投射矩阵,然后应用到OpenGL渲染环境中。
在ES2.0API中,先要添加一个矩阵成员到图像对象的顶点着色器中。
1. 添加矩阵到顶点着色器 - 下面的代码中包含uMVPMatrix成员,允许你应用投射和摄像视角矩阵到对象坐标中。
1. 投射矩阵 - 使用几何学创建一个投射矩阵,用来计算对象的坐标,以便图像被以正确的比例绘制。下面的例子展示了如何基于屏幕尺寸比例创建一个投射矩阵,然后应用到OpenGL渲染环境中。
public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); // make adjustments for screen ratio float ratio = (float) width / height; gl.glMatrixMode(GL10.GL_PROJECTION); // set matrix to projection mode gl.glLoadIdentity(); // reset the matrix to its default state gl.glFrustumf(-ratio, ratio, -1, 1, 3, 7); // apply the projection matrix }2. 摄像转换矩阵 - 一旦你已经使用投射矩阵调整了坐标系统,你也必须使用一个摄像视角。下面的例子展示了如何修改onDrawFrame()方法实现应用一个模式视图,然后使用GLU.gluLookAt()功能创建一个视角转换,类似一个拍摄点。
public void onDrawFrame(GL10 gl) { ... // Set GL_MODELVIEW transformation mode gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); // reset the matrix to its default state // When using GL_MODELVIEW, you must set the camera view GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f); ... }OpenGL ES 2.0中的投射和摄像视角
在ES2.0API中,先要添加一个矩阵成员到图像对象的顶点着色器中。
1. 添加矩阵到顶点着色器 - 下面的代码中包含uMVPMatrix成员,允许你应用投射和摄像视角矩阵到对象坐标中。
private final String vertexShaderCode = // This matrix member variable provides a hook to manipulate // the coordinates of objects that use this vertex shader "uniform mat4 uMVPMatrix; \n" + "attribute vec4 vPosition; \n" + "void main(){ \n" + // the matrix must be included as part of gl_Position " gl_Position = uMVPMatrix * vPosition; \n" + "} \n";2. 访问着色器矩阵 - 在顶点着色器中创建了一个钩子后,我们可以访问顶点着色器中的矩阵变量了。
public void onSurfaceCreated(GL10 unused, EGLConfig config) { ... muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); ... }3. 创建投射和摄像视角矩阵。
public void onSurfaceCreated(GL10 unused, EGLConfig config) { ... // Create a camera view matrix Matrix.setLookAtM(mVMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f); } public void onSurfaceChanged(GL10 unused, int width, int height) { GLES20.glViewport(0, 0, width, height); float ratio = (float) width / height; // create a projection matrix from device screen geometry Matrix.frustumM(mProjMatrix, 0, -ratio, ratio, -1, 1, 3, 7); }4. 应用投射和摄像视角矩阵
public void onDrawFrame(GL10 unused) { ... // Combine the projection and camera view matrices Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0); // Apply the combined projection and camera view transformations GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0); // Draw objects ... }
0 0
- OpenGL ES 1.0与OpenGL ES 2.0投射和摄像视角代码区别
- opengl 和opengl es 区别
- OpenGL Es 视角设定(glFrustum)
- OPENGL与OPENGL ES的区别
- OpenGL ES与OpenGL 的区别
- 关于OPENGL与OPENGL ES的区别
- openGL与openGL ES 的区别
- 关于OPENGL与OPENGL ES的区别
- OpenGL ES与OpenGL的区别
- OpenGL 和 OpenGL ES的一点区别
- OpenGL ES(4) - 应用投影和摄像视图
- OpenGL ES 1.x/OpenGL ES 2.0 区别
- OpenGL 和OpenGL ES简介
- Qt 与 OpenGL ES
- EGLSurfaces 和 OpenGL ES
- 并发和OpenGL ES
- OpenGLES/OpenGL 区别&OpenGL ES 1.x/OpenGL ES 2.0 区别
- OpenGLES/OpenGL 区别&OpenGL ES 1.x/OpenGL ES 2.0 区别
- 解决:“由于最小日志空间要求,无法收缩日志文件”
- JAVA初级掌握的J2SE知识(二)和Java核心的API
- [leetcode] 76. Minimum Window Substring 解题报告
- Java千百问_01基本概念(008)_jar是什么
- leetcode #82 in cpp
- OpenGL ES 1.0与OpenGL ES 2.0投射和摄像视角代码区别
- Error when loading the SDK:发现以元素 'd:skin' 开头的无效内容
- part2.内存管理先导知识
- 勾股定理一日一证连载18
- Docker In Action -- Notes
- FGPA 130实例-->problem 5.3~5.15
- 浏览器输入网址从FTP服务上下载文件
- 51nod 1138 连续整数的和
- 界面 API: 游戏商店新的合作方式