Android OpenGL ES基本用法(1),环境的搭建


目录


Android OpenGL ES 环境的搭建

第一步:继承GL SurfaceView 
OpenGL封装好的类,可以减少很多代码

第二步:实现接口GLSurfaceView.Render
渲染的接口

第三步:编写glsl脚本(render)
package com.jianji.delogo.Test.MediaCodec;

import android.content.Context;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;


public class GLTestView extends GLSurfaceView implements GLSurfaceView.Renderer {

    public GLTestView(Context context) {
        this(context, null);
    }

    public GLTestView(Context context, AttributeSet attrs) {
        super(context, attrs);
        //设置OpenGL的版本
        setEGLContextClientVersion(2);
        setRenderer(this);
    }


    /**
     * Called when the surface is created or recreated.
     */
    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {

    }

    /**
     * Called when the surface changed size.
     */
    @Override
    public void onSurfaceChanged(GL10 gl, int width, int height) {
        //设置大小位置
        GLES20.glViewport(0, 0, width, height);
    }

    /**
     * Called to draw the current frame.
     */
    @Override
    public void onDrawFrame(GL10 gl) {
        //清屏,清理掉颜色的缓冲区
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
        //设置清屏的颜色,这里是float颜色的取值范围的[0,1]
        GLES20.glClearColor(1.0f,0f,0f,1.0f);
    }
}

Android OpenGL ES基本用法(1),环境的搭建_第1张图片

你可能感兴趣的:(OpenGL,OpenGL)