服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服务器之家 - 编程语言 - JAVA教程 - java基于OpenGL ES实现渲染实例

java基于OpenGL ES实现渲染实例

2019-12-23 15:24红薯 JAVA教程

这篇文章主要介绍了java基于OpenGL ES实现渲染,实例分析了OpenGL渲染操作的相关技巧,需要的朋友可以参考下

本文实例讲述了java基于OpenGL ES实现渲染的方法。分享给大家供大家参考。具体如下:

1. Run.java文件:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package net.obviam.opengl;
import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class Run extends Activity {
  /** The OpenGL view */
  private GLSurfaceView glSurfaceView;
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // requesting to turn the title OFF
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    // making it full screen
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
    // Initiate the Open GL view and
    // create an instance with this activity
    glSurfaceView = new GLSurfaceView(this);
    // set our renderer to be the main renderer with
    // the current activity context
    glSurfaceView.setRenderer(new GlRenderer());
    setContentView(glSurfaceView);
  }
  /** Remember to resume the glSurface */
  @Override
  protected void onResume() {
    super.onResume();
    glSurfaceView.onResume();
  }
  /** Also pause the glSurface */
  @Override
  protected void onPause() {
    super.onPause();
    glSurfaceView.onPause();
  }
}

2. GlRenderer.java文件:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLSurfaceView.Renderer;
public class GlRenderer implements Renderer {
  @Override
  public void onDrawFrame(GL10 gl) {
  }
  @Override
  public void onSurfaceChanged(GL10 gl, int width, int height) {
  }
  @Override
  public void onSurfaceCreated(GL10 gl, EGLConfig config) {
  }
}

希望本文所述对大家的java程序设计有所帮助。

延伸 · 阅读

精彩推荐