OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HighQualityTextRenderer.java
Go to the documentation of this file.
1 /* Copyright (c) 2013-2017, ARM Limited and Contributors
2  *
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge,
6  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 package com.arm.malideveloper.openglessdk.highqualitytextjava;
22 
24 
25 import javax.microedition.khronos.egl.EGLConfig;
26 import javax.microedition.khronos.opengles.GL10;
27 
28 import android.opengl.GLES20;
29 import android.opengl.GLSurfaceView;
30 
31 public class HighQualityTextRenderer implements GLSurfaceView.Renderer {
32 
33  private TextObject theTextObj = new TextObject();
34 
35  private float theViewportHeight = 0.0f;
36 
37  private boolean mustRebuildText = true;
38 
40  super();
41  }
42 
43  // Touch UP event occured
44  public void touchUp(float aX, float aY) {
45  mustRebuildText = true;
46  }
47 
48  // Touch UP event occured
49  public void touchMove(float aX, float aY,
50  float aPrevX, float aPrevY) {
51  theTextObj.setRelPos(0.0f, 0.0f, (aPrevY - aY)/(float)(theViewportHeight / 4));
52  }
53 
54  // Touch UP event occured
55  public void touchDown(float aX, float aY) {
56  }
57 
58  public void onSurfaceCreated(GL10 unused, EGLConfig config) {
59 
60  android.util.Log.i("INFO", "Extensions: " + GLES20.glGetString(GLES20.GL_EXTENSIONS));
61 
62  // Set the background frame color
63  GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
64 
65  /*
66  Just in case you would like to set UTF8 text as a string. Below is an example of chinese string converted to UTF8
67  char utf8Chars[] = {0xEF, 0xBB, 0xBF, 0xE6, 0x9C, 0xAC, 0xE7, 0xBD, 0x91, 0xE9, 0xA6, 0x96, 0xE9, 0xA1, 0xB5};
68  byte byteChars[] = new byte[utf8Chars.length];
69  for (int i = 0; i < utf8Chars.length; i++ )
70  byteChars[i] = (byte)utf8Chars[i];
71 
72  String str = null;
73  try {
74  str = new String(byteChars, "UTF8");
75  }
76  catch (Exception e) {
77  }
78  theTextObj.setText(str);
79  */
80 
81  // Initialize text object
82  theTextObj.init();
83  theTextObj.setText("A high text quality!");
84  theTextObj.setPosition(0.0f, 0.0f, -1.0f);
85 
86  checkGLError("onSurfaceCreated");
87 }
88 
89  public void onDrawFrame(GL10 unused) {
90 
91  // Redraw background color
92  GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
93 
94  // Render text object
95  theTextObj.render();
96 
97  if (mustRebuildText) {
98  theTextObj.update();
99  mustRebuildText = false;
100  }
101 
102  checkGLError("onDrawFrame");
103  }
104 
105  static public void checkGLError(final String aDesc) {
106  int errorCode = GLES20.GL_NO_ERROR;
107  do {
108  errorCode = GLES20.glGetError();
109  if (errorCode != GLES20.GL_NO_ERROR)
110  android.util.Log.i("ERROR", "GL error: " + aDesc + " errorCode:" + errorCode);
111  } while (errorCode != GLES20.GL_NO_ERROR);
112  }
113 
114  public void onSurfaceChanged(GL10 unused, int width, int height) {
116  // Update viewport
117  GLES20.glViewport(0, 0, width, height);
118  // Update Projection matrix
119  theTextObj.updateCamera(width, height);
120  }
121 }
GLint GLsizei GLsizei height
Definition: gl2ext.h:179
GLint GLsizei width
Definition: gl2ext.h:179