OpenGL学习(1)基本概述
2016-08-15 00:40
176 查看
OpenGL学习(1)基本概述
(1)重写Rendar(渲染器), 重写三个方法:
a、onSurfaceCreated(GL10 gl, EGLConfig config); b、onSurfaceChanged(GL10 gl, int width, int height); c、 onDrawFrame(GL10 gl);
package com.example.mychapter2; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; import android.opengl.GLU; import android.opengl.GLSurfaceView.Renderer; public class GLRender implements Renderer { public void onDrawFrame(GL10 gl) { // TODO Auto-generated method stub // 首先清理屏幕 gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); // 设置模型视图矩阵 gl.glMatrixMode(GL10.GL_MODELVIEW); // 重置矩阵 gl.glLoadIdentity(); // 视点变换 GLU.gluLookAt(gl, 0, 0, 3, 0, 0, 0, 0, 1, 0); // ... } public void onSurfaceChanged(GL10 gl, int width, int height) { // TODO Auto-generated method stub float ratio = (float) width / height; // 设置视口(OpenGL场景的大小) gl.glViewport(0, 0, width, height); // 设置投影矩阵为透视投影 gl.glMatrixMode(GL10.GL_PROJECTION); // 重置投影矩阵(置为单位矩阵) gl.glLoadIdentity(); // 创建一个透视投影矩阵(设置视口大小) gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10); } public void onSurfaceCreated(GL10 gl, EGLConfig config) { // TODO Auto-generated method stub // 告诉系统需要对透视进行修正 gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST); // 设置清理屏幕的颜色 gl.glClearColor(0, 0, 0, 1); // 启用深度缓存 gl.glEnable(GL10.GL_DEPTH_TEST); } }
(2)创建一个GLSurfaceView
(a)创建一个GLSurfaceView实例mGLSurfaceView,(b)设置渲染器mGLSurfaceView.setRenderer(Render);
package com.example.mychapter2; import android.app.Activity; import android.opengl.GLSurfaceView; import android.os.Bundle; public class ChapterMain extends Activity { private GLSurfaceView mGLSurfaceView; /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 实例化GLSurfaceView mGLSurfaceView = new GLSurfaceView(this); // 设置渲染器 mGLSurfaceView.setRenderer(new GLRender()); setContentView(mGLSurfaceView); } protected void onResume() { super.onResume(); mGLSurfaceView.onResume(); } protected void onPause() { super.onPause(); mGLSurfaceView.onPause(); } }
相关文章推荐
- WML学习(一):概述和基本规则
- WML学习(一):概述和基本规则
- OpenGL学习笔记(12)基本光照
- 不要急,我与你一起学习JSP(二)――JSP的基本概述
- Android 五大基本组件学习之 概述
- WML学习(一):概述和基本规则
- MySql 基础学习笔记 1——概述与基本数据类型: 整型: 1)TINYINT 2)SMALLINT 3) MEDIUMINT 4)INT 5)BIGINT 主要是大小的区别 图 浮点型:命令
- javascript 学习一(概述+基本语法)
- 黑马程序员——学习笔记01.Java基本概述
- openGl学习之基本图元
- OpenGL学习笔记(5)3D基本概念
- 我与你一起学习JSP(二)——JSP的基本概述
- 不要急,我与你一起学习JSP(二)——JSP的基本概述
- OpenGL学习——基本概念和坐标变换
- OpenGL入门学习[九] OpenGL混合的基本知识
- OpenGL 学习1–OpenGL 概述
- 【OpenGL学习代码笔记之一】 基本形状绘制及动画初窥
- arm学习笔记一(arm概述及其基本编程模型)
- OPENGL学习系列——基本介绍
- opengl GLSL基本语法 学习 随笔二