Freehand line and a vibrato APP (1) acquaintance openGL ES

Nothing else to do, freehand line and a vibrato App, because it is written notes, the order will be somewhat chaotic, but basically divided into the following several steps

  • Use first met the openGL

  • Display camera

  • Record video

  • Add Features: Set video recording speed

  • Add features: a variety of special effects

Here is the opening

1. What is OpenGL?

Open Graphics Library

Industry-standard graphics space, is a cross-programming language, cross-platform, professional graphics programming (software) interface. It is a two-dimensional, three-dimensional images, it is a powerful, easy call the underlying graphics library.
Nothing to do with hardware. It can be portable between different platforms such as Windows, Linux, Mac, Android, IOS. Therefore, support for OpenGL software has good portability, you can get a very wide range of applications.

2.0 is currently widely supported

<uses-feature android:glEsVersion="0x00020000" android:required="true"/>

GLSurfaceView
inheritance to SurfaceView, its embedded surface responsible for OpenGL rendering.

  • Surface Management and EGL
  • Allows custom renderer (render).
  • Let renderer in a separate thread in operation, and the UI thread separation.
  • Rendering support on-demand (on-demand) and continuous rendering (continuous).

2. OpenGL rendering process

Sentence is the process to convert the information into a geometric grid consisting of one image.

Here Insert Picture Description

  1. Acquires vertex data, the vertex data is then passed to the vertex shader, primitive vertex position determination
  2. Element assembly for
  3. Rasterization
  4. Fragment shader processing the influence of light, shadows on the image to fill color, then each fragment is processed, the final frame buffer.

3. OpenGL coordinate system

openGL coordinate system

  • OpenGL world coordinates in the range [-1,1], for determining the shape in OpenGL, vertex position coordinates is given according to this coordinate
  • Texture coordinates, in the range [0,1], operating in the OpenGL texture, is operated according to this coordinate.
  • Android screen coordinates in the range [0,1], the device according to the coordinates of the screen, to display content in OpenGL.

4. Shader shader

  • Shader (Shader) applets running on the GPU
  • Vertex shader
    - How applet vertices, normals, and other data
  • Fragment shader
    - Effect of how to handle light, shadows, occlusion, and the like on the surface of the environment, the applet generates a final image,

5. GLSL

OpenGL Shading Language (OpenGL Shading Language)

type of data

float float
vec2 contains two floating-point data vector
vec4 vector contains four floating-point data
sampler2D 2D texture sampler (representing one texture)

Modifiers

attribute attribute variables. Only a vertex shader. The general use of vertex data represent some variables, such as: vertex coordinates, texture coordinates, colors and the like.
uniforms consistent variables. Values agree variables during execution shader is constant. And is different from the constant const, this value is not known at compile time is initialized by an external shader.
varying volatile variables. It is transferred to the data from the vertex shader variable fragment shader.

Built-in functions

Texture texture2D (sampler coordinates) sample designated position
texture2D (sampler, sample point coordinates)

Built-in variables

Vertex shader
gl_Position vec4 vertex position
fragment shader
gl_FragColor vec4 Color

other

precision lowp low precision
precision mediump accuracy in
precision highp precision

example:

// 把顶点坐标给这个变量, 确定要画画的形状
attribute vec4 vPosition;
//接收纹理坐标,接收采样器采样图片的坐标
attribute vec4 vCoord;
//变换矩阵, 需要将原本的vCoord(01,11,00,10) 与矩阵相乘 才能够得到 surfacetexure(特殊)的正确的采样坐标
uniform mat4 vMatrix;
//传给片元着色器 像素点
varying vec2 aCoord;
void main(){
    //内置变量 gl_Position ,我们把顶点数据赋值给这个变量 opengl就知道它要画什么形状了
    gl_Position = vPosition;
    // 进过测试 和设备有关
    aCoord = (vMatrix * vCoord).xy;
    //aCoord =  vec2((vCoord*vMatrix).x,(vCoord*vMatrix).y);
}
#extension GL_OES_EGL_image_external : require
//SurfaceTexture比较特殊
//float数据是什么精度的
precision mediump float;
//采样点的坐标
varying vec2 aCoord;
//采样器
uniform samplerExternalOES vTexture;
void main(){
    //变量 接收像素值
    // texture2D:采样器 采集 aCoord的像素
    //赋值给 gl_FragColor 就可以了
    gl_FragColor = texture2D(vTexture,aCoord);
}

Guess you like

Origin blog.csdn.net/u011077027/article/details/93379997