├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── github │ │ └── piasy │ │ └── openglestutorial_android │ │ ├── ColorShaderProgram.java │ │ ├── DemoRenderer.java │ │ ├── MainActivity.java │ │ ├── Mallet.java │ │ ├── ShaderHelper.java │ │ ├── ShaderProgram.java │ │ ├── Table.java │ │ ├── TextureShaderProgram.java │ │ ├── Utils.java │ │ └── VertexArray.java │ └── res │ ├── drawable-nodpi │ ├── air_hockey_surface.png │ └── air_hockey_surface_low_res.png │ ├── drawable-xhdpi │ └── p_300px.png │ ├── layout │ └── activity_main.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── raw │ ├── fragment.glsl │ ├── texture_fragment.glsl │ ├── texture_vertex.glsl │ └── vertex.glsl │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | **.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Piasy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenGLESTutorial-Android 2 | OpenGL ES Android tutorial, following https://pragprog.com/book/kbogla/opengl-es-2-for-android 3 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "26.0.0" 6 | defaultConfig { 7 | applicationId "com.github.piasy.openglestutorial_android" 8 | minSdkVersion 17 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 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 'com.android.support:appcompat-v7:25.3.1' 24 | } 25 | -------------------------------------------------------------------------------- /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 /Users/piasy/tools/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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/piasy/openglestutorial_android/ColorShaderProgram.java: -------------------------------------------------------------------------------- 1 | package com.github.piasy.openglestutorial_android; 2 | 3 | import android.content.Context; 4 | import android.opengl.GLES20; 5 | 6 | /** 7 | * Created by Piasy{github.com/Piasy} on 15/07/2017. 8 | */ 9 | 10 | public class ColorShaderProgram extends ShaderProgram { 11 | // Uniform locations 12 | private final int mUMatrixLocation; 13 | 14 | // Attribute locations 15 | private final int mAPositionLocation; 16 | private final int mAColorLocation; 17 | 18 | public ColorShaderProgram(final Context context) { 19 | super(context, R.raw.vertex, R.raw.fragment); 20 | 21 | // Retrieve uniform locations for the shader program. 22 | mUMatrixLocation = GLES20.glGetUniformLocation(mProgram, U_MATRIX); 23 | // Retrieve attribute locations for the shader program. 24 | mAPositionLocation = GLES20.glGetAttribLocation(mProgram, A_POSITION); 25 | mAColorLocation = GLES20.glGetAttribLocation(mProgram, A_COLOR); 26 | } 27 | 28 | public void setUniforms(float[] matrix) { 29 | // Pass the matrix into the shader program. 30 | GLES20.glUniformMatrix4fv(mUMatrixLocation, 1, false, matrix, 0); 31 | } 32 | 33 | public int getPositionAttributeLocation() { 34 | return mAPositionLocation; 35 | } 36 | 37 | public int getColorAttributeLocation() { 38 | return mAColorLocation; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/piasy/openglestutorial_android/DemoRenderer.java: -------------------------------------------------------------------------------- 1 | package com.github.piasy.openglestutorial_android; 2 | 3 | import android.content.Context; 4 | import android.opengl.GLES20; 5 | import android.opengl.GLSurfaceView; 6 | import android.opengl.Matrix; 7 | import javax.microedition.khronos.egl.EGLConfig; 8 | import javax.microedition.khronos.opengles.GL10; 9 | 10 | /** 11 | * Created by Piasy{github.com/Piasy} on 07/07/2017. 12 | */ 13 | class DemoRenderer implements GLSurfaceView.Renderer { 14 | 15 | private final Context mContext; 16 | private final float[] mProjectionMatrix = new float[16]; 17 | private final float[] mModelMatrix = new float[16]; 18 | private final float[] mTmpMatrix = new float[16]; 19 | 20 | private Table mTable; 21 | private Mallet mMallet; 22 | private TextureShaderProgram mTextureShaderProgram; 23 | private ColorShaderProgram mColorShaderProgram; 24 | private int mTexture; 25 | 26 | DemoRenderer(final Context context) { 27 | mContext = context; 28 | } 29 | 30 | @Override 31 | public void onSurfaceCreated(GL10 unused, EGLConfig config) { 32 | GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 33 | 34 | mTable = new Table(); 35 | mMallet = new Mallet(); 36 | mTextureShaderProgram = new TextureShaderProgram(mContext); 37 | mColorShaderProgram = new ColorShaderProgram(mContext); 38 | mTexture = Utils.loadTexture(mContext, R.drawable.air_hockey_surface); 39 | } 40 | 41 | @Override 42 | public void onSurfaceChanged(GL10 unused, int width, int height) { 43 | GLES20.glViewport(0, 0, width, height); 44 | 45 | Matrix.perspectiveM(mProjectionMatrix, 0, 45, (float) width / height, 1f, 10f); 46 | 47 | Matrix.setIdentityM(mModelMatrix, 0); 48 | Matrix.translateM(mModelMatrix, 0, 0f, 0f, -2.5f); 49 | Matrix.rotateM(mModelMatrix, 0, -60f, 1f, 0f, 0f); 50 | Matrix.multiplyMM(mTmpMatrix, 0, mProjectionMatrix, 0, mModelMatrix, 0); 51 | System.arraycopy(mTmpMatrix, 0, mProjectionMatrix, 0, mTmpMatrix.length); 52 | } 53 | 54 | @Override 55 | public void onDrawFrame(GL10 unused) { 56 | // Clear the rendering surface. 57 | GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); 58 | 59 | // Draw the table. 60 | mTextureShaderProgram.useProgram(); 61 | mTextureShaderProgram.setUniforms(mProjectionMatrix, mTexture); 62 | mTable.bindData(mTextureShaderProgram); 63 | mTable.draw(); 64 | 65 | // Draw the mallets. 66 | mColorShaderProgram.useProgram(); 67 | mColorShaderProgram.setUniforms(mProjectionMatrix); 68 | mMallet.bindData(mColorShaderProgram); 69 | mMallet.draw(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/piasy/openglestutorial_android/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.github.piasy.openglestutorial_android; 2 | 3 | import android.opengl.GLSurfaceView; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.widget.Toast; 7 | 8 | public class MainActivity extends AppCompatActivity { 9 | 10 | private GLSurfaceView mGLSurfaceView; 11 | private DemoRenderer mRenderer; 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.activity_main); 17 | 18 | if (!Utils.supportGlEs20(this)) { 19 | Toast.makeText(this, "GLES 2.0 not supported!", Toast.LENGTH_LONG).show(); 20 | finish(); 21 | return; 22 | } 23 | 24 | mGLSurfaceView = (GLSurfaceView) findViewById(R.id.surface); 25 | 26 | mGLSurfaceView.setEGLContextClientVersion(2); 27 | mRenderer = new DemoRenderer(this); 28 | mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); 29 | mGLSurfaceView.setRenderer(mRenderer); 30 | mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY); 31 | } 32 | 33 | @Override 34 | protected void onDestroy() { 35 | super.onDestroy(); 36 | } 37 | 38 | @Override 39 | protected void onPause() { 40 | super.onPause(); 41 | mGLSurfaceView.onPause(); 42 | } 43 | 44 | @Override 45 | protected void onResume() { 46 | super.onResume(); 47 | mGLSurfaceView.onResume(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/piasy/openglestutorial_android/Mallet.java: -------------------------------------------------------------------------------- 1 | package com.github.piasy.openglestutorial_android; 2 | 3 | import android.opengl.GLES20; 4 | 5 | /** 6 | * Created by Piasy{github.com/Piasy} on 15/07/2017. 7 | */ 8 | 9 | public class Mallet { 10 | private static final int POSITION_COMPONENT_COUNT = 2; 11 | private static final int COLOR_COMPONENT_COUNT = 3; 12 | private static final int STRIDE = (POSITION_COMPONENT_COUNT + COLOR_COMPONENT_COUNT) 13 | * Utils.BYTES_PER_FLOAT; 14 | 15 | private static final float[] VERTEX_DATA = { 16 | // Order of coordinates: X, Y, R, G, B 17 | 0f, -0.4f, 0f, 0f, 1f, 18 | 0f, 0.4f, 1f, 0f, 0f 19 | }; 20 | 21 | private final VertexArray mVertexArray; 22 | 23 | public Mallet() { 24 | mVertexArray = new VertexArray(VERTEX_DATA); 25 | } 26 | 27 | public void bindData(ColorShaderProgram colorProgram) { 28 | mVertexArray.setVertexAttribPointer( 29 | 0, 30 | colorProgram.getPositionAttributeLocation(), 31 | POSITION_COMPONENT_COUNT, 32 | STRIDE); 33 | mVertexArray.setVertexAttribPointer( 34 | POSITION_COMPONENT_COUNT, 35 | colorProgram.getColorAttributeLocation(), 36 | COLOR_COMPONENT_COUNT, 37 | STRIDE); 38 | } 39 | 40 | public void draw() { 41 | GLES20.glDrawArrays(GLES20.GL_POINTS, 0, 2); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/piasy/openglestutorial_android/ShaderHelper.java: -------------------------------------------------------------------------------- 1 | package com.github.piasy.openglestutorial_android; 2 | 3 | import android.opengl.GLES20; 4 | import android.util.Log; 5 | 6 | /** 7 | * Created by Piasy{github.com/Piasy} on 07/07/2017. 8 | */ 9 | 10 | public final class ShaderHelper { 11 | 12 | private static final String TAG = "ShaderHelper"; 13 | 14 | private ShaderHelper() { 15 | // util 16 | } 17 | 18 | public static int compileVertexShader(String shader) { 19 | return compileShader(GLES20.GL_VERTEX_SHADER, shader); 20 | } 21 | 22 | public static int compileFragmentShader(String shader) { 23 | return compileShader(GLES20.GL_FRAGMENT_SHADER, shader); 24 | } 25 | 26 | public static int linkProgram(int vertexShader, int fragmentShader) { 27 | int program = GLES20.glCreateProgram(); 28 | 29 | if (program == 0) { 30 | Log.e(TAG, "create program fail, " + GLES20.glGetProgramInfoLog(program)); 31 | 32 | return 0; 33 | } 34 | 35 | GLES20.glAttachShader(program, vertexShader); 36 | GLES20.glAttachShader(program, fragmentShader); 37 | 38 | GLES20.glLinkProgram(program); 39 | 40 | int[] linkStatus = new int[1]; 41 | GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0); 42 | 43 | if (linkStatus[0] == GLES20.GL_FALSE) { 44 | Log.e(TAG, "link program fail, " + GLES20.glGetProgramInfoLog(program)); 45 | 46 | return 0; 47 | } 48 | 49 | return program; 50 | } 51 | 52 | public static boolean validateProgram(int program) { 53 | GLES20.glValidateProgram(program); 54 | 55 | int[] validateStatus = new int[1]; 56 | GLES20.glGetProgramiv(program, GLES20.GL_VALIDATE_STATUS, validateStatus, 0); 57 | 58 | Log.i(TAG, "validateProgram: " + validateStatus[0] + ", " 59 | + GLES20.glGetProgramInfoLog(program)); 60 | 61 | return validateStatus[0] == GLES20.GL_TRUE; 62 | } 63 | 64 | private static int compileShader(int type, String shader) { 65 | int shaderObj = GLES20.glCreateShader(type); 66 | 67 | if (shaderObj == 0) { 68 | Log.e(TAG, "create shader obj fail: " + type); 69 | return 0; 70 | } 71 | 72 | GLES20.glShaderSource(shaderObj, shader); 73 | GLES20.glCompileShader(shaderObj); 74 | 75 | final int[] compileStatus = new int[1]; 76 | GLES20.glGetShaderiv(shaderObj, GLES20.GL_COMPILE_STATUS, compileStatus, 0); 77 | 78 | if (compileStatus[0] == GLES20.GL_FALSE) { 79 | Log.e(TAG, "compile shader code fail: " + type + ", " 80 | + GLES20.glGetShaderInfoLog(shaderObj)); 81 | 82 | GLES20.glDeleteShader(shaderObj); 83 | return 0; 84 | } 85 | 86 | return shaderObj; 87 | } 88 | 89 | public static int buildProgram(String vertexShaderSource, String fragmentShaderSource) { 90 | int program; 91 | 92 | // Compile the shaders. 93 | int vertexShader = compileVertexShader(vertexShaderSource); 94 | int fragmentShader = compileFragmentShader(fragmentShaderSource); 95 | 96 | // Link them into a shader program. 97 | program = linkProgram(vertexShader, fragmentShader); 98 | 99 | validateProgram(program); 100 | 101 | return program; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/piasy/openglestutorial_android/ShaderProgram.java: -------------------------------------------------------------------------------- 1 | package com.github.piasy.openglestutorial_android; 2 | 3 | import android.content.Context; 4 | import android.opengl.GLES20; 5 | import android.support.annotation.RawRes; 6 | 7 | /** 8 | * Created by Piasy{github.com/Piasy} on 15/07/2017. 9 | */ 10 | 11 | public abstract class ShaderProgram { 12 | // Uniform constants 13 | protected static final String U_MATRIX = "u_Matrix"; 14 | protected static final String U_TEXTURE_UNIT = "u_TextureUnit"; 15 | 16 | // Attribute constants 17 | protected static final String A_POSITION = "a_Position"; 18 | protected static final String A_COLOR = "a_Color"; 19 | protected static final String A_TEXTURE_COORDINATES = "a_TextureCoordinates"; 20 | 21 | // Shader program 22 | protected final int mProgram; 23 | 24 | protected ShaderProgram(Context context, @RawRes int vertexShaderResourceId, 25 | @RawRes int fragmentShaderResourceId) { 26 | // Compile the shaders and link the program. 27 | mProgram = ShaderHelper.buildProgram( 28 | Utils.loadShader(context, vertexShaderResourceId), 29 | Utils.loadShader(context, fragmentShaderResourceId)); 30 | } 31 | 32 | public void useProgram() { 33 | // Set the current OpenGL shader program to this program. 34 | GLES20.glUseProgram(mProgram); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/piasy/openglestutorial_android/Table.java: -------------------------------------------------------------------------------- 1 | package com.github.piasy.openglestutorial_android; 2 | 3 | import android.opengl.GLES20; 4 | 5 | /** 6 | * Created by Piasy{github.com/Piasy} on 15/07/2017. 7 | */ 8 | 9 | public class Table { 10 | private static final int POSITION_COMPONENT_COUNT = 2; 11 | private static final int TEXTURE_COORDINATES_COMPONENT_COUNT = 2; 12 | private static final int STRIDE = (POSITION_COMPONENT_COUNT 13 | + TEXTURE_COORDINATES_COMPONENT_COUNT) 14 | * Utils.BYTES_PER_FLOAT; 15 | 16 | private static final float[] VERTEX_DATA = { 17 | // Order of coordinates: X, Y, S, T 18 | 19 | // Triangle Fan 20 | 0f, 0f, 0.5f, 0.5f, 21 | -0.5f, -0.8f, 0f, 0.9f, 22 | 0.5f, -0.8f, 1f, 0.9f, 23 | 0.5f, 0.8f, 1f, 0.1f, 24 | -0.5f, 0.8f, 0f, 0.1f, 25 | -0.5f, -0.8f, 0f, 0.9f 26 | }; 27 | 28 | private final VertexArray mVertexArray; 29 | 30 | public Table() { 31 | mVertexArray = new VertexArray(VERTEX_DATA); 32 | } 33 | 34 | public void bindData(TextureShaderProgram textureProgram) { 35 | mVertexArray.setVertexAttribPointer( 36 | 0, 37 | textureProgram.getPositionAttributeLocation(), 38 | POSITION_COMPONENT_COUNT, 39 | STRIDE); 40 | 41 | mVertexArray.setVertexAttribPointer( 42 | POSITION_COMPONENT_COUNT, 43 | textureProgram.getTextureCoordinatesAttributeLocation(), 44 | TEXTURE_COORDINATES_COMPONENT_COUNT, 45 | STRIDE); 46 | } 47 | 48 | public void draw() { 49 | GLES20.glDrawArrays(GLES20.GL_TRIANGLE_FAN, 0, 6); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/piasy/openglestutorial_android/TextureShaderProgram.java: -------------------------------------------------------------------------------- 1 | package com.github.piasy.openglestutorial_android; 2 | 3 | import android.content.Context; 4 | import android.opengl.GLES20; 5 | 6 | /** 7 | * Created by Piasy{github.com/Piasy} on 15/07/2017. 8 | */ 9 | 10 | public class TextureShaderProgram extends ShaderProgram { 11 | // Uniform locations 12 | private final int mUMatrixLocation; 13 | private final int mUTextureUnitLocation; 14 | 15 | // Attribute locations 16 | private final int mAPositionLocation; 17 | private final int mATextureCoordinatesLocation; 18 | 19 | public TextureShaderProgram(final Context context) { 20 | super(context, R.raw.texture_vertex, R.raw.texture_fragment); 21 | 22 | // Retrieve uniform locations for the shader program. 23 | mUMatrixLocation = GLES20.glGetUniformLocation(mProgram, U_MATRIX); 24 | mUTextureUnitLocation = GLES20.glGetUniformLocation(mProgram, U_TEXTURE_UNIT); 25 | // Retrieve attribute locations for the shader program. 26 | mAPositionLocation = GLES20.glGetAttribLocation(mProgram, A_POSITION); 27 | mATextureCoordinatesLocation = GLES20.glGetAttribLocation(mProgram, A_TEXTURE_COORDINATES); 28 | } 29 | 30 | public void setUniforms(float[] matrix, int textureId) { 31 | // Pass the matrix into the shader program. 32 | GLES20.glUniformMatrix4fv(mUMatrixLocation, 1, false, matrix, 0); 33 | 34 | // Set the active texture unit to texture unit 0. 35 | GLES20.glActiveTexture(GLES20.GL_TEXTURE0); 36 | 37 | // Bind the texture to this unit. 38 | GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId); 39 | 40 | // Tell the texture uniform sampler to use this texture in the shader by 41 | // telling it to read from texture unit 0. 42 | GLES20.glUniform1i(mUTextureUnitLocation, 0); 43 | } 44 | 45 | public int getPositionAttributeLocation() { 46 | return mAPositionLocation; 47 | } 48 | 49 | public int getTextureCoordinatesAttributeLocation() { 50 | return mATextureCoordinatesLocation; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/piasy/openglestutorial_android/Utils.java: -------------------------------------------------------------------------------- 1 | package com.github.piasy.openglestutorial_android; 2 | 3 | import android.app.Activity; 4 | import android.app.ActivityManager; 5 | import android.content.Context; 6 | import android.graphics.Bitmap; 7 | import android.graphics.BitmapFactory; 8 | import android.opengl.GLES20; 9 | import android.opengl.GLUtils; 10 | import android.os.Environment; 11 | import android.support.annotation.DrawableRes; 12 | import android.support.annotation.RawRes; 13 | import android.util.Log; 14 | import java.io.BufferedOutputStream; 15 | import java.io.BufferedReader; 16 | import java.io.FileOutputStream; 17 | import java.io.IOException; 18 | import java.io.InputStream; 19 | import java.io.InputStreamReader; 20 | import java.nio.Buffer; 21 | import java.nio.ByteBuffer; 22 | 23 | /** 24 | * Created by Piasy{github.com/Piasy} on 6/7/16. 25 | */ 26 | public final class Utils { 27 | 28 | public static final int BYTES_PER_FLOAT = 4; 29 | 30 | private static final String TAG = "Utils"; 31 | 32 | private Utils() { 33 | // util 34 | } 35 | 36 | public static String loadShader(Context context, @RawRes int resId) { 37 | StringBuilder builder = new StringBuilder(); 38 | 39 | try { 40 | InputStream inputStream = context.getResources().openRawResource(resId); 41 | BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); 42 | 43 | String line; 44 | while ((line = reader.readLine()) != null) { 45 | builder.append(line) 46 | .append('\n'); 47 | } 48 | reader.close(); 49 | } catch (IOException e) { 50 | e.printStackTrace(); 51 | } 52 | 53 | return builder.toString(); 54 | } 55 | 56 | public static int loadTexture(Context context, @DrawableRes int resId) { 57 | int[] textureObjectIds = new int[1]; 58 | GLES20.glGenTextures(1, textureObjectIds, 0); 59 | if (textureObjectIds[0] == 0) { 60 | Log.e(TAG, "Could not generate a new OpenGL texture object."); 61 | return 0; 62 | } 63 | 64 | BitmapFactory.Options options = new BitmapFactory.Options(); 65 | options.inScaled = false; 66 | Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resId, options); 67 | if (bitmap == null) { 68 | Log.e(TAG, "Resource ID " + resId + " could not be decoded."); 69 | GLES20.glDeleteTextures(1, textureObjectIds, 0); 70 | return 0; 71 | } 72 | 73 | // bind 74 | GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureObjectIds[0]); 75 | GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, 76 | GLES20.GL_LINEAR_MIPMAP_LINEAR); 77 | GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, 78 | GLES20.GL_LINEAR); 79 | GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0); 80 | bitmap.recycle(); 81 | 82 | GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D); 83 | // unbind 84 | GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); 85 | 86 | return textureObjectIds[0]; 87 | } 88 | 89 | public static boolean supportGlEs20(Activity activity) { 90 | ActivityManager activityManager = (ActivityManager) activity.getSystemService( 91 | Context.ACTIVITY_SERVICE); 92 | return activityManager.getDeviceConfigurationInfo().reqGlEsVersion >= 0x20000; 93 | } 94 | 95 | static void sendImage(int width, int height) { 96 | ByteBuffer rgbaBuf = ByteBuffer.allocateDirect(width * height * 4); 97 | rgbaBuf.position(0); 98 | long start = System.nanoTime(); 99 | GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, 100 | rgbaBuf); 101 | long end = System.nanoTime(); 102 | Log.d("TryOpenGL", "glReadPixels: " + (end - start)); 103 | saveRgb2Bitmap(rgbaBuf, Environment.getExternalStorageDirectory().getAbsolutePath() 104 | + "/gl_dump_" + width + "_" + height + ".png", width, height); 105 | } 106 | 107 | static void saveRgb2Bitmap(Buffer buf, String filename, int width, int height) { 108 | Log.d("TryOpenGL", "Creating " + filename); 109 | BufferedOutputStream bos = null; 110 | try { 111 | bos = new BufferedOutputStream(new FileOutputStream(filename)); 112 | Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 113 | bmp.copyPixelsFromBuffer(buf); 114 | bmp.compress(Bitmap.CompressFormat.PNG, 90, bos); 115 | bmp.recycle(); 116 | } catch (IOException e) { 117 | e.printStackTrace(); 118 | } finally { 119 | if (bos != null) { 120 | try { 121 | bos.close(); 122 | } catch (IOException e) { 123 | e.printStackTrace(); 124 | } 125 | } 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/piasy/openglestutorial_android/VertexArray.java: -------------------------------------------------------------------------------- 1 | package com.github.piasy.openglestutorial_android; 2 | 3 | /** 4 | * Created by Piasy{github.com/Piasy} on 15/07/2017. 5 | */ 6 | 7 | import android.opengl.GLES20; 8 | import java.nio.ByteBuffer; 9 | import java.nio.ByteOrder; 10 | import java.nio.FloatBuffer; 11 | 12 | public class VertexArray { 13 | private final FloatBuffer mFloatBuffer; 14 | 15 | public VertexArray(float[] vertexData) { 16 | mFloatBuffer = ByteBuffer 17 | .allocateDirect(vertexData.length * Utils.BYTES_PER_FLOAT) 18 | .order(ByteOrder.nativeOrder()) 19 | .asFloatBuffer() 20 | .put(vertexData); 21 | } 22 | 23 | public void setVertexAttribPointer(int dataOffset, int attributeLocation, 24 | int componentCount, int stride) { 25 | mFloatBuffer.position(dataOffset); 26 | GLES20.glVertexAttribPointer(attributeLocation, componentCount, GLES20.GL_FLOAT, false, 27 | stride, mFloatBuffer); 28 | GLES20.glEnableVertexAttribArray(attributeLocation); 29 | 30 | mFloatBuffer.position(0); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/air_hockey_surface.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Piasy/LearnOpenGL/af3d56c3124fc2e6d661cd17168c9b95ec3cbffe/app/src/main/res/drawable-nodpi/air_hockey_surface.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/air_hockey_surface_low_res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Piasy/LearnOpenGL/af3d56c3124fc2e6d661cd17168c9b95ec3cbffe/app/src/main/res/drawable-nodpi/air_hockey_surface_low_res.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/p_300px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Piasy/LearnOpenGL/af3d56c3124fc2e6d661cd17168c9b95ec3cbffe/app/src/main/res/drawable-xhdpi/p_300px.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Piasy/LearnOpenGL/af3d56c3124fc2e6d661cd17168c9b95ec3cbffe/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Piasy/LearnOpenGL/af3d56c3124fc2e6d661cd17168c9b95ec3cbffe/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Piasy/LearnOpenGL/af3d56c3124fc2e6d661cd17168c9b95ec3cbffe/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Piasy/LearnOpenGL/af3d56c3124fc2e6d661cd17168c9b95ec3cbffe/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Piasy/LearnOpenGL/af3d56c3124fc2e6d661cd17168c9b95ec3cbffe/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Piasy/LearnOpenGL/af3d56c3124fc2e6d661cd17168c9b95ec3cbffe/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Piasy/LearnOpenGL/af3d56c3124fc2e6d661cd17168c9b95ec3cbffe/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Piasy/LearnOpenGL/af3d56c3124fc2e6d661cd17168c9b95ec3cbffe/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Piasy/LearnOpenGL/af3d56c3124fc2e6d661cd17168c9b95ec3cbffe/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Piasy/LearnOpenGL/af3d56c3124fc2e6d661cd17168c9b95ec3cbffe/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/raw/fragment.glsl: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | 3 | varying vec4 v_Color; 4 | 5 | void main() { 6 | gl_FragColor = v_Color; 7 | } 8 | -------------------------------------------------------------------------------- /app/src/main/res/raw/texture_fragment.glsl: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | uniform sampler2D u_TextureUnit; 3 | varying vec2 v_TextureCoordinates; 4 | 5 | void main() { 6 | gl_FragColor = texture2D(u_TextureUnit, v_TextureCoordinates); 7 | } -------------------------------------------------------------------------------- /app/src/main/res/raw/texture_vertex.glsl: -------------------------------------------------------------------------------- 1 | uniform mat4 u_Matrix; 2 | 3 | attribute vec4 a_Position; 4 | attribute vec2 a_TextureCoordinates; 5 | varying vec2 v_TextureCoordinates; 6 | 7 | void main() { 8 | v_TextureCoordinates = a_TextureCoordinates; 9 | gl_Position = u_Matrix * a_Position; 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/res/raw/vertex.glsl: -------------------------------------------------------------------------------- 1 | uniform mat4 u_Matrix; 2 | 3 | attribute vec4 a_Position; 4 | attribute vec4 a_Color; 5 | 6 | varying vec4 v_Color; 7 | 8 | void main() { 9 | v_Color = a_Color; 10 | 11 | gl_Position = u_Matrix * a_Position; 12 | gl_PointSize = 10.0; 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | OpenGLESTutorial-Android 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:2.3.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 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /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 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Piasy/LearnOpenGL/af3d56c3124fc2e6d661cd17168c9b95ec3cbffe/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Jun 29 13:59:50 CST 2017 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-3.5-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 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------