opengl android入门,Android OpenGL入门之GLSurfaceView

本文介绍了Android中用于OpenGL渲染的GLSurfaceView。GLSurfaceView管理着一个用于显示OpenGL渲染的特殊Surface,并在单独的线程中进行渲染。使用步骤包括创建GLSurfaceView,设置版本号,处理生命周期,设置渲染器以及实现渲染接口的方法。GLSurfaceView通过EGL进行配置、上下文和表面的管理,涉及eglGetDisplay、eglInitialize、eglChooseConfig、eglCreateContext、eglCreateWindowSurface等多个关键方法。
摘要由CSDN通过智能技术生成

GLSurfaceView使用

OpenGL ES是是一个开源图形库,那么与之相关的需要一个东西去显示画面,在android里,opengl包里提供了一个View叫GLSurfaceView,它的定义如下:

An implementation of SurfaceView that uses the dedicated surface for

displaying OpenGL rendering.

它的特性如下:

Manages a surface, which is a special piece of memory that can be

composited into the Android view system.

Manages an EGL display, which enables OpenGL to render into a surface.

Accepts a user-provided Renderer object that does the actual rendering.

Renders on a dedicated thread to decouple rendering performance from the UI thread.

Supports both on-demand and continuous rendering.

Optionally wraps, traces, and/or error-checks the renderer's OpenGL calls.

可见系统已封装好一个View用于渲染画面并能进行相应设置。

使用步骤如下:

1.创建定义一个GLSurfaceView

2.调用GLSurfaceView的setEGLContextClientVersion设置版本号,可设为2

3.onResume 和 onPause分别调用GLSurfaceView相应的生命周期方法

4.调用GLSurfaceView的setRender设置自己实现GLSurfaceView.Render接口的类

5.Render接口有3个方法,分别是SurfaceCreated时候进行相应的初始化工作,SurfaceChange时候高宽的适配以及具体的DrawFrame方法

onSurfaceCreated(GL10 gl, EGLConfig config);

onSurfaceChan

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值