Projection and camera view in OpenGL ES 2.0
来源:互联网 发布:unix高级环境编程 编辑:程序博客网 时间:2024/05/24 05:52
在ES2.0的API中,你可以通过添加一个矩阵成员到顶点着色器来为你的图像对象应用一个投影和视点转换。通过这个添加的矩阵成员,你可以生成并且应用投影矩阵和视点转换到你的对象中
2、访问顶点着色器:在你的顶点着色器中创建了一个钩子来应用投影和视点转换后,你可以访问这个成员来应用投影和视点转换矩阵。如下的代码显示了如何修改GLSurfaceView.Renderer的onSurfaceCreate()方法来访问上面在顶点着色器中定义的矩阵变量。
3、创建投影和视图矩阵:为图像对象创建投影和视图矩阵。如下的代码演示了如何修改GLSurfaceView.Renderer的onSurfaceCreated()和onSurfaceChanged()方法来基于当前设备的屏幕尺寸来创建视图矩阵和投影矩阵。
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、访问顶点着色器:在你的顶点着色器中创建了一个钩子来应用投影和视点转换后,你可以访问这个成员来应用投影和视点转换矩阵。如下的代码显示了如何修改GLSurfaceView.Renderer的onSurfaceCreate()方法来访问上面在顶点着色器中定义的矩阵变量。
public void onSurfaceCreated(GL10 unused, EGLConfig config) { ... muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); ... }
3、创建投影和视图矩阵:为图像对象创建投影和视图矩阵。如下的代码演示了如何修改GLSurfaceView.Renderer的onSurfaceCreated()和onSurfaceChanged()方法来基于当前设备的屏幕尺寸来创建视图矩阵和投影矩阵。
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、应用投影矩阵和视点变换矩阵:要应用投影和视点变换,把矩阵叠加起来,然后把他们设置到顶点着色器。如下的代码演示了如何修改GLSurfaceView.Renderer的onDrawFrame()方法来合并上面创建的投影矩阵和视点矩阵并且把他们应用到要被渲染的图像对象。
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 ... }查看Displaying Graphics with OpenGL ES来查看一个完整的例子里面显示怎么样通过OpenGL ES 2.0来应用投影和视点变换。
0 0
- Projection and camera view in OpenGL ES 2.0
- Projection and camera view in OpenGL ES 1.0
- Displaying Graphics with OpenGL ES(四)——Applying Projection and Camera Views
- android opengl es:投影变换Projection
- projection and view matrices
- Isometric View and Isometric Projection
- OpenGL ES View Snapshot
- OpenGL ES View Snapshot
- OpenGL ES View Snapshot
- faster-alternatives-to-glreadpixels-and-glteximage2d-in-opengl-es
- Faster Alternatives to glReadPixels and glTexImage2D in OpenGL ES
- Clipping-planes in OpenGL ES 2.0
- openGL ES 2.0 Primitive Assembly and Rasterization
- openGL ES 2.0 fragment shader and framebuffer
- Android OpenGL ES 开发教程(17):投影变换Projection
- Android OpenGL ES 开发教程(17):投影变换Projection
- Android OpenGL ES 开发教程(17):投影变换Projection
- Android OpenGL ES 开发教程(17):投影变换Projection
- Singleton
- SPOJ 9894 Tichu ( 状态压缩 )
- ArcEngine 一些实现代码
- 页面滚动条去除与增加分析
- Ubuntu下安装C/C++开发环境【!!!有更新!!!Ubuntu14.10下使用eclipse搭建C语言开发环境】
- Projection and camera view in OpenGL ES 2.0
- AT&T汇编操作数指示符
- GIT和SVN之间的五个基本区别
- 第12周 项目4-银行系统(任务2)
- 【WebGL初学系列之四】纹理三角
- windows下忘记mysql超级管理员root密码的解决办法
- java Future 接口介绍
- 解决java.lang.IllegalArgumentException: pointerIndex out of range 或者 arrayindexoutofboundsexception的错误
- window下github上传markdown文件中文乱码