├── .gitignore
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── anandmuralidhar
│ │ └── glescontextandroid
│ │ ├── GLESContextActivity.java
│ │ ├── MyGLRenderer.java
│ │ └── MyGLSurfaceView.java
│ ├── jni
│ ├── glesNative
│ │ ├── glesNative.cpp
│ │ ├── glesNative.h
│ │ └── myLogger.h
│ └── jniCalls
│ │ ├── glesContextActivity.cpp
│ │ └── myGLRenderer.cpp
│ └── res
│ ├── layout
│ └── gl_context.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── native_app_glue
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ └── AndroidManifest.xml
├── ndk_helper
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ └── AndroidManifest.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | #built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 |
15 | # Local configuration file (sdk path, etc)
16 | local.properties
17 |
18 | # Windows thumbnail db
19 | Thumbs.db
20 |
21 | # OSX files
22 | .DS_Store
23 |
24 | # Eclipse project files
25 | .classpath
26 | .project
27 |
28 | # Android Studio
29 | *.iml
30 | .idea
31 | #.idea/workspace.xml - remove # and delete .idea if it better suit your needs.
32 | .gradle
33 | gradle.properties
34 | build
35 |
36 | libs
37 | obj
38 | assets
39 | drawable-temp
40 | import-summary.txt
41 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction, and
10 | distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright
13 | owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all other entities
16 | that control, are controlled by, or are under common control with that entity.
17 | For the purposes of this definition, "control" means (i) the power, direct or
18 | indirect, to cause the direction or management of such entity, whether by
19 | contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20 | outstanding shares, or (iii) beneficial ownership of such entity.
21 |
22 | "You" (or "Your") shall mean an individual or Legal Entity exercising
23 | permissions granted by this License.
24 |
25 | "Source" form shall mean the preferred form for making modifications, including
26 | but not limited to software source code, documentation source, and configuration
27 | files.
28 |
29 | "Object" form shall mean any form resulting from mechanical transformation or
30 | translation of a Source form, including but not limited to compiled object code,
31 | generated documentation, and conversions to other media types.
32 |
33 | "Work" shall mean the work of authorship, whether in Source or Object form, made
34 | available under the License, as indicated by a copyright notice that is included
35 | in or attached to the work (an example is provided in the Appendix below).
36 |
37 | "Derivative Works" shall mean any work, whether in Source or Object form, that
38 | is based on (or derived from) the Work and for which the editorial revisions,
39 | annotations, elaborations, or other modifications represent, as a whole, an
40 | original work of authorship. For the purposes of this License, Derivative Works
41 | shall not include works that remain separable from, or merely link (or bind by
42 | name) to the interfaces of, the Work and Derivative Works thereof.
43 |
44 | "Contribution" shall mean any work of authorship, including the original version
45 | of the Work and any modifications or additions to that Work or Derivative Works
46 | thereof, that is intentionally submitted to Licensor for inclusion in the Work
47 | by the copyright owner or by an individual or Legal Entity authorized to submit
48 | on behalf of the copyright owner. For the purposes of this definition,
49 | "submitted" means any form of electronic, verbal, or written communication sent
50 | to the Licensor or its representatives, including but not limited to
51 | communication on electronic mailing lists, source code control systems, and
52 | issue tracking systems that are managed by, or on behalf of, the Licensor for
53 | the purpose of discussing and improving the Work, but excluding communication
54 | that is conspicuously marked or otherwise designated in writing by the copyright
55 | owner as "Not a Contribution."
56 |
57 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58 | of whom a Contribution has been received by Licensor and subsequently
59 | incorporated within the Work.
60 |
61 | 2. Grant of Copyright License.
62 |
63 | Subject to the terms and conditions of this License, each Contributor hereby
64 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
65 | irrevocable copyright license to reproduce, prepare Derivative Works of,
66 | publicly display, publicly perform, sublicense, and distribute the Work and such
67 | Derivative Works in Source or Object form.
68 |
69 | 3. Grant of Patent License.
70 |
71 | Subject to the terms and conditions of this License, each Contributor hereby
72 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
73 | irrevocable (except as stated in this section) patent license to make, have
74 | made, use, offer to sell, sell, import, and otherwise transfer the Work, where
75 | such license applies only to those patent claims licensable by such Contributor
76 | that are necessarily infringed by their Contribution(s) alone or by combination
77 | of their Contribution(s) with the Work to which such Contribution(s) was
78 | submitted. If You institute patent litigation against any entity (including a
79 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a
80 | Contribution incorporated within the Work constitutes direct or contributory
81 | patent infringement, then any patent licenses granted to You under this License
82 | for that Work shall terminate as of the date such litigation is filed.
83 |
84 | 4. Redistribution.
85 |
86 | You may reproduce and distribute copies of the Work or Derivative Works thereof
87 | in any medium, with or without modifications, and in Source or Object form,
88 | provided that You meet the following conditions:
89 |
90 | You must give any other recipients of the Work or Derivative Works a copy of
91 | this License; and
92 | You must cause any modified files to carry prominent notices stating that You
93 | changed the files; and
94 | You must retain, in the Source form of any Derivative Works that You distribute,
95 | all copyright, patent, trademark, and attribution notices from the Source form
96 | of the Work, excluding those notices that do not pertain to any part of the
97 | Derivative Works; and
98 | If the Work includes a "NOTICE" text file as part of its distribution, then any
99 | Derivative Works that You distribute must include a readable copy of the
100 | attribution notices contained within such NOTICE file, excluding those notices
101 | that do not pertain to any part of the Derivative Works, in at least one of the
102 | following places: within a NOTICE text file distributed as part of the
103 | Derivative Works; within the Source form or documentation, if provided along
104 | with the Derivative Works; or, within a display generated by the Derivative
105 | Works, if and wherever such third-party notices normally appear. The contents of
106 | the NOTICE file are for informational purposes only and do not modify the
107 | License. You may add Your own attribution notices within Derivative Works that
108 | You distribute, alongside or as an addendum to the NOTICE text from the Work,
109 | provided that such additional attribution notices cannot be construed as
110 | modifying the License.
111 | You may add Your own copyright statement to Your modifications and may provide
112 | additional or different license terms and conditions for use, reproduction, or
113 | distribution of Your modifications, or for any such Derivative Works as a whole,
114 | provided Your use, reproduction, and distribution of the Work otherwise complies
115 | with the conditions stated in this License.
116 |
117 | 5. Submission of Contributions.
118 |
119 | Unless You explicitly state otherwise, any Contribution intentionally submitted
120 | for inclusion in the Work by You to the Licensor shall be under the terms and
121 | conditions of this License, without any additional terms or conditions.
122 | Notwithstanding the above, nothing herein shall supersede or modify the terms of
123 | any separate license agreement you may have executed with Licensor regarding
124 | such Contributions.
125 |
126 | 6. Trademarks.
127 |
128 | This License does not grant permission to use the trade names, trademarks,
129 | service marks, or product names of the Licensor, except as required for
130 | reasonable and customary use in describing the origin of the Work and
131 | reproducing the content of the NOTICE file.
132 |
133 | 7. Disclaimer of Warranty.
134 |
135 | Unless required by applicable law or agreed to in writing, Licensor provides the
136 | Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
137 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
138 | including, without limitation, any warranties or conditions of TITLE,
139 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
140 | solely responsible for determining the appropriateness of using or
141 | redistributing the Work and assume any risks associated with Your exercise of
142 | permissions under this License.
143 |
144 | 8. Limitation of Liability.
145 |
146 | In no event and under no legal theory, whether in tort (including negligence),
147 | contract, or otherwise, unless required by applicable law (such as deliberate
148 | and grossly negligent acts) or agreed to in writing, shall any Contributor be
149 | liable to You for damages, including any direct, indirect, special, incidental,
150 | or consequential damages of any character arising as a result of this License or
151 | out of the use or inability to use the Work (including but not limited to
152 | damages for loss of goodwill, work stoppage, computer failure or malfunction, or
153 | any and all other commercial damages or losses), even if such Contributor has
154 | been advised of the possibility of such damages.
155 |
156 | 9. Accepting Warranty or Additional Liability.
157 |
158 | While redistributing the Work or Derivative Works thereof, You may choose to
159 | offer, and charge a fee for, acceptance of support, warranty, indemnity, or
160 | other liability obligations and/or rights consistent with this License. However,
161 | in accepting such obligations, You may act only on Your own behalf and on Your
162 | sole responsibility, not on behalf of any other Contributor, and only if You
163 | agree to indemnify, defend, and hold each Contributor harmless for any liability
164 | incurred by, or claims asserted against, such Contributor by reason of your
165 | accepting any such warranty or additional liability.
166 |
167 | END OF TERMS AND CONDITIONS
168 |
169 | APPENDIX: How to apply the Apache License to your work
170 |
171 | To apply the Apache License to your work, attach the following boilerplate
172 | notice, with the fields enclosed by brackets "[]" replaced with your own
173 | identifying information. (Don't include the brackets!) The text should be
174 | enclosed in the appropriate comment syntax for the file format. We also
175 | recommend that a file or class name and description of purpose be included on
176 | the same "printed page" as the copyright notice for easier identification within
177 | third-party archives.
178 |
179 | Copyright [yyyy] [name of copyright owner]
180 |
181 | Licensed under the Apache License, Version 2.0 (the "License");
182 | you may not use this file except in compliance with the License.
183 | You may obtain a copy of the License at
184 |
185 | http://www.apache.org/licenses/LICENSE-2.0
186 |
187 | Unless required by applicable law or agreed to in writing, software
188 | distributed under the License is distributed on an "AS IS" BASIS,
189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190 | See the License for the specific language governing permissions and
191 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | GLESContextAndroid
2 | ==================
3 | This project sets up GLES context in Android, creates a native object, and renders to the display from native code. The rendering call simply changes the screen color to blue. OpenGL ES and GLSL versions are displayed on the screen using Java. We use an AsyncTask to communicate across GL and UI threads in Android.
4 |
5 | A blog describing this project:
6 | http://www.anandmuralidhar.com/blog/android/gles-context/
7 |
8 | License
9 | -------
10 |
11 | Copyright 2016 Anand Muralidhar
12 |
13 | Licensed to the Apache Software Foundation (ASF) under one or more contributor
14 | license agreements. See the NOTICE file distributed with this work for
15 | additional information regarding copyright ownership. The ASF licenses this
16 | file to you under the Apache License, Version 2.0 (the "License"); you may not
17 | use this file except in compliance with the License. You may obtain a copy of
18 | the License at
19 |
20 | http://www.apache.org/licenses/LICENSE-2.0
21 |
22 | Unless required by applicable law or agreed to in writing, software
23 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
25 | License for the specific language governing permissions and limitations under
26 | the License.
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | import org.apache.tools.ant.taskdefs.condition.Os
2 |
3 | apply plugin: 'com.android.model.application'
4 |
5 | model {
6 | android {
7 |
8 | // 23 = Android Marshmallow
9 | compileSdkVersion = 23
10 | buildToolsVersion = '23.0.2'
11 |
12 | defaultConfig {
13 | applicationId "com.anandmuralidhar.glescontextandroid"
14 | // assuming that device had Android KitKat (19) or above
15 | minSdkVersion.apiLevel = 19
16 | targetSdkVersion.apiLevel = 22
17 |
18 | // versionCode and versionName are relevant if you release the app on Google Play
19 | versionCode 1
20 | versionName "1.0"
21 | }
22 |
23 | ndk {
24 | platformVersion = 19
25 | moduleName = 'GLESNative' // this creates libGLESNative.so and should be loaded in Java
26 | toolchain = "gcc"
27 | stl = 'gnustl_static'
28 |
29 | // specify the path to jni code
30 | cppFlags.addAll(['-I' + file('src/main/jni/glesNative')])
31 |
32 | cppFlags.addAll(['-std=c++11', '-Wall', '-fno-exceptions', '-fno-rtti'])
33 | ldLibs.addAll(['android', 'log', 'EGL', 'GLESv2', "stdc++"])
34 | }
35 |
36 | sources {
37 | main {
38 | jni {
39 | dependencies {
40 | // we use some functions from ndk_helper to simplify native tasks
41 | project ':ndk_helper' linkage 'static'
42 | }
43 | source {
44 | srcDirs 'src/main/jni'
45 | }
46 | }
47 | jniLibs {}
48 | }
49 | }
50 |
51 | buildTypes {
52 | release {
53 | minifyEnabled = false
54 | proguardFiles.add(file('proguard-rules.txt'))
55 | }
56 | }
57 |
58 | }
59 | }
60 |
61 | dependencies {
62 | compile 'com.android.support:appcompat-v7:23.4.0'
63 | }
64 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/anand/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/anandmuralidhar/glescontextandroid/GLESContextActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Anand Muralidhar
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.anandmuralidhar.glescontextandroid;
18 |
19 | import android.app.Activity;
20 | import android.opengl.GLSurfaceView;
21 | import android.os.AsyncTask;
22 | import android.os.Bundle;
23 | import android.widget.TextView;
24 |
25 | public class GLESContextActivity extends Activity {
26 | private GLSurfaceView mGLView = null;
27 | private TextView mTextView = null;
28 | private native void CreateObjectNative();
29 | private native void DeleteObjectNative();
30 | private native String GetGLESVersionNative();
31 | private native boolean IsInitsDoneNative();
32 |
33 | @Override
34 | public void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 |
37 | // call the native constructors to create an object
38 | CreateObjectNative();
39 |
40 | // layout has only two components, a GLSurfaceView and a TextView
41 | setContentView(R.layout.gl_context);
42 | mGLView = (MyGLSurfaceView) findViewById (R.id.gl_surface_view);
43 | mTextView = (TextView) findViewById(R.id.gles_version_textbox);
44 | }
45 |
46 | @Override
47 | protected void onResume() {
48 |
49 | super.onResume();
50 |
51 | // Android suggests that we call onResume on GLSurfaceView
52 | if (mGLView != null) {
53 | mGLView.onResume();
54 | }
55 |
56 | new AsyncDisplayText().execute();
57 | }
58 |
59 | @Override
60 | protected void onPause() {
61 |
62 | super.onPause();
63 |
64 | // Android suggests that we call onPause on GLSurfaceView
65 | if(mGLView != null) {
66 | mGLView.onPause();
67 | }
68 | }
69 |
70 | @Override
71 | protected void onDestroy() {
72 |
73 | super.onDestroy();
74 |
75 | // We are exiting the activity, let's delete the native objects
76 | DeleteObjectNative();
77 |
78 | }
79 |
80 |
81 | // this task simply waits till all inits are completed in native code
82 | // then it displays the GLES version on the screen
83 | class AsyncDisplayText extends AsyncTask {
84 |
85 | @Override
86 | // this function executes on a background thread
87 | // hence we cannot make GL calls or manipulate UI elements here
88 | protected Integer doInBackground(Void... params) {
89 |
90 | // keep polling to check if native objects are initialized
91 | while(!IsInitsDoneNative()) {
92 | try {
93 | Thread.sleep(100);
94 | } catch (InterruptedException e) {
95 | e.printStackTrace();
96 | } catch (Exception e) {
97 | e.printStackTrace();
98 | }
99 | }
100 | return 0;
101 | }
102 |
103 | @Override
104 | // this function executes on the UI thread and we can modify UI elements
105 | protected void onPostExecute(Integer result) {
106 |
107 | // GLES version is displayed on the screen
108 | DisplayGLVersion(GetGLESVersionNative());
109 |
110 | }
111 | }
112 |
113 | void DisplayGLVersion(String GLVersionInfo) {
114 | if(mTextView != null) {
115 | mTextView.setText(GLVersionInfo);
116 | }
117 | }
118 |
119 | // load libGLESNative.so since it has all the native functions
120 | static {
121 | System.loadLibrary("GLESNative");
122 | }
123 | }
124 |
125 |
--------------------------------------------------------------------------------
/app/src/main/java/com/anandmuralidhar/glescontextandroid/MyGLRenderer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Anand Muralidhar
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.anandmuralidhar.glescontextandroid;
18 |
19 | import android.opengl.GLSurfaceView;
20 | import android.util.Log;
21 |
22 | import javax.microedition.khronos.egl.EGLConfig;
23 | import javax.microedition.khronos.opengles.GL10;
24 |
25 | class MyGLRenderer implements GLSurfaceView.Renderer {
26 |
27 | private native void DrawFrameNative();
28 | private native void SurfaceCreatedNative();
29 | private native void SurfaceChangedNative(int width, int height);
30 |
31 |
32 | public void onSurfaceCreated(GL10 gl, EGLConfig config) {
33 |
34 | // called when the surface is created or recreated
35 | // create (or recreate) native objects that are required for rendering
36 | Log.d("GLES", "onSurfaceCreated");
37 | SurfaceCreatedNative();
38 |
39 | }
40 |
41 | public void onDrawFrame(GL10 unused) {
42 |
43 | // called to draw the current frame
44 | // call the rendering functions in native
45 | DrawFrameNative();
46 |
47 | }
48 |
49 | public void onSurfaceChanged(GL10 unused, int width, int height) {
50 |
51 | // called after surface is created and GLES surface changes size
52 | // this can typically happen if device orientation changes
53 | // we need to set GLES viewport to handle the change in size
54 | Log.d("GLES", "onSurfaceChanged");
55 | SurfaceChangedNative(width, height);
56 |
57 | }
58 |
59 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/anandmuralidhar/glescontextandroid/MyGLSurfaceView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Anand Muralidhar
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.anandmuralidhar.glescontextandroid;
18 |
19 | import android.content.Context;
20 | import android.opengl.GLSurfaceView;
21 | import android.util.AttributeSet;
22 | import android.util.Log;
23 | import android.view.SurfaceHolder;
24 |
25 | class MyGLSurfaceView extends GLSurfaceView {
26 |
27 | private MyGLRenderer mRenderer;
28 |
29 | public MyGLSurfaceView(Context context, AttributeSet attrs) {
30 | super(context, attrs);
31 |
32 | try {
33 | // Create GLES context. Even though we are specifying OpenGL ES 2, it will try to
34 | // create the highest possible context on a phone
35 | setEGLContextClientVersion(2);
36 |
37 | // set our custom Renderer for drawing on the created SurfaceView
38 | mRenderer = new MyGLRenderer();
39 | setRenderer(mRenderer);
40 |
41 | // calls onDrawFrame(...) continuously
42 | setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
43 |
44 | } catch (Exception e) {
45 |
46 | // Trouble, something's wrong!
47 | Log.e("GLESNativeAndroid", "Unable to create GLES context!", e);
48 |
49 | }
50 |
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/jni/glesNative/glesNative.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Anand Muralidhar
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include "glesNative.h"
18 |
19 | /**
20 | * Checks for OpenGL errors.Very useful while debugging. Call it as often as required
21 | */
22 | void CheckGLError(std::string funcName){
23 |
24 | GLenum err = glGetError();
25 | if (err == GL_NO_ERROR) {
26 | return;
27 | } else {
28 | MyLOGF("[FAIL GL] %s", funcName.c_str());
29 | }
30 |
31 | switch(err) {
32 |
33 | case GL_INVALID_ENUM:
34 | MyLOGE("GL_INVALID_ENUM: GLenum argument out of range");
35 | break;
36 |
37 | case GL_INVALID_VALUE:
38 | MyLOGE("GL_INVALID_VALUE: numeric argument out of range");
39 | break;
40 |
41 | case GL_INVALID_OPERATION:
42 | MyLOGE("GL_INVALID_OPERATION: operation illegal in current state");
43 | break;
44 |
45 | case GL_INVALID_FRAMEBUFFER_OPERATION:
46 | MyLOGE("GL_INVALID_FRAMEBUFFER_OPERATION: framebuffer object is not complete");
47 | break;
48 |
49 | case GL_OUT_OF_MEMORY:
50 | MyLOGE( "GL_OUT_OF_MEMORY: not enough memory left to execute command");
51 | break;
52 |
53 | default:
54 | MyLOGE("unlisted error");
55 | break;
56 | }
57 | }
58 |
59 | /**
60 | * Class constructor
61 | */
62 | GLESNative::GLESNative() {
63 | initsDone = false;
64 | glesVersionInfo ="";
65 | }
66 |
67 | /**
68 | * Perform inits and set various GLES options before rendering image
69 | */
70 | void GLESNative::PerformGLInits() {
71 |
72 | // Black background
73 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
74 |
75 | // load the GLES version into a string
76 | std::ostringstream version_string;
77 | version_string << glGetString(GL_VERSION) << ", " << glGetString(GL_SHADING_LANGUAGE_VERSION);
78 | glesVersionInfo = std::string(version_string.str());
79 |
80 | // check if the device supports GLES 3 or GLES 2
81 | const char* versionStr = (const char*)glGetString(GL_VERSION);
82 | if (strstr(versionStr, "OpenGL ES 3.") && gl3stubInit()) {
83 | MyLOGD("Device supports GLES 3");
84 | } else {
85 | MyLOGD("Device supports GLES 2");
86 | }
87 |
88 | initsDone = true;
89 |
90 | CheckGLError("GLESNative::PerformGLInits");
91 | }
92 |
93 |
94 | void GLESNative::Render() {
95 |
96 | // blue background
97 | glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
98 |
99 | // clear the screen
100 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
101 |
102 | CheckGLError("GLESNative::Render");
103 |
104 | }
105 |
106 | void GLESNative::SetViewport(int width, int height) {
107 |
108 | // set the viewport
109 | // function is also called when user changes device orientation
110 | glViewport(0, 0, width, height);
111 |
112 | CheckGLError("GLESNative::SetViewport");
113 | }
114 |
--------------------------------------------------------------------------------
/app/src/main/jni/glesNative/glesNative.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Anand Muralidhar
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef GLESCONTEXTANDROID_GLES_CONTEXT_H
18 | #define GLESCONTEXTANDROID_GLES_CONTEXT_H
19 |
20 |
21 | #include "myLogger.h"
22 | #include
23 | #include
24 | #include
25 | #include "gl3stub.h"
26 | #include
27 | #include
28 |
29 | class GLESNative {
30 | public:
31 | GLESNative();
32 | void PerformGLInits();
33 | void Render();
34 | void SetViewport(int width, int height);
35 | bool IsInitsDone(){return initsDone;}
36 | std::string GetGLESVersionInfo() {return glesVersionInfo;}
37 |
38 | private:
39 | bool initsDone;
40 | std::string glesVersionInfo;
41 | };
42 |
43 | #endif //GLESCONTEXTANDROID_GLES_CONTEXT_H
44 |
--------------------------------------------------------------------------------
/app/src/main/jni/glesNative/myLogger.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Anand Muralidhar
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef GLESNATIVEANDROID_My_LOGGER_H
18 | #define GLESNATIVEANDROID_My_LOGGER_H
19 |
20 | #include
21 |
22 | #define LOG_TAG "GLESContextAndroid"
23 | #define MyLOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
24 | #define MyLOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
25 | #define MyLOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG,__VA_ARGS__)
26 | #define MyLOGI(...) __android_log_print(ANDROID_LOG_INFO , LOG_TAG,__VA_ARGS__)
27 | #define MyLOGW(...) __android_log_print(ANDROID_LOG_WARN , LOG_TAG,__VA_ARGS__)
28 | #define MyLOGF(...) __android_log_print(ANDROID_LOG_FATAL , LOG_TAG,__VA_ARGS__)
29 | #define MyLOGSIMPLE(...)
30 |
31 | #endif //GLESNATIVEANDROID_My_LOGGER_H
32 |
--------------------------------------------------------------------------------
/app/src/main/jni/jniCalls/glesContextActivity.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Anand Muralidhar
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 | #include "glesNative.h"
19 |
20 | #ifdef __cplusplus
21 | extern "C" {
22 | #endif
23 |
24 | GLESNative *gGlesObject;
25 |
26 | JNIEXPORT void JNICALL
27 | Java_com_anandmuralidhar_glescontextandroid_GLESContextActivity_CreateObjectNative(JNIEnv *env,
28 | jobject instance) {
29 | gGlesObject = new GLESNative();
30 |
31 | }
32 |
33 | JNIEXPORT void JNICALL
34 | Java_com_anandmuralidhar_glescontextandroid_GLESContextActivity_DeleteObjectNative(JNIEnv *env,
35 | jobject instance) {
36 | if (gGlesObject != NULL) {
37 | delete gGlesObject;
38 | }
39 | gGlesObject = NULL;
40 | }
41 |
42 | JNIEXPORT jboolean JNICALL
43 | Java_com_anandmuralidhar_glescontextandroid_GLESContextActivity_IsInitsDoneNative(JNIEnv *env,
44 | jobject instance) {
45 |
46 | if (gGlesObject == NULL || !gGlesObject->IsInitsDone()) {
47 | return JNI_FALSE;
48 | } else {
49 | return JNI_TRUE;
50 | }
51 |
52 | }
53 |
54 |
55 | JNIEXPORT jstring JNICALL
56 | Java_com_anandmuralidhar_glescontextandroid_GLESContextActivity_GetGLESVersionNative(JNIEnv *env,
57 | jobject instance) {
58 |
59 | std::string retValue = "";
60 | if (gGlesObject == NULL) {
61 | return env->NewStringUTF(retValue.c_str());
62 | }
63 | retValue = gGlesObject->GetGLESVersionInfo();
64 | return env->NewStringUTF(retValue.c_str());
65 | }
66 |
67 | #ifdef __cplusplus
68 | }
69 | #endif
70 |
--------------------------------------------------------------------------------
/app/src/main/jni/jniCalls/myGLRenderer.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 Anand Muralidhar
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 | #include "glesNative.h"
19 |
20 |
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | extern GLESNative *gGlesObject;
26 |
27 | JNIEXPORT void JNICALL
28 | Java_com_anandmuralidhar_glescontextandroid_MyGLRenderer_DrawFrameNative(JNIEnv *env,
29 | jobject instance) {
30 |
31 | if (gGlesObject == NULL) {
32 | return;
33 | }
34 | gGlesObject->Render();
35 |
36 | }
37 |
38 | JNIEXPORT void JNICALL
39 | Java_com_anandmuralidhar_glescontextandroid_MyGLRenderer_SurfaceCreatedNative(JNIEnv *env,
40 | jobject instance) {
41 |
42 | if (gGlesObject == NULL) {
43 | return;
44 | }
45 | gGlesObject->PerformGLInits();
46 |
47 | }
48 |
49 | JNIEXPORT void JNICALL
50 | Java_com_anandmuralidhar_glescontextandroid_MyGLRenderer_SurfaceChangedNative(JNIEnv *env,
51 | jobject instance,
52 | jint width,
53 | jint height) {
54 |
55 | if (gGlesObject == NULL) {
56 | return;
57 | }
58 | gGlesObject->SetViewport(width, height);
59 |
60 | }
61 |
62 | #ifdef __cplusplus
63 | }
64 | #endif
65 |
66 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/gl_context.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
10 |
11 |
12 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anandmuralidhar24/GLESContextAndroid/7c2a4c0d25c6960f8c6dfc7088f020fb08b7342e/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anandmuralidhar24/GLESContextAndroid/7c2a4c0d25c6960f8c6dfc7088f020fb08b7342e/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anandmuralidhar24/GLESContextAndroid/7c2a4c0d25c6960f8c6dfc7088f020fb08b7342e/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anandmuralidhar24/GLESContextAndroid/7c2a4c0d25c6960f8c6dfc7088f020fb08b7342e/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anandmuralidhar24/GLESContextAndroid/7c2a4c0d25c6960f8c6dfc7088f020fb08b7342e/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #FFFFFF
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | GLESContextAndroid
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath "com.android.tools.build:gradle-experimental:0.7.0-alpha4"
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anandmuralidhar24/GLESContextAndroid/7c2a4c0d25c6960f8c6dfc7088f020fb08b7342e/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/native_app_glue/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/native_app_glue/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.model.library'
2 |
3 | def ndkDir = System.getenv("ANDROID_NDK_HOME")
4 | def propertiesFile = project.rootProject.file('local.properties')
5 | if (propertiesFile.exists()) {
6 | Properties properties = new Properties()
7 | properties.load(propertiesFile.newDataInputStream())
8 | ndkDir = properties.getProperty('ndk.dir')
9 | }
10 |
11 | model {
12 | android {
13 | compileSdkVersion = 23
14 | buildToolsVersion = '23.0.2'
15 | defaultConfig.with {
16 | minSdkVersion.apiLevel = 9
17 | targetSdkVersion.apiLevel = 23
18 | versionCode = 1
19 | versionName = '0.0.1'
20 | }
21 | ndk {
22 | moduleName = 'native_app_glue'
23 | ldLibs.addAll(['log', 'android'])
24 | ldFlags.add('-c')
25 | }
26 | sources {
27 | main {
28 | jni {
29 | source {
30 | srcDir "${ndkDir}/sources/android/native_app_glue"
31 | }
32 | exportedHeaders {
33 | srcDir "${ndkDir}/sources/android/native_app_glue"
34 | }
35 | }
36 | }
37 | }
38 | }
39 | }
40 | dependencies {
41 | compile 'com.android.support:appcompat-v7:23.+'
42 | }
43 |
--------------------------------------------------------------------------------
/native_app_glue/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/anand/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/native_app_glue/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/ndk_helper/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/ndk_helper/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.model.library'
2 |
3 | def ndkDir = System.getenv("ANDROID_NDK_HOME")
4 | def propertiesFile = project.rootProject.file('local.properties')
5 | if (propertiesFile.exists()) {
6 | Properties properties = new Properties()
7 | properties.load(propertiesFile.newDataInputStream())
8 | ndkDir = properties.getProperty('ndk.dir')
9 | }
10 |
11 | model {
12 | android {
13 | compileSdkVersion = 23
14 | buildToolsVersion = '23.0.2'
15 | defaultConfig.with {
16 | minSdkVersion.apiLevel = 9
17 | targetSdkVersion.apiLevel = 23
18 | versionCode = 1
19 | versionName = '0.0.1'
20 | }
21 | ndk {
22 | moduleName = 'ndk_helper'
23 | stl = 'gnustl_static'
24 | ldLibs.addAll(['log', 'android', 'EGL', 'GLESv2'])
25 | ldFlags.add('-c')
26 | }
27 | sources {
28 | main {
29 | jni {
30 | source {
31 | srcDir "${ndkDir}/sources/android/ndk_helper"
32 | }
33 | exportedHeaders {
34 | srcDir "${ndkDir}/sources/android/ndk_helper"
35 | }
36 | dependencies {
37 | project ':native_app_glue' linkage 'static'
38 | }
39 | }
40 | }
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/ndk_helper/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/anand/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/ndk_helper/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':ndk_helper', ':native_app_glue'
2 |
--------------------------------------------------------------------------------