OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Template.cpp
Go to the documentation of this file.
1 /* Copyright (c) 2012-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 
31 #include <GLES2/gl2.h>
32 #include <GLES2/gl2ext.h>
33 
34 #include <cstdio>
35 #include <cstdlib>
36 
37 #include <jni.h>
38 #include <android/log.h>
39 
40 #include "Template.h"
41 #include "Text.h"
42 #include "AndroidPlatform.h"
43 
44 using std::string;
45 using namespace MaliSDK;
46 
47 /* Asset directories and filenames. */
48 string resourceDirectory = "/data/data/com.arm.malideveloper.openglessdk.template/";
49 
50 /* A text object to draw text on the screen.*/
52 
53 bool setupGraphics(int width, int height)
54 {
55  /* Initialize OpenGL ES. */
56  GL_CHECK(glEnable(GL_BLEND));
57  GL_CHECK(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
58 
59  /* Initialize the Text object and add some text. */
60  text = new Text(resourceDirectory.c_str(), width, height);
61 
62  text->addString(0, 0, "Template", 255, 255, 255, 255);
63 
64  /* Code to setup shaders, geometry, and to initialize OpenGL ES states. */
65 
66  return true;
67 }
68 
69 void renderFrame(void)
70 {
71  /* Code to draw one frame. */
72 
73  /* Draw fonts. */
74  text->draw();
75 }
76 
77 extern "C"
78 {
80  (JNIEnv *env, jclass jcls, jint width, jint height)
81  {
82  setupGraphics(width, height);
83  }
84 
86  (JNIEnv *env, jclass jcls)
87  {
88  renderFrame();
89  }
90 
92  (JNIEnv *, jclass)
93  {
94  delete text;
95  }
96 }
Functions for drawing text in OpenGL ES.
Definition: Text.h:44
bool setupGraphics(int width, int height)
Definition: Template.cpp:53
GLint GLsizei GLsizei height
Definition: gl2ext.h:179
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_template_Template_init(JNIEnv *env, jclass jcls, jint width, jint height)
Definition: Template.cpp:80
Text * text
Definition: Template.cpp:51
void addString(int xPosition, int yPosition, const char *string, int red, int green, int blue, int alpha)
Add a std::string to be drawn to the screen.
Definition: Text.cpp:157
string resourceDirectory
Definition: Template.cpp:48
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_template_Template_step(JNIEnv *env, jclass jcls)
Definition: Template.cpp:86
#define GL_CHECK(x)
Definition: AstcTextures.h:59
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_template_Template_uninit(JNIEnv *, jclass)
Definition: Template.cpp:92
GLint GLsizei width
Definition: gl2ext.h:179
void draw(void)
Draw the text to the screen.
Definition: Text.cpp:265
void renderFrame(void)
Definition: Template.cpp:69