├── LICENSE
├── OpenGLGui
├── .gitignore
├── .idea
│ ├── .name
│ ├── compiler.xml
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── gradle.xml
│ ├── misc.xml
│ ├── modules.xml
│ ├── runConfigurations.xml
│ └── vcs.xml
├── OpenGLGui.iml
├── app
│ ├── .gitignore
│ ├── app.iml
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── graphics
│ │ │ └── openglgui
│ │ │ └── ApplicationTest.java
│ │ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ └── com
│ │ │ └── graphics
│ │ │ └── openglgui
│ │ │ ├── Cube.java
│ │ │ ├── Cube.java~
│ │ │ ├── GLView.java
│ │ │ ├── Mesh.java
│ │ │ ├── MeshViewActivity.java
│ │ │ ├── PlyParser.java
│ │ │ ├── shader.frag
│ │ │ ├── shader.frag~
│ │ │ ├── shader.vert
│ │ │ ├── shader.vert~
│ │ │ └── util
│ │ │ ├── SystemUiHider.java
│ │ │ ├── SystemUiHiderBase.java
│ │ │ └── SystemUiHiderHoneycomb.java
│ │ └── res
│ │ ├── layout
│ │ └── activity_fullscreen.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── raw
│ │ └── controller_ascii.ply
│ │ ├── values-v11
│ │ └── styles.xml
│ │ └── values
│ │ ├── attrs.xml
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
└── README.md
/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,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/OpenGLGui/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 | /captures
8 |
--------------------------------------------------------------------------------
/OpenGLGui/.idea/.name:
--------------------------------------------------------------------------------
1 | OpenGL Gui
--------------------------------------------------------------------------------
/OpenGLGui/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/OpenGLGui/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/OpenGLGui/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/OpenGLGui/.idea/misc.xml:
--------------------------------------------------------------------------------
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 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Android API 19 Platform
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/OpenGLGui/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/OpenGLGui/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/OpenGLGui/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/OpenGLGui/OpenGLGui.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/OpenGLGui/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/OpenGLGui/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | generateDebugAndroidTestSources
19 | generateDebugSources
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/OpenGLGui/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 21
5 | buildToolsVersion "22.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.graphics.openglgui"
9 | minSdkVersion 19
10 | targetSdkVersion 21
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'app/libs', include: ['*.jar'])
24 | compile 'com.android.support:appcompat-v7:21.0.3'
25 | compile 'com.android.support:support-v4:21.0.3'
26 | }
27 |
--------------------------------------------------------------------------------
/OpenGLGui/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/replica/RepLabs/android-studio-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 |
--------------------------------------------------------------------------------
/OpenGLGui/app/src/androidTest/java/com/graphics/openglgui/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.graphics.openglgui;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
9 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/java/com/graphics/openglgui/Cube.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Code to build a cube. Lots of help here from
3 | * http://bit.ly/1QPBhqK
4 | */
5 | package com.graphics.openglgui;
6 |
7 | import android.opengl.GLES20;
8 | import android.util.Log;
9 |
10 | import java.nio.ByteBuffer;
11 | import java.nio.ByteOrder;
12 | import java.nio.FloatBuffer;
13 |
14 | public class Cube {
15 | private FloatBuffer cubeBuffer;
16 | private int mMVPMatrixHandle;
17 | private int mPositionHandle;
18 | private int mColorHandle;
19 | private int[] bufferIdx;
20 | // number of coordinates per vertex in this array
21 | static final int BYTES_PER_FLOAT = 4;
22 | static final int COORDS_PER_VERTEX = 3;
23 | static final int COORDS_PER_COLOR = 4;
24 | private final int stride = (COORDS_PER_COLOR + COORDS_PER_VERTEX) * BYTES_PER_FLOAT;
25 | static final int CUBE_VERTICES = 36;
26 | static float cubeCoords[] = {
27 | -0.5f,-0.5f, 0.5f, 1,0,0,1,
28 | +0.5f,-0.5f, 0.5f, 1,0,0,1,
29 | -0.5f,+0.5f, 0.5f, 1,0,0,1,
30 | -0.5f,+0.5f, 0.5f, 1,0,0,1,
31 | +0.5f,-0.5f, 0.5f, 1,0,0,1,
32 | +0.5f,+0.5f, 0.5f, 1,0,0,1,
33 | // Back
34 | +0.5f,-0.5f,-0.5f, 0,0,1,1,
35 | -0.5f,-0.5f,-0.5f, 0,0,1,1,
36 | +0.5f,+0.5f,-0.5f, 0,0,1,1,
37 | +0.5f,+0.5f,-0.5f, 0,0,1,1,
38 | -0.5f,-0.5f,-0.5f, 0,0,1,1,
39 | -0.5f,+0.5f,-0.5f, 0,0,1,1,
40 | // Right
41 | +0.5f,-0.5f,+0.5f, 1,1,0,1,
42 | +0.5f,-0.5f,-0.5f, 1,1,0,1,
43 | +0.5f,+0.5f,+0.5f, 1,1,0,1,
44 | +0.5f,+0.5f,+0.5f, 1,1,0,1,
45 | +0.5f,-0.5f,-0.5f, 1,1,0,1,
46 | +0.5f,+0.5f,-0.5f, 1,1,0,1,
47 | // Left
48 | -0.5f,-0.5f,-0.5f, 0,1,0,1,
49 | -0.5f,-0.5f,+0.5f, 0,1,0,1,
50 | -0.5f,+0.5f,-0.5f, 0,1,0,1,
51 | -0.5f,+0.5f,-0.5f, 0,1,0,1,
52 | -0.5f,-0.5f,+0.5f, 0,1,0,1,
53 | -0.5f,+0.5f,+0.5f, 0,1,0,1,
54 | // Top
55 | -0.5f,+0.5f,+0.5f, 0,1,1,1,
56 | +0.5f,+0.5f,+0.5f, 0,1,1,1,
57 | -0.5f,+0.5f,-0.5f, 0,1,1,1,
58 | -0.5f,+0.5f,-0.5f, 0,1,1,1,
59 | +0.5f,+0.5f,+0.5f, 0,1,1,1,
60 | +0.5f,+0.5f,-0.5f, 0,1,1,1,
61 | // Bottom
62 | -0.5f,-0.5f,-0.5f, 1,0,1,1,
63 | +0.5f,-0.5f,-0.5f, 1,0,1,1,
64 | -0.5f,-0.5f,+0.5f, 1,0,1,1,
65 | -0.5f,-0.5f,+0.5f, 1,0,1,1,
66 | +0.5f,-0.5f,-0.5f, 1,0,1,1,
67 | +0.5f,-0.5f,+0.5f, 1,0,1,1,
68 | };
69 |
70 | public int loadShader(int type, final String shaderCode) {
71 | int shader = GLES20.glCreateShader(type);
72 | // add the source code to the shader and compile it
73 | GLES20.glShaderSource(shader, shaderCode);
74 | GLES20.glCompileShader(shader);
75 | int[] compiled = new int[1];
76 | GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
77 | if (compiled[0] == 0) {
78 | Log.e("Shader", "Could not compile shader " + type + ":");
79 | Log.e("Shader", GLES20.glGetShaderInfoLog(shader));
80 | GLES20.glDeleteShader(shader);
81 | shader = 0;
82 | }
83 | return shader;
84 | }
85 |
86 | protected String getVertexShaderCode() {
87 | final String code =
88 | "uniform mat4 uMVPMatrix;\n" +
89 | "attribute vec3 vPosition;\n" +
90 | "attribute vec4 vColor;\n" +
91 | "varying vec4 fColor;\n" +
92 | "void main() {\n" +
93 | " gl_Position = uMVPMatrix * vec4(vPosition, 1);\n" +
94 | " fColor = vColor;\n" +
95 | "}\n";
96 | return code;
97 | }
98 |
99 | protected String getFragmentShaderCode() {
100 | final String code =
101 | "precision mediump float;\n" +
102 | "varying vec4 fColor;\n" +
103 | "void main() {\n" +
104 | " gl_FragColor = fColor;\n" +
105 | "}\n";
106 | return code;
107 | }
108 |
109 | protected void checkGlError(String TAG, String op) {
110 | int error;
111 | while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
112 | Log.e(TAG, op + ": glError " + error);
113 | throw new RuntimeException(op + ": glError " + error);
114 | }
115 | }
116 |
117 | private final int mProgram;
118 | // Riffed off of the Android OpenGL ES 2.0 How-to page
119 | // http://bit.ly/1KVYlAx
120 | public Cube() {
121 | bufferIdx = new int[1];
122 | GLES20.glGenBuffers(1, bufferIdx, 0);
123 | cubeBuffer = ByteBuffer.allocateDirect(cubeCoords.length * BYTES_PER_FLOAT)
124 | .order(ByteOrder.nativeOrder())
125 | .asFloatBuffer();
126 | cubeBuffer.put(cubeCoords).position(0);
127 | Log.v("Cube Init", "I'm a warning!");
128 |
129 | GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, bufferIdx[0]);
130 | Log.v("Cube Init", "I'm a warning! 2");
131 | GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER,
132 | cubeBuffer.capacity() * BYTES_PER_FLOAT,
133 | cubeBuffer,
134 | GLES20.GL_STATIC_DRAW);
135 | Log.v("Cube Init", "I'm a warning! 3");
136 | GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
137 | Log.v("Cube Init", "Cube bound to buffer");
138 |
139 | // Get our shaders ready
140 | int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, getVertexShaderCode());
141 | int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, getFragmentShaderCode());
142 | mProgram = GLES20.glCreateProgram();
143 | // add the vertex shader to program
144 | GLES20.glAttachShader(mProgram, vertexShader);
145 | checkGlError("Cube", "glAttachShader");
146 |
147 | // add the fragment shader to program
148 | GLES20.glAttachShader(mProgram, fragmentShader);
149 | checkGlError("Cube", "glAttachShader");
150 |
151 | GLES20.glLinkProgram(mProgram);
152 | }
153 |
154 | private final int vertexCount = 36;
155 | public void draw(float[] mvpMatrix) {
156 | // Add program to OpenGL ES environment
157 | GLES20.glUseProgram(mProgram);
158 | // Position Buffer, passed into shader
159 | mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
160 | Log.i("Draw function: ", Integer.toString(mPositionHandle));
161 | GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, bufferIdx[0]);
162 | GLES20.glEnableVertexAttribArray(mPositionHandle);
163 | GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX,
164 | GLES20.GL_FLOAT, false, stride, 0);
165 | // Color Buffer, passed into shader
166 | mColorHandle = GLES20.glGetAttribLocation(mProgram, "vColor");
167 | GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, bufferIdx[0]);
168 | GLES20.glEnableVertexAttribArray(mColorHandle);
169 | GLES20.glVertexAttribPointer(mColorHandle, COORDS_PER_COLOR,
170 | GLES20.GL_FLOAT, false, stride, COORDS_PER_VERTEX * BYTES_PER_FLOAT);
171 | // get handle to shape's transformation matrix
172 | mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
173 | // Pass the projection and view transformation to the shader
174 | GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
175 | // Draw the triangle
176 | GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount);
177 | // Disable vertex array
178 | GLES20.glDisableVertexAttribArray(mPositionHandle);
179 | GLES20.glDisableVertexAttribArray(mColorHandle);
180 | GLES20.glFlush();
181 | }
182 | }
183 |
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/java/com/graphics/openglgui/Cube.java~:
--------------------------------------------------------------------------------
1 | /*
2 | * Code to build a cube. Lots of help here from
3 | * http://bit.ly/1QPBhqK
4 | */
5 | package com.graphics.openglgui;
6 |
7 | import android.opengl.GLES20;
8 | import android.util.Log;
9 | import java.nio.FloatBuffer;
10 | import java.nio.ByteBuffer;
11 | import java.nio.ByteOrder;
12 |
13 | public class Cube {
14 | private FloatBuffer vertexBuffer;
15 | private FloatBuffer colorBuffer;
16 | private int mMVPMatrixHandle;
17 | private int mPositionHandle;
18 | private int mColorHandle;
19 | private int[] buffers;
20 | // number of coordinates per vertex in this array
21 | static final int COORDS_PER_VERTEX = 3;
22 | static float cubeCoords[] = {
23 | -0.5f,-0.5f, 0.5f,
24 | +0.5f,-0.5f, 0.5f,
25 | -0.5f,+0.5f, 0.5f,
26 | -0.5f,+0.5f, 0.5f,
27 | +0.5f,-0.5f, 0.5f,
28 | +0.5f,+0.5f, 0.5f,
29 | // Back
30 | +0.5f,-0.5f,-0.5f,
31 | -0.5f,-0.5f,-0.5f,
32 | +0.5f,+0.5f,-0.5f,
33 | +0.5f,+0.5f,-0.5f,
34 | -0.5f,-0.5f,-0.5f,
35 | -0.5f,+0.5f,-0.5f,
36 | // Right
37 | +0.5f,-0.5f,+0.5f,
38 | +0.5f,-0.5f,-0.5f,
39 | +0.5f,+0.5f,+0.5f,
40 | +0.5f,+0.5f,+0.5f,
41 | +0.5f,-0.5f,-0.5f,
42 | +0.5f,+0.5f,-0.5f,
43 | // Left
44 | -0.5f,-0.5f,-0.5f,
45 | -0.5f,-0.5f,+0.5f,
46 | -0.5f,+0.5f,-0.5f,
47 | -0.5f,+0.5f,-0.5f,
48 | -0.5f,-0.5f,+0.5f,
49 | -0.5f,+0.5f,+0.5f,
50 | // Top
51 | -0.5f,+0.5f,+0.5f,
52 | +0.5f,+0.5f,+0.5f,
53 | -0.5f,+0.5f,-0.5f,
54 | -0.5f,+0.5f,-0.5f,
55 | +0.5f,+0.5f,+0.5f,
56 | +0.5f,+0.5f,-0.5f,
57 | // Bottom
58 | -0.5f,-0.5f,-0.5f,
59 | +0.5f,-0.5f,-0.5f,
60 | -0.5f,-0.5f,+0.5f,
61 | -0.5f,-0.5f,+0.5f,
62 | +0.5f,-0.5f,-0.5f,
63 | +0.5f,-0.5f,+0.5f,
64 | };
65 |
66 | static float cubeColors[] = {
67 | 1,0,0,1,
68 | 1,0,0,1,
69 | 1,0,0,1,
70 | 1,0,0,1,
71 | 1,0,0,1,
72 | 1,0,0,1,
73 |
74 | 0,0,1,1,
75 | 0,0,1,1,
76 | 0,0,1,1,
77 | 0,0,1,1,
78 | 0,0,1,1,
79 | 0,0,1,1,
80 |
81 | 1,1,0,1,
82 | 1,1,0,1,
83 | 1,1,0,1,
84 | 1,1,0,1,
85 | 1,1,0,1,
86 | 1,1,0,1,
87 |
88 | 0,1,0,1,
89 | 0,1,0,1,
90 | 0,1,0,1,
91 | 0,1,0,1,
92 | 0,1,0,1,
93 | 0,1,0,1,
94 |
95 | 0,1,1,1,
96 | 0,1,1,1,
97 | 0,1,1,1,
98 | 0,1,1,1,
99 | 0,1,1,1,
100 | 0,1,1,1,
101 |
102 | 1,0,1,1,
103 | 1,0,1,1,
104 | 1,0,1,1,
105 | 1,0,1,1,
106 | 1,0,1,1,
107 | 1,0,1,1,
108 | };
109 |
110 | public int loadShader(int type, String shaderCode) {
111 | // create a vertex shader type (GLES20.GL_VERTEX_SHADER)
112 | // or a fragment shader type (GLES20.GL_FRAGMENT_SHADER)
113 | int shader = GLES20.glCreateShader(type);
114 | // add the source code to the shader and compile it
115 | GLES20.glShaderSource(shader, shaderCode);
116 | GLES20.glCompileShader(shader);
117 | return shader;
118 | }
119 |
120 | private final String vertexShaderCode =
121 | // This matrix member variable provides a hook to manipulate
122 | // the coordinates of the objects that use this vertex shader
123 | "uniform mat4 uMVPMatrix;" +
124 | "attribute vec4 vPosition;" +
125 | "void main() {" +
126 | // the matrix must be included as a modifier of gl_Position
127 | // Note that the uMVPMatrix factor *must be first* in order
128 | // for the matrix multiplication product to be correct.
129 | " gl_Position = uMVPMatrix * vPosition;" +
130 | "}";
131 |
132 | private final String fragmentShaderCode =
133 | "precision mediump float;" +
134 | "attribute vec4 vColor;" +
135 | "void main() {" +
136 | " gl_FragColor = vColor;" +
137 | "}";
138 |
139 | private final int mProgram;
140 |
141 | // Riffed off of the Android OpenGL ES 2.0 How-to page
142 | // http://bit.ly/1KVYlAx
143 | public Cube() {
144 | buffers = new int[3];
145 | vertexBuffer = ByteBuffer.allocateDirect(cubeCoords.length * 4)
146 | .order(ByteOrder.nativeOrder())
147 | .asFloatBuffer();
148 | vertexBuffer.put(cubeCoords).position(0);
149 | Log.v("Cube Init", "I'm a warning!");
150 | Log.v("Cube Init", "Coord Buffer capacity: " + vertexBuffer.capacity());
151 |
152 | GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[0]);
153 | Log.v("Cube Init", "I'm a warning! 2");
154 | GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER,
155 | vertexBuffer.capacity(),
156 | vertexBuffer,
157 | GLES20.GL_STATIC_DRAW);
158 | Log.v("Cube Init", "I'm a warning! 3");
159 | GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
160 | Log.v("Cube Init", "Position bound");
161 | colorBuffer = ByteBuffer.allocateDirect(cubeColors.length * 4)
162 | .order(ByteOrder.nativeOrder())
163 | .asFloatBuffer();
164 | colorBuffer.put(cubeColors).position(0);
165 | Log.v("Cube Init", "Color Buffer capacity: " + colorBuffer.capacity());
166 | GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[1]);
167 | GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER,
168 | colorBuffer.capacity(),
169 | colorBuffer,
170 | GLES20.GL_STATIC_DRAW);
171 | GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
172 | Log.v("Cube Init", "Color bound");
173 |
174 | // Get our shaders ready
175 | int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER,
176 | vertexShaderCode);
177 | int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER,
178 | fragmentShaderCode);
179 | mProgram = GLES20.glCreateProgram();
180 | // add the vertex shader to program
181 | GLES20.glAttachShader(mProgram, vertexShader);
182 | // add the fragment shader to program
183 | GLES20.glAttachShader(mProgram, fragmentShader);
184 | // creates OpenGL ES program executables
185 | GLES20.glBindAttribLocation(mProgram, 0, "vPosition");
186 | GLES20.glBindAttribLocation(mProgram, 1, "vColor");
187 | GLES20.glLinkProgram(mProgram);
188 | }
189 |
190 | private final int vertexCount = 36;
191 | public void draw(float[] mvpMatrix) {
192 | // Add program to OpenGL ES environment
193 | GLES20.glUseProgram(mProgram);
194 | // Position Buffer, passed into shader
195 | // GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[0]);
196 | mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
197 | GLES20.glEnableVertexAttribArray(mPositionHandle);
198 | GLES20.glVertexAttribPointer(mPositionHandle, 3,
199 | GLES20.GL_FLOAT, false,
200 | 0, vertexBuffer);
201 | // Color Buffer, passed into shader
202 | // GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[1]);
203 | Log.v("Draw", "we're doing things!");
204 | mColorHandle = GLES20.glGetAttribLocation(mProgram, "vColor");
205 | GLES20.glEnableVertexAttribArray(mColorHandle);
206 | GLES20.glVertexAttribPointer(mColorHandle, 4,
207 | GLES20.GL_FLOAT, false,
208 | 0, colorBuffer);
209 | // get handle to shape's transformation matrix
210 | mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
211 | // Pass the projection and view transformation to the shader
212 | GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
213 | // Draw the triangle
214 | GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount);
215 | // Disable vertex array
216 | GLES20.glDisableVertexAttribArray(mPositionHandle);
217 | GLES20.glDisableVertexAttribArray(mColorHandle);
218 | GLES20.glFlush();
219 | }
220 | }
221 |
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/java/com/graphics/openglgui/GLView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Example 10: Surface view
3 | * These sites were incredibly useful while learning this task:
4 | * http://androidbook.com/item/4231
5 | * http://www.learnopengles.com/tag/vertex-shader/
6 | * http://www.learnopengles.com/tag/vertex-shader/
7 | * http://developer.android.com/training/graphics/opengl/touch.html
8 | */
9 |
10 | package com.graphics.openglgui;
11 |
12 | import android.content.Context;
13 | import android.opengl.GLES20;
14 | import android.opengl.GLSurfaceView;
15 | import android.opengl.Matrix;
16 | import android.util.AttributeSet;
17 | import android.view.MotionEvent;
18 | import android.view.ScaleGestureDetector;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 |
23 | import javax.microedition.khronos.egl.EGLConfig;
24 | import javax.microedition.khronos.opengles.GL10;
25 |
26 | class GLView extends GLSurfaceView {
27 | private Renderer renderer;
28 | ScaleGestureDetector SGD;
29 | private float mPreviousX;
30 | private float mPreviousY;
31 |
32 | // Constructor
33 | public GLView(Context context, AttributeSet attributeSet) {
34 | super(context, attributeSet);
35 | // Create an OpenGL ES 2.0 context
36 | setEGLContextClientVersion(2);
37 | // Set the Renderer for drawing on the GLSurfaceView
38 | renderer = new Renderer(context);
39 | setRenderer(renderer);
40 | SGD = new ScaleGestureDetector(context, new ScaleListener());
41 | }
42 |
43 | private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
44 | @Override
45 | public boolean onScale(ScaleGestureDetector detector) {
46 | renderer.scale *= detector.getScaleFactor();
47 | return true;
48 | }
49 | }
50 |
51 | @Override
52 | public boolean onTouchEvent(MotionEvent e) {
53 | // MotionEvent reports input details from the touch screen
54 | // and other input controls. In this case, you are only
55 | // interested in events where the touch position changed.
56 | float x = e.getX();
57 | float y = e.getY();
58 | int motionaction = e.getAction() & MotionEvent.ACTION_MASK;
59 | switch (motionaction) {
60 | case MotionEvent.ACTION_DOWN:
61 | // Prevent jumping around.
62 | mPreviousX = x;
63 | mPreviousY = y;
64 | break;
65 | case MotionEvent.ACTION_MOVE:
66 | if (renderer != null) {
67 | float deltaX = (x - mPreviousX) / 2f;
68 | float deltaY = (y - mPreviousY) / 2f;
69 | renderer.mDeltaX += deltaX;
70 | renderer.mDeltaY += deltaY;
71 | }
72 | mPreviousX = x;
73 | mPreviousY = y;
74 | break;
75 | }
76 | SGD.onTouchEvent(e);
77 | return true;
78 | }
79 |
80 | // Called when reset button is pressed.
81 | public void Reset() {
82 | renderer.scale = 1;
83 | Matrix.setIdentityM(renderer.mAccumulatedRotation, 0);
84 | }
85 |
86 | public static class Renderer implements GLSurfaceView.Renderer {
87 | private Cube cube;
88 | private Mesh mesh;
89 | // Intrinsic Matrices
90 | private final float[] mModelMatrix = new float[16];
91 | private final float[] mViewMatrix = new float[16];
92 | // Projection matrix is set in onSurfaceChanged()
93 | private final float[] mProjectionMatrix = new float[16];
94 | private final float[] mMVPMatrix = new float[16];
95 | // Rotations for our touch movements
96 | private final float[] mAccumulatedRotation = new float[16];
97 | private final float[] mCurrentRotation = new float[16];
98 | public volatile float mDeltaX;
99 | public volatile float mDeltaY;
100 | public volatile float scale = 1;
101 | public Context current_context;
102 | private InputStream plyInput;
103 |
104 |
105 | public Renderer(Context context) {
106 | current_context = context;
107 | // Just in case we don't use the PLY in the future,
108 | // we need to give the user the option of switching out.
109 | plyInput = context.getResources().openRawResource(R.raw.controller_ascii);
110 | }
111 |
112 | public void onSurfaceCreated(GL10 gl,EGLConfig config) {
113 | GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.4f);
114 | // Initialize the accumulated rotation matrix
115 | Matrix.setIdentityM(mAccumulatedRotation, 0);
116 | // TODO(bminortx): put in loader for mesh
117 | cube = new Cube();
118 | try {
119 | mesh = new Mesh(plyInput);
120 | } catch (IOException e) {
121 | e.printStackTrace();
122 | }
123 | try {
124 | mesh.createProgram();
125 | } catch (IOException e) {
126 | e.printStackTrace();
127 | }
128 | }
129 |
130 | public void onDrawFrame(GL10 gl) {
131 | float[] mTemporaryMatrix = new float[16];
132 | GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
133 | // Model, View, and Projection
134 | Matrix.setIdentityM(mModelMatrix, 0);
135 | Matrix.scaleM(mModelMatrix, 0, scale, scale, scale);
136 | Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
137 | // Set a matrix that contains the current rotation.
138 | // Code below adapted from http://www.learnopengles.com/rotating-an-object-with-touch-events/
139 | Matrix.setIdentityM(mCurrentRotation, 0);
140 | Matrix.rotateM(mCurrentRotation, 0, mDeltaX, 0.0f, 1.0f, 0.0f);
141 | Matrix.rotateM(mCurrentRotation, 0, mDeltaY, -1.0f, 0.0f, 0.0f);
142 | mDeltaX = 0.0f;
143 | mDeltaY = 0.0f;
144 | // Multiply the current rotation by the accumulated rotation,
145 | // and then set the accumulated rotation to the result.
146 | Matrix.multiplyMM(mTemporaryMatrix, 0,
147 | mCurrentRotation, 0,
148 | mAccumulatedRotation, 0);
149 | System.arraycopy(mTemporaryMatrix, 0,
150 | mAccumulatedRotation, 0, 16);
151 | // Rotate the cube taking the overall rotation into account.
152 | Matrix.multiplyMM(mTemporaryMatrix, 0,
153 | mModelMatrix, 0,
154 | mAccumulatedRotation, 0);
155 | System.arraycopy(mTemporaryMatrix, 0, mModelMatrix, 0, 16);
156 | // Calculate the projection and view transformation
157 | Matrix.multiplyMM(mTemporaryMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
158 | Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mTemporaryMatrix, 0);
159 | // Draw shape
160 | mesh.draw(mMVPMatrix);
161 | }
162 |
163 | public void onSurfaceChanged(GL10 gl,int width,int height) {
164 | GLES20.glViewport(0, 0, width, height);
165 | float ratio = (float) width / height;
166 | // this projection matrix is applied to object coordinates
167 | // in the onDrawFrame() method
168 | Matrix.frustumM(mProjectionMatrix, 0, -ratio, ratio, -1, 1, 1, 100);
169 | }
170 | }
171 | }
172 |
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/java/com/graphics/openglgui/Mesh.java:
--------------------------------------------------------------------------------
1 | /*
2 | See this link for more info:
3 | http://www.learnopengles.com/android-lesson-eight-an-introduction-to-index-buffer-objects-ibos/
4 | */
5 |
6 | package com.graphics.openglgui;
7 |
8 | import android.opengl.GLES20;
9 | import android.util.Log;
10 |
11 | import java.io.IOException;
12 | import java.io.InputStream;
13 | import java.nio.ByteBuffer;
14 | import java.nio.ByteOrder;
15 | import java.nio.FloatBuffer;
16 | import java.nio.IntBuffer;
17 |
18 | /**
19 | * Created by replica on 10/8/15.
20 | */
21 | public class Mesh {
22 | private int mMVPMatrixHandle;
23 | private int mPositionHandle;
24 | private int mColorHandle;
25 | private int[] bufferIdx;
26 | private int vertexCount;
27 | private int facesCount;
28 | private FloatBuffer meshBuffer;
29 | private FloatBuffer colorBuffer;
30 | private IntBuffer facesBuffer;
31 | private PlyParser parser;
32 | private int mProgram;
33 | // number of coordinates per vertex in this array
34 | static final int BYTES_PER_FLOAT = 4;
35 | static final int BYTES_PER_SHORT = 2;
36 | static final int COORDS_PER_VERTEX = 3;
37 | static final int COORDS_PER_COLOR = 4;
38 | private final int stride = (COORDS_PER_COLOR + COORDS_PER_VERTEX) * BYTES_PER_FLOAT;
39 |
40 | public int loadShader(int type, final String shaderCode) {
41 | int shader = GLES20.glCreateShader(type);
42 | // add the source code to the shader and compile it
43 | GLES20.glShaderSource(shader, shaderCode);
44 | GLES20.glCompileShader(shader);
45 | int[] compiled = new int[1];
46 | GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
47 | if (compiled[0] == 0) {
48 | Log.e("Shader", "Could not compile shader " + type + ":");
49 | Log.e("Shader", GLES20.glGetShaderInfoLog(shader));
50 | GLES20.glDeleteShader(shader);
51 | shader = 0;
52 | }
53 | return shader;
54 | }
55 |
56 | protected String getVertexShaderCode() {
57 | final String code =
58 | "uniform mat4 uMVPMatrix;\n" +
59 | "attribute vec3 vPosition;\n" +
60 | "attribute vec4 vColor;\n" +
61 | "varying vec4 fColor;\n" +
62 | "void main() {\n" +
63 | " gl_Position = uMVPMatrix * vec4(vPosition, 1);\n" +
64 | " fColor = vColor;\n" +
65 | "}\n";
66 | return code;
67 | }
68 |
69 | protected String getFragmentShaderCode() {
70 | final String code =
71 | "precision mediump float;\n" +
72 | "varying vec4 fColor;\n" +
73 | "void main() {\n" +
74 | " gl_FragColor = fColor;\n" +
75 | "}\n";
76 | return code;
77 | }
78 |
79 | protected void checkGlError(String TAG, String op) {
80 | int error;
81 | while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
82 | Log.e(TAG, op + ": glError " + error);
83 | throw new RuntimeException(op + ": glError " + error);
84 | }
85 | }
86 |
87 | // Riffed off of the Android OpenGL ES 2.0 How-to page
88 | // http://bit.ly/1KVYlAx
89 | public Mesh(InputStream ply_file) throws IOException {
90 | parser = new PlyParser(ply_file);
91 | }
92 |
93 | public boolean createProgram() throws IOException {
94 | if (!parser.ParsePly()) {
95 | // It's not a PLY, so don't go any farther
96 | return false;
97 | }
98 | vertexCount = parser.getVertexCount();
99 | facesCount = parser.getFaceCount();
100 | bufferIdx = new int[3];
101 | GLES20.glGenBuffers(3, bufferIdx, 0);
102 | meshBuffer = ByteBuffer.allocateDirect(parser.getVertices().length * BYTES_PER_FLOAT)
103 | .order(ByteOrder.nativeOrder())
104 | .asFloatBuffer();
105 | meshBuffer.put(parser.getVertices()).position(0);
106 | colorBuffer = ByteBuffer.allocateDirect(parser.getColors().length * BYTES_PER_FLOAT)
107 | .order(ByteOrder.nativeOrder())
108 | .asFloatBuffer();
109 | colorBuffer.put(parser.getColors()).position(0);
110 | // TODO(bminortx): check size of int
111 | facesBuffer = ByteBuffer.allocateDirect(parser.getFaces().length * BYTES_PER_FLOAT)
112 | .order(ByteOrder.nativeOrder())
113 | .asIntBuffer();
114 | facesBuffer.put(parser.getFaces()).position(0);
115 |
116 | GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, bufferIdx[0]);
117 | GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER,
118 | meshBuffer.capacity() * BYTES_PER_FLOAT,
119 | meshBuffer,
120 | GLES20.GL_STATIC_DRAW);
121 | GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, bufferIdx[1]);
122 | GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER,
123 | colorBuffer.capacity() * BYTES_PER_FLOAT,
124 | colorBuffer,
125 | GLES20.GL_STATIC_DRAW);
126 | GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, bufferIdx[2]);
127 | GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER,
128 | facesBuffer.capacity() * BYTES_PER_FLOAT,
129 | facesBuffer,
130 | GLES20.GL_STATIC_DRAW);
131 | GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
132 |
133 | // Get our shaders ready
134 | int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, getVertexShaderCode());
135 | int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, getFragmentShaderCode());
136 | mProgram = GLES20.glCreateProgram();
137 | // add the vertex shader to program
138 | GLES20.glAttachShader(mProgram, vertexShader);
139 | checkGlError("Cube", "glAttachShader");
140 | // add the fragment shader to program
141 | GLES20.glAttachShader(mProgram, fragmentShader);
142 | checkGlError("Cube", "glAttachShader");
143 | GLES20.glLinkProgram(mProgram);
144 | return true;
145 | }
146 |
147 | public void draw(float[] mvpMatrix) {
148 | // Add program to OpenGL ES environment
149 | GLES20.glUseProgram(mProgram);
150 | // Position Buffer, passed into shader
151 | mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
152 | GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, bufferIdx[0]);
153 | GLES20.glEnableVertexAttribArray(mPositionHandle);
154 | GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX,
155 | GLES20.GL_FLOAT, false, 0, 0);
156 | // Color Buffer, passed into shader
157 | mColorHandle = GLES20.glGetAttribLocation(mProgram, "vColor");
158 | GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, bufferIdx[1]);
159 | GLES20.glEnableVertexAttribArray(mColorHandle);
160 | GLES20.glVertexAttribPointer(mColorHandle, COORDS_PER_COLOR,
161 | GLES20.GL_FLOAT, false, 0, 0);
162 | // get handle to shape's transformation matrix
163 | mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
164 | // Pass the projection and view transformation to the shader
165 | GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
166 | // Draw the triangle
167 | // GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount);
168 | GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, bufferIdx[2]);
169 | GLES20.glDrawElements(GLES20.GL_TRIANGLE_STRIP, facesCount * 3, GLES20.GL_UNSIGNED_INT, 0);
170 | // Disable vertex array
171 | GLES20.glDisableVertexAttribArray(mPositionHandle);
172 | GLES20.glDisableVertexAttribArray(mColorHandle);
173 | GLES20.glFlush();
174 | }
175 | }
176 |
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/java/com/graphics/openglgui/MeshViewActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Example 10: Activities
3 | */
4 |
5 | package com.graphics.openglgui;
6 |
7 | import android.app.Activity;
8 | import android.content.res.Configuration;
9 | import android.os.Bundle;
10 | import android.view.View;
11 |
12 | public class MeshViewActivity extends Activity {
13 | GLView view;
14 |
15 | @Override protected void onCreate(Bundle icicle) {
16 | super.onCreate(icicle);
17 | setContentView(R.layout.activity_fullscreen);
18 | view = (GLView)findViewById(R.id.gl_view);
19 | }
20 |
21 | @Override protected void onPause() {
22 | super.onPause();
23 | view.onPause();
24 | }
25 |
26 | @Override protected void onResume() {
27 | super.onResume();
28 | view.onResume();
29 | }
30 |
31 | @Override public void onConfigurationChanged(Configuration conf) {
32 | super.onConfigurationChanged(conf);
33 | }
34 |
35 | public void Reset(View v) {
36 | view.Reset();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/java/com/graphics/openglgui/PlyParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | PLYParser: A reader for .ply files
3 | See the below links for info:
4 | http://paulbourke.net/dataformats/ply/
5 | http://stackoverflow.com/questions/6420293/reading-android-raw-text-file
6 | */
7 |
8 | package com.graphics.openglgui;
9 |
10 | import android.util.Log;
11 |
12 | import java.io.BufferedReader;
13 | import java.io.IOException;
14 | import java.io.InputStream;
15 | import java.io.InputStreamReader;
16 |
17 | public class PlyParser {
18 | // Parser mechanisms
19 | private BufferedReader bufferedReader;
20 | private final int NO_INDEX = 100;
21 | private int vertexIndex = NO_INDEX;
22 | private int colorIndex = NO_INDEX;
23 | private int normalIndex = NO_INDEX;
24 | private boolean inHeader = true;
25 | public int currentElement = 0;
26 | public int currentFace = 0;
27 | /* data fields to store points, colors, faces information read from PLY file */
28 | public float[] vertices = null;
29 | public float[] colors = null;
30 | public float[] normals = null;
31 | public int[] faces = null;
32 | // Size of an individual element, in floats
33 | public int vertexSize = 0;
34 | public int colorSize = 0;
35 | public int normalSize = 0;
36 | public int faceSize = 3;
37 | // Normalizing constants
38 | public float vertexMax = 0;
39 | public float colorMax = 0;
40 | // Number of elements in the entire PLY
41 | public int vertexCount = 0;
42 | public int faceCount = 0;
43 | // Counter for header
44 | private int elementCount = 0;
45 |
46 | public PlyParser(InputStream plyFile) {
47 | bufferedReader = new BufferedReader(new InputStreamReader(plyFile));
48 | }
49 |
50 | boolean ParsePly() throws IOException {
51 | // Check if this is even a PLY file.
52 | String line = bufferedReader.readLine();
53 | if(!line.equals("ply")) {
54 | Log.e("ReadHeader", "File is not a PLY! Leave us.");
55 | return false;
56 | }
57 |
58 | // Check for ASCII format
59 | line = bufferedReader.readLine();
60 | String words[] = line.split(" ");
61 | if(!words[1].equals("ascii")) {
62 | Log.e("ReadHeader", "File is not ASCII format! Cannot read.");
63 | return false;
64 | }
65 |
66 | // Read the header
67 | line = bufferedReader.readLine();
68 | while (line != null && inHeader) {
69 | ReadHeader(line);
70 | line = bufferedReader.readLine();
71 | }
72 |
73 | // Populate the data
74 | if (vertexSize != 3) {
75 | Log.e("ParsePly", "Incorrect count of vertices! Expected 3.");
76 | return false;
77 | }
78 | vertices = new float[vertexCount * vertexSize];
79 | faces = new int[faceCount * faceSize];
80 | if (colorSize != 0) { colors = new float [vertexCount * colorSize]; }
81 | if (normalSize != 0) { normals = new float [vertexCount * normalSize]; }
82 | line = bufferedReader.readLine();
83 | while (line != null) {
84 | ReadData(line);
85 | line = bufferedReader.readLine();
86 | }
87 | ScaleData();
88 | return true;
89 | }
90 |
91 | void ReadHeader(String line) {
92 | // Make into a list of words, yo.
93 | String words[] = line.split(" ");
94 | if(words[0].equals("comment")) { return; }
95 | // Check if element or property
96 | if (words[0].equals("element")) {
97 | if (words[1].equals("vertex")) {
98 | vertexCount = Integer.parseInt(words[2]);
99 | } else if (words[1].equals("face")) {
100 | faceCount = Integer.parseInt(words[2]);
101 | }
102 | }
103 | if (words[0].equals("property")) {
104 | if (words[2].equals("x") ||
105 | words[2].equals("y") ||
106 | words[2].equals("z")) {
107 | if (vertexIndex > elementCount) { vertexIndex = elementCount; }
108 | vertexSize++;
109 | } else if (words[2].equals("nx") ||
110 | words[2].equals("ny")||
111 | words[2].equals("nz")) {
112 | if (normalIndex > elementCount) { normalIndex = elementCount; }
113 | normalSize++;
114 | } else if (words[2].equals("red") ||
115 | words[2].equals("green") ||
116 | words[2].equals("blue") ||
117 | words[2].equals("alpha")) {
118 | if (colorIndex > elementCount) { colorIndex = elementCount; }
119 | colorSize++;
120 | }
121 | elementCount++;
122 | }
123 |
124 | if (words[0].equals("end_header")) {
125 | inHeader = false;
126 | return;
127 | }
128 | }
129 |
130 | void ReadData(String line) {
131 | String words[] = line.split(" ");
132 | // Compensate for extra line read with (vertexCount - 1)
133 | if (currentElement < vertexCount - 1) {
134 | for (int i = 0; i < vertexSize; i++) {
135 | vertices[currentElement * vertexSize + i] = Float.parseFloat(words[vertexIndex + i]);
136 | if (vertexMax < Math.abs(vertices[currentElement * vertexSize + i])) {
137 | vertexMax = Math.abs(vertices[currentElement * vertexSize + i]);
138 | }
139 | }
140 | for (int i = 0; i < colorSize; i++) {
141 | colors[currentElement * colorSize + i] = Float.parseFloat(words[colorIndex + i]);
142 | if (colorMax < colors[currentElement * colorSize + i]) {
143 | colorMax = colors[currentElement * colorSize + i];
144 | }
145 | }
146 | for (int i = 0; i < normalSize; i++) {
147 | normals[currentElement * normalSize + i] = Float.parseFloat(words[normalIndex + i]);
148 | }
149 | currentElement++;
150 | } else if (currentFace < faceCount) {
151 | for (int i = 0; i < 3; i++) {
152 | faces[currentFace * faceSize + i] = Integer.parseInt(words[i + 1]);
153 | }
154 | currentFace++;
155 | }
156 | }
157 |
158 | void ScaleData() {
159 | for (int i = 0; i < vertexCount * vertexSize; i++) {
160 | vertices[i] /= vertexMax;
161 | }
162 | for (int i = 0; i < vertexCount * colorSize; i++) {
163 | colors[i] /= colorMax;
164 | }
165 | }
166 |
167 | // Getters
168 | public float[] getVertices() { return vertices; }
169 |
170 | public int getVertexCount() {
171 | return vertexCount;
172 | }
173 |
174 | public float[] getColors() {
175 | return colors;
176 | }
177 |
178 | public float[] getNormals() {
179 | return normals;
180 | }
181 |
182 | public int getFaceCount() {
183 | return faceCount;
184 | }
185 |
186 | public int[] getFaces() {
187 | return faces;
188 | }
189 | }
190 |
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/java/com/graphics/openglgui/shader.frag:
--------------------------------------------------------------------------------
1 | precision mediump float;
2 | varying vec4 vColor;
3 |
4 | void main() {
5 | gl_FragColor = vColor;
6 | }
7 |
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/java/com/graphics/openglgui/shader.frag~:
--------------------------------------------------------------------------------
1 | precision mediump float;
2 | varying vec4 vColor;
3 | void main() {
4 | gl_FragColor = vColor;
5 | }
6 |
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/java/com/graphics/openglgui/shader.vert:
--------------------------------------------------------------------------------
1 | uniform mat4 uMVPMatrix;
2 | attribute vec3 vPosition;
3 | varying vec4 v Color;
4 |
5 | void main() {
6 | gl_Position = uMVPMatrix * vPosition;
7 | }
8 |
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/java/com/graphics/openglgui/shader.vert~:
--------------------------------------------------------------------------------
1 | "uniform mat4 uMVPMatrix;" +
2 | "attribute vec3 vPosition;" +
3 | "varying vec4 v Color;" +
4 | "void main() {" +
5 | " gl_Position = uMVPMatrix * vPosition;" +
6 | "}";
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/java/com/graphics/openglgui/util/SystemUiHider.java:
--------------------------------------------------------------------------------
1 | package com.graphics.openglgui.util;
2 |
3 | import android.app.Activity;
4 | import android.os.Build;
5 | import android.view.View;
6 |
7 | /**
8 | * A utility class that helps with showing and hiding system UI such as the
9 | * status bar and navigation/system bar. This class uses backward-compatibility
10 | * techniques described in
12 | * Creating Backward-Compatible UIs to ensure that devices running any
13 | * version of Android OS are supported. More specifically, there are separate
14 | * implementations of this abstract class: for newer devices,
15 | * {@link #getInstance} will return a {@link SystemUiHiderHoneycomb} instance,
16 | * while on older devices {@link #getInstance} will return a
17 | * {@link SystemUiHiderBase} instance.
18 | *
19 | * For more on system bars, see System Bars .
22 | *
23 | * @see android.view.View#setSystemUiVisibility(int)
24 | * @see android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN
25 | */
26 | public abstract class SystemUiHider {
27 | /**
28 | * When this flag is set, the
29 | * {@link android.view.WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN}
30 | * flag will be set on older devices, making the status bar "float" on top
31 | * of the activity layout. This is most useful when there are no controls at
32 | * the top of the activity layout.
33 | *
34 | * This flag isn't used on newer devices because the action
36 | * bar , the most important structural element of an Android app, should
37 | * be visible and not obscured by the system UI.
38 | */
39 | public static final int FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES = 0x1;
40 |
41 | /**
42 | * When this flag is set, {@link #show()} and {@link #hide()} will toggle
43 | * the visibility of the status bar. If there is a navigation bar, show and
44 | * hide will toggle low profile mode.
45 | */
46 | public static final int FLAG_FULLSCREEN = 0x2;
47 |
48 | /**
49 | * When this flag is set, {@link #show()} and {@link #hide()} will toggle
50 | * the visibility of the navigation bar, if it's present on the device and
51 | * the device allows hiding it. In cases where the navigation bar is present
52 | * but cannot be hidden, show and hide will toggle low profile mode.
53 | */
54 | public static final int FLAG_HIDE_NAVIGATION = FLAG_FULLSCREEN | 0x4;
55 |
56 | /**
57 | * The activity associated with this UI hider object.
58 | */
59 | protected Activity mActivity;
60 |
61 | /**
62 | * The view on which {@link View#setSystemUiVisibility(int)} will be called.
63 | */
64 | protected View mAnchorView;
65 |
66 | /**
67 | * The current UI hider flags.
68 | *
69 | * @see #FLAG_FULLSCREEN
70 | * @see #FLAG_HIDE_NAVIGATION
71 | * @see #FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES
72 | */
73 | protected int mFlags;
74 |
75 | /**
76 | * The current visibility callback.
77 | */
78 | protected OnVisibilityChangeListener mOnVisibilityChangeListener = sDummyListener;
79 |
80 | /**
81 | * Creates and returns an instance of {@link SystemUiHider} that is
82 | * appropriate for this device. The object will be either a
83 | * {@link SystemUiHiderBase} or {@link SystemUiHiderHoneycomb} depending on
84 | * the device.
85 | *
86 | * @param activity The activity whose window's system UI should be
87 | * controlled by this class.
88 | * @param anchorView The view on which
89 | * {@link View#setSystemUiVisibility(int)} will be called.
90 | * @param flags Either 0 or any combination of {@link #FLAG_FULLSCREEN},
91 | * {@link #FLAG_HIDE_NAVIGATION}, and
92 | * {@link #FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES}.
93 | */
94 | public static SystemUiHider getInstance(Activity activity, View anchorView, int flags) {
95 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
96 | return new SystemUiHiderHoneycomb(activity, anchorView, flags);
97 | } else {
98 | return new SystemUiHiderBase(activity, anchorView, flags);
99 | }
100 | }
101 |
102 | protected SystemUiHider(Activity activity, View anchorView, int flags) {
103 | mActivity = activity;
104 | mAnchorView = anchorView;
105 | mFlags = flags;
106 | }
107 |
108 | /**
109 | * Sets up the system UI hider. Should be called from
110 | * {@link Activity#onCreate}.
111 | */
112 | public abstract void setup();
113 |
114 | /**
115 | * Returns whether or not the system UI is visible.
116 | */
117 | public abstract boolean isVisible();
118 |
119 | /**
120 | * Hide the system UI.
121 | */
122 | public abstract void hide();
123 |
124 | /**
125 | * Show the system UI.
126 | */
127 | public abstract void show();
128 |
129 | /**
130 | * Toggle the visibility of the system UI.
131 | */
132 | public void toggle() {
133 | if (isVisible()) {
134 | hide();
135 | } else {
136 | show();
137 | }
138 | }
139 |
140 | /**
141 | * Registers a callback, to be triggered when the system UI visibility
142 | * changes.
143 | */
144 | public void setOnVisibilityChangeListener(OnVisibilityChangeListener listener) {
145 | if (listener == null) {
146 | listener = sDummyListener;
147 | }
148 |
149 | mOnVisibilityChangeListener = listener;
150 | }
151 |
152 | /**
153 | * A dummy no-op callback for use when there is no other listener set.
154 | */
155 | private static OnVisibilityChangeListener sDummyListener = new OnVisibilityChangeListener() {
156 | @Override
157 | public void onVisibilityChange(boolean visible) {
158 | }
159 | };
160 |
161 | /**
162 | * A callback interface used to listen for system UI visibility changes.
163 | */
164 | public interface OnVisibilityChangeListener {
165 | /**
166 | * Called when the system UI visibility has changed.
167 | *
168 | * @param visible True if the system UI is visible.
169 | */
170 | public void onVisibilityChange(boolean visible);
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/java/com/graphics/openglgui/util/SystemUiHiderBase.java:
--------------------------------------------------------------------------------
1 | package com.graphics.openglgui.util;
2 |
3 | import android.app.Activity;
4 | import android.view.View;
5 | import android.view.WindowManager;
6 |
7 | /**
8 | * A base implementation of {@link SystemUiHider}. Uses APIs available in all
9 | * API levels to show and hide the status bar.
10 | */
11 | public class SystemUiHiderBase extends SystemUiHider {
12 | /**
13 | * Whether or not the system UI is currently visible. This is a cached value
14 | * from calls to {@link #hide()} and {@link #show()}.
15 | */
16 | private boolean mVisible = true;
17 |
18 | /**
19 | * Constructor not intended to be called by clients. Use
20 | * {@link SystemUiHider#getInstance} to obtain an instance.
21 | */
22 | protected SystemUiHiderBase(Activity activity, View anchorView, int flags) {
23 | super(activity, anchorView, flags);
24 | }
25 |
26 | @Override
27 | public void setup() {
28 | if ((mFlags & FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES) == 0) {
29 | mActivity.getWindow().setFlags(
30 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
31 | | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
32 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
33 | | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
34 | }
35 | }
36 |
37 | @Override
38 | public boolean isVisible() {
39 | return mVisible;
40 | }
41 |
42 | @Override
43 | public void hide() {
44 | if ((mFlags & FLAG_FULLSCREEN) != 0) {
45 | mActivity.getWindow().setFlags(
46 | WindowManager.LayoutParams.FLAG_FULLSCREEN,
47 | WindowManager.LayoutParams.FLAG_FULLSCREEN);
48 | }
49 | mOnVisibilityChangeListener.onVisibilityChange(false);
50 | mVisible = false;
51 | }
52 |
53 | @Override
54 | public void show() {
55 | if ((mFlags & FLAG_FULLSCREEN) != 0) {
56 | mActivity.getWindow().setFlags(
57 | 0,
58 | WindowManager.LayoutParams.FLAG_FULLSCREEN);
59 | }
60 | mOnVisibilityChangeListener.onVisibilityChange(true);
61 | mVisible = true;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/java/com/graphics/openglgui/util/SystemUiHiderHoneycomb.java:
--------------------------------------------------------------------------------
1 | package com.graphics.openglgui.util;
2 |
3 | import android.annotation.TargetApi;
4 | import android.app.Activity;
5 | import android.os.Build;
6 | import android.view.View;
7 | import android.view.WindowManager;
8 |
9 | /**
10 | * An API 11+ implementation of {@link SystemUiHider}. Uses APIs available in
11 | * Honeycomb and later (specifically {@link View#setSystemUiVisibility(int)}) to
12 | * show and hide the system UI.
13 | */
14 | @TargetApi(Build.VERSION_CODES.HONEYCOMB)
15 | public class SystemUiHiderHoneycomb extends SystemUiHiderBase {
16 | /**
17 | * Flags for {@link View#setSystemUiVisibility(int)} to use when showing the
18 | * system UI.
19 | */
20 | private int mShowFlags;
21 |
22 | /**
23 | * Flags for {@link View#setSystemUiVisibility(int)} to use when hiding the
24 | * system UI.
25 | */
26 | private int mHideFlags;
27 |
28 | /**
29 | * Flags to test against the first parameter in
30 | * {@link android.view.View.OnSystemUiVisibilityChangeListener#onSystemUiVisibilityChange(int)}
31 | * to determine the system UI visibility state.
32 | */
33 | private int mTestFlags;
34 |
35 | /**
36 | * Whether or not the system UI is currently visible. This is cached from
37 | * {@link android.view.View.OnSystemUiVisibilityChangeListener}.
38 | */
39 | private boolean mVisible = true;
40 |
41 | /**
42 | * Constructor not intended to be called by clients. Use
43 | * {@link SystemUiHider#getInstance} to obtain an instance.
44 | */
45 | protected SystemUiHiderHoneycomb(Activity activity, View anchorView, int flags) {
46 | super(activity, anchorView, flags);
47 |
48 | mShowFlags = View.SYSTEM_UI_FLAG_VISIBLE;
49 | mHideFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
50 | mTestFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
51 |
52 | if ((mFlags & FLAG_FULLSCREEN) != 0) {
53 | // If the client requested fullscreen, add flags relevant to hiding
54 | // the status bar. Note that some of these constants are new as of
55 | // API 16 (Jelly Bean). It is safe to use them, as they are inlined
56 | // at compile-time and do nothing on pre-Jelly Bean devices.
57 | mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
58 | mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
59 | | View.SYSTEM_UI_FLAG_FULLSCREEN;
60 | }
61 |
62 | if ((mFlags & FLAG_HIDE_NAVIGATION) != 0) {
63 | // If the client requested hiding navigation, add relevant flags.
64 | mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
65 | mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
66 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
67 | mTestFlags |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
68 | }
69 | }
70 |
71 | /**
72 | * {@inheritDoc}
73 | */
74 | @Override
75 | public void setup() {
76 | mAnchorView.setOnSystemUiVisibilityChangeListener(mSystemUiVisibilityChangeListener);
77 | }
78 |
79 | /**
80 | * {@inheritDoc}
81 | */
82 | @Override
83 | public void hide() {
84 | mAnchorView.setSystemUiVisibility(mHideFlags);
85 | }
86 |
87 | /**
88 | * {@inheritDoc}
89 | */
90 | @Override
91 | public void show() {
92 | mAnchorView.setSystemUiVisibility(mShowFlags);
93 | }
94 |
95 | /**
96 | * {@inheritDoc}
97 | */
98 | @Override
99 | public boolean isVisible() {
100 | return mVisible;
101 | }
102 |
103 | private View.OnSystemUiVisibilityChangeListener mSystemUiVisibilityChangeListener
104 | = new View.OnSystemUiVisibilityChangeListener() {
105 | @Override
106 | public void onSystemUiVisibilityChange(int vis) {
107 | // Test against mTestFlags to see if the system UI is visible.
108 | if ((vis & mTestFlags) != 0) {
109 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
110 | // Pre-Jelly Bean, we must manually hide the action bar
111 | // and use the old window flags API.
112 | mActivity.getActionBar().hide();
113 | mActivity.getWindow().setFlags(
114 | WindowManager.LayoutParams.FLAG_FULLSCREEN,
115 | WindowManager.LayoutParams.FLAG_FULLSCREEN);
116 | }
117 |
118 | // Trigger the registered listener and cache the visibility
119 | // state.
120 | mOnVisibilityChangeListener.onVisibilityChange(false);
121 | mVisible = false;
122 |
123 | } else {
124 | mAnchorView.setSystemUiVisibility(mShowFlags);
125 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
126 | // Pre-Jelly Bean, we must manually show the action bar
127 | // and use the old window flags API.
128 | mActivity.getActionBar().show();
129 | mActivity.getWindow().setFlags(
130 | 0,
131 | WindowManager.LayoutParams.FLAG_FULLSCREEN);
132 | }
133 |
134 | // Trigger the registered listener and cache the visibility
135 | // state.
136 | mOnVisibilityChangeListener.onVisibilityChange(true);
137 | mVisible = true;
138 | }
139 | }
140 | };
141 | }
142 |
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/res/layout/activity_fullscreen.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
12 |
13 |
21 |
22 |
29 |
30 |
31 |
32 |
34 |
35 |
38 |
39 |
47 |
48 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bminortx/Android-PLY-Reader/1437621acd7e2391922df1f4703a3f066f4bf93b/OpenGLGui/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bminortx/Android-PLY-Reader/1437621acd7e2391922df1f4703a3f066f4bf93b/OpenGLGui/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bminortx/Android-PLY-Reader/1437621acd7e2391922df1f4703a3f066f4bf93b/OpenGLGui/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bminortx/Android-PLY-Reader/1437621acd7e2391922df1f4703a3f066f4bf93b/OpenGLGui/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #66000000
4 |
5 |
6 |
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | OpenGL: PLY Loader
3 |
4 | Reset View
5 |
6 |
--------------------------------------------------------------------------------
/OpenGLGui/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
14 |
15 |
16 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/OpenGLGui/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:1.2.3'
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 |
--------------------------------------------------------------------------------
/OpenGLGui/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/OpenGLGui/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bminortx/Android-PLY-Reader/1437621acd7e2391922df1f4703a3f066f4bf93b/OpenGLGui/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/OpenGLGui/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 07 15:51:57 MDT 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.4-all.zip
7 |
--------------------------------------------------------------------------------
/OpenGLGui/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 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/OpenGLGui/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 |
--------------------------------------------------------------------------------
/OpenGLGui/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android PLY Reader #
2 |
3 | This program allows the user to view ASCII .ply files on their phone
4 | using OpenGL ES.
5 |
6 | 
7 |
8 | ## How to Use ##
9 |
10 | This project is written with Gradle support, and does not use
11 | JNI. This should make it a breeze to compile in Android Studio. There
12 | is only one .ply located in memory, but the parser is not unique to
13 | this file; the only requirement is that it be in ASCII format.
14 |
15 | - Drag to rotate the object around the screen.
16 | - Move two fingers towards/away each other for a scaling effect. It's
17 | recommended that your first finger stay in one place on the screen,
18 | to avoid simultaneous rotation of the object.
19 |
20 | And that's it! Since there are so many vertices, it takes a couple of
21 | seconds for anything to show on the screen (~2 sec on my HTC One
22 | M8). There are myriad improvements to be made to the app, but it's
23 | complete enough for a proof-of-concept.
24 |
--------------------------------------------------------------------------------