├── .gitignore
├── README.md
├── app
├── build.gradle
├── lint.xml
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── org
│ │ └── wysaid
│ │ └── ndkopenglbackdraw
│ │ ├── GLHelpFunctions.java
│ │ └── MainActivity.java
│ ├── jni
│ ├── Android.mk
│ ├── Application.mk
│ ├── NDKOpenGLBackDraw.c
│ └── org_wysaid_ndkopenglbackdraw_GLHelpFunctions.h
│ └── res
│ ├── drawable-nodpi
│ └── ic_launcher.png
│ ├── layout
│ └── activity_main.xml
│ ├── menu
│ └── main.xml
│ ├── values-sw600dp
│ └── dimens.xml
│ ├── values-sw720dp-land
│ └── dimens.xml
│ ├── values-v11
│ └── styles.xml
│ ├── values-v14
│ └── styles.xml
│ └── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── import-summary.txt
├── screenshot.jpg
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | build/
7 | /captures
8 | .idea/
9 | .svn/
10 | *iml
11 | .idea/
12 | local/
13 | libs/
14 | bin/
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # NDKOpenGLOffscreenRendering
2 | 简单demo, Android下使用NDK(C++)+GLES2.0进行后台绘图,保存到bitmap并交给java层处理. 在安卓下使用PBuffer创建context并实现在ndk下后台处理
3 | 
4 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "22.0.1"
6 |
7 | defaultConfig {
8 | applicationId "org.wysaid.ndkopenglbackdraw"
9 | minSdkVersion 8
10 | targetSdkVersion 22
11 |
12 | ndk {
13 | moduleName "NDKOpenGLBackDraw"
14 | abiFilters "armeabi"
15 | ldLibs "log", "android", "EGL", "GLESv2", "jnigraphics"
16 | }
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/app/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
17 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/org/wysaid/ndkopenglbackdraw/GLHelpFunctions.java:
--------------------------------------------------------------------------------
1 | package org.wysaid.ndkopenglbackdraw;
2 |
3 | import javax.microedition.khronos.egl.EGL10;
4 | import javax.microedition.khronos.egl.EGLConfig;
5 | import javax.microedition.khronos.egl.EGLContext;
6 | import javax.microedition.khronos.egl.EGLDisplay;
7 | import javax.microedition.khronos.opengles.GL10;
8 |
9 | import android.annotation.SuppressLint;
10 | import android.graphics.Bitmap;
11 | import android.opengl.EGL14;
12 | import android.util.Log;
13 |
14 | public class GLHelpFunctions {
15 |
16 | public static native void getGLBackDrawImage(Bitmap bm);
17 |
18 | // use GLES2.0.
19 | static int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
20 | static int[] attrib_list = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
21 | static private int[] version = new int[2];
22 | static EGLConfig[] configs = new EGLConfig[1];
23 | static int[] num_config = new int[1];
24 |
25 | @SuppressLint("InlinedApi") static int[] configSpec = { EGL10.EGL_SURFACE_TYPE, EGL10.EGL_PBUFFER_BIT,
26 | EGL10.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
27 | EGL10.EGL_RED_SIZE, 8, EGL10.EGL_GREEN_SIZE, 8,
28 | EGL10.EGL_BLUE_SIZE, 8, EGL10.EGL_ALPHA_SIZE, 8, EGL10.EGL_NONE };
29 | // eglCreatePbufferSurface used this config
30 | static int attribListPbuffer[] = {
31 | // The NDK code would never draw to Pbuffer, so it's not neccessary to
32 | // match anything.
33 | EGL10.EGL_WIDTH, 32, EGL10.EGL_HEIGHT, 32, EGL10.EGL_NONE };
34 | static EGL10 mEgl;
35 | static GL10 gl;
36 | static javax.microedition.khronos.egl.EGLSurface mEglPBSurface;
37 | static EGLContext mEglContext;
38 | static EGLConfig mEglConfig;
39 | static EGLDisplay mEglDisplay;
40 |
41 | static public void initEGL() {
42 | mEgl = (EGL10) EGLContext.getEGL();
43 | mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
44 | mEgl.eglInitialize(mEglDisplay, version);
45 | mEgl.eglChooseConfig(mEglDisplay, configSpec, configs, 1, num_config);
46 | mEglConfig = configs[0];
47 | mEglContext = mEgl.eglCreateContext(mEglDisplay, mEglConfig,
48 | EGL10.EGL_NO_CONTEXT, attrib_list);
49 | if (mEglContext == EGL10.EGL_NO_CONTEXT) {
50 | Log.d("ERROR:", "eglCreateContext Failed!");
51 | }
52 | mEglPBSurface = mEgl.eglCreatePbufferSurface(mEglDisplay, mEglConfig,
53 | attribListPbuffer);
54 | if (mEglPBSurface == EGL10.EGL_NO_SURFACE) {
55 | Log.d("ERROR:", "eglCreatePbufferSurface Failed!");
56 | }
57 |
58 | if (!mEgl.eglMakeCurrent(mEglDisplay, mEglPBSurface, mEglPBSurface, mEglContext)) {
59 | Log.d("ERROR:", "eglMakeCurrent failed:" + mEgl.eglGetError());
60 | }
61 | // You can do some works using OpenGL with java code. But this demo would do that within NDK.
62 | gl = (GL10) mEglContext.getGL();
63 | }
64 |
65 | static public void enableEGL() {
66 | if (!mEgl.eglMakeCurrent(mEglDisplay, mEglPBSurface, mEglPBSurface, mEglContext))
67 | {
68 | Log.d("ERROR:", "eglMakeCurrent failed:" + mEgl.eglGetError());
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/app/src/main/java/org/wysaid/ndkopenglbackdraw/MainActivity.java:
--------------------------------------------------------------------------------
1 | package org.wysaid.ndkopenglbackdraw;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.drawable.BitmapDrawable;
5 | import android.os.Bundle;
6 | import android.annotation.SuppressLint;
7 | import android.app.Activity;
8 | import android.graphics.Bitmap;
9 | import android.view.Menu;
10 | import android.view.View;
11 | import android.widget.Button;
12 | import android.widget.ImageView;
13 | import android.widget.LinearLayout;
14 |
15 | public class MainActivity extends Activity {
16 | static
17 | {
18 | System.loadLibrary("NDKOpenGLBackDraw");
19 | }
20 |
21 | @SuppressLint("NewApi")
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 |
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_main);
27 | dispalyLayout = (LinearLayout) findViewById(R.id.displayLayout);
28 | displayView = (ImageView) findViewById(R.id.imageView1);
29 | button = (Button) findViewById(R.id.button1);
30 | button.setOnClickListener(clickListener);
31 | GLHelpFunctions.initEGL();
32 | bitmap = Bitmap.createBitmap(800, 800, Bitmap.Config.ARGB_8888);
33 |
34 | Bitmap displayBitmap = ((BitmapDrawable)displayView.getDrawable()).getBitmap();
35 | Canvas canvas = new Canvas(bitmap);
36 | for(int i = 0; i < bitmap.getHeight(); i += displayBitmap.getHeight()) {
37 | for(int j = 0; j < bitmap.getWidth(); j += displayBitmap.getWidth()) {
38 | canvas.drawBitmap(displayBitmap, j, i, null);
39 | }
40 | }
41 | }
42 |
43 | @Override
44 | public boolean onCreateOptionsMenu(Menu menu) {
45 | // Inflate the menu; this adds items to the action bar if it is present.
46 | getMenuInflater().inflate(R.menu.main, menu);
47 | return true;
48 | }
49 |
50 | android.view.View.OnClickListener clickListener =
51 | new android.view.View.OnClickListener() {
52 | @Override
53 | public void onClick(View view) {
54 | // TODO Auto-generated method stub
55 | GLHelpFunctions.enableEGL();
56 | GLHelpFunctions.getGLBackDrawImage(bitmap);
57 | displayView.setImageBitmap(bitmap);
58 | }
59 | };
60 |
61 | ImageView displayView;
62 | LinearLayout dispalyLayout;
63 | Button button;
64 | Bitmap bitmap;
65 | }
66 |
--------------------------------------------------------------------------------
/app/src/main/jni/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 |
3 | include $(CLEAR_VARS)
4 |
5 | LOCAL_MODULE := NDKOpenGLBackDraw
6 | LOCAL_SRC_FILES := NDKOpenGLBackDraw.c
7 |
8 | LOCAL_LDLIBS := -llog -lGLESv2 -landroid -ljnigraphics
9 |
10 | include $(BUILD_SHARED_LIBRARY)
11 |
--------------------------------------------------------------------------------
/app/src/main/jni/Application.mk:
--------------------------------------------------------------------------------
1 | APP_STL := gnustl_static
--------------------------------------------------------------------------------
/app/src/main/jni/NDKOpenGLBackDraw.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | #ifndef LOG_TAG
8 | #define LOG_TAG "NDKOpenGLBackDraw"
9 | #endif
10 |
11 | #define LOG_INFO(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
12 | #define LOG_ERROR(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
13 | #define SHADER_STRING(...) #__VA_ARGS__
14 |
15 | void printGLString(const char* name, GLenum em)
16 | {
17 | const char *s = (const char*)glGetString(em);
18 | LOG_INFO("GL_INFO %s = %s\n", name, s);
19 | }
20 |
21 | void checkGLError(const char* op)
22 | {
23 | GLint error;
24 | for (error = glGetError(); error; error = glGetError())
25 | {
26 | LOG_INFO("after %s() glError (0x%x)\n", op, error);
27 | }
28 | }
29 |
30 | const char* const g_defaultVertexShaderString = SHADER_STRING
31 | (
32 | attribute vec2 vPosition;
33 | varying vec2 textureCoordinate;
34 | void main()
35 | {
36 | gl_Position = vec4(vPosition, 0.0, 1.0);
37 | textureCoordinate = (vPosition.xy + 1.0) / 2.0;
38 | }
39 | );
40 |
41 | const char* const g_defaultFragmentShaderString = SHADER_STRING
42 | (
43 | precision mediump float;
44 | varying vec2 textureCoordinate;
45 | uniform sampler2D myTexture;
46 | void main()
47 | {
48 | vec4 textureColor = texture2D(myTexture, textureCoordinate);
49 | textureColor.rb += textureCoordinate.xy;
50 | gl_FragColor = textureColor;
51 | }
52 | );
53 |
54 | const GLfloat g_vertices[] =
55 | {
56 | -1.0f, 1.0f,
57 | 1.0f, 1.0f,
58 | -1.0f, -1.0f,
59 | 1.0f, -1.0f
60 | };
61 |
62 | void runBackDraw(char* row, int w, int h)
63 | {
64 | GLuint texture, renderBuffer, frameBuffer;
65 | printGLString("Version", GL_VERSION);
66 | printGLString("Vendor", GL_VENDOR);
67 | printGLString("Renderer", GL_RENDERER);
68 |
69 | glActiveTexture(GL_TEXTURE0);
70 | glGenTextures(1, &texture);
71 | LOG_INFO("Input Image Texture id %d\n", texture);
72 | glBindTexture(GL_TEXTURE_2D, texture);
73 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
74 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, row);
75 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
76 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
77 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
78 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
79 |
80 | glGenFramebuffers(1, &frameBuffer);
81 | glGenRenderbuffers(1, &renderBuffer);
82 | glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
83 | glBindRenderbuffer(GL_RENDERBUFFER, renderBuffer);
84 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, w, h);
85 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
86 | GL_RENDERBUFFER, renderBuffer);
87 |
88 | if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
89 | {
90 | LOG_ERROR("Image Handler initImageFBO failed!\n");
91 | }
92 | else
93 | {
94 | glViewport(0, 0, w, h);
95 |
96 | ////////////////////////////////////
97 | GLuint vsh, fsh, program;
98 | vsh = glCreateShader(GL_VERTEX_SHADER);
99 | fsh = glCreateShader(GL_FRAGMENT_SHADER);
100 | program = glCreateProgram();
101 | glShaderSource(vsh, 1, (const GLchar**)&g_defaultVertexShaderString, NULL);
102 | glShaderSource(fsh, 1, (const GLchar**)&g_defaultFragmentShaderString, NULL);
103 | glCompileShader(vsh);
104 | glCompileShader(fsh);
105 | glAttachShader(program, vsh);
106 | glAttachShader(program, fsh);
107 | glLinkProgram(program);
108 | glDeleteShader(vsh);
109 | glDeleteShader(fsh);
110 | glUseProgram(program);
111 | GLuint vPosition = glGetAttribLocation(program, "vPosition");
112 | checkGLError("glGetAttribLocation");
113 | LOG_INFO("glGetAttribLocation(\"vPosition\") = %d\n", vPosition);
114 | glVertexAttribPointer(vPosition, 2, GL_FLOAT, GL_FALSE, 0, g_vertices);
115 | glEnableVertexAttribArray(vPosition);
116 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
117 |
118 | glPixelStorei(GL_PACK_ALIGNMENT, 1);
119 | glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, row);
120 | }
121 |
122 | glDeleteTextures(1, &texture);
123 | glDeleteFramebuffers(1, &frameBuffer);
124 | glDeleteRenderbuffers(1, &renderBuffer);
125 | }
126 |
127 |
128 | JNIEXPORT void JNICALL Java_org_wysaid_ndkopenglbackdraw_GLHelpFunctions_getGLBackDrawImage(JNIEnv *env, jclass cls, jobject bitmap)
129 | {
130 | AndroidBitmapInfo info;
131 | int w, h, ret;
132 | char* row;
133 |
134 | if ((ret = AndroidBitmap_getInfo(env, bitmap, &info)) < 0)
135 | {
136 | LOG_ERROR("AndroidBitmap_getInfo() failed ! error=%d", ret);
137 | return;
138 | }
139 |
140 | LOG_INFO("color image :: width is %d; height is %d; stride is %d; format is %d;flags is %d", info.width, info.height, info.stride, info.format, info.flags);
141 |
142 | if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888)
143 | {
144 | LOG_ERROR("Bitmap format is not RGBA_8888 !");
145 | return;
146 | }
147 |
148 | w = info.width;
149 | h = info.height;
150 | ret = AndroidBitmap_lockPixels(env, bitmap, (void**) &row);
151 |
152 | if (ret < 0)
153 | {
154 | LOG_ERROR("AndroidBitmap_lockPixels() failed ! error=%d", ret);
155 | return ;
156 | }
157 |
158 | runBackDraw(row, w, h);
159 | LOG_INFO("unlocking pixels");
160 | AndroidBitmap_unlockPixels(env, bitmap);
161 | }
--------------------------------------------------------------------------------
/app/src/main/jni/org_wysaid_ndkopenglbackdraw_GLHelpFunctions.h:
--------------------------------------------------------------------------------
1 | /* DO NOT EDIT THIS FILE - it is machine generated */
2 | #include
3 | /* Header for class org_wysaid_ndkopenglbackdraw_GLHelpFunctions */
4 |
5 | #ifndef _Included_org_wysaid_ndkopenglbackdraw_GLHelpFunctions
6 | #define _Included_org_wysaid_ndkopenglbackdraw_GLHelpFunctions
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 | /*
11 | * Class: org_wysaid_ndkopenglbackdraw_GLHelpFunctions
12 | * Method: getGLBackDrawImage
13 | * Signature: (Landroid/graphics/Bitmap;)V
14 | */
15 | JNIEXPORT void JNICALL Java_org_wysaid_ndkopenglbackdraw_GLHelpFunctions_getGLBackDrawImage
16 | (JNIEnv *, jclass, jobject);
17 |
18 | #ifdef __cplusplus
19 | }
20 | #endif
21 | #endif
22 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-nodpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wysaid/NDKOpenGLOffscreenRendering/092ca356598974e6fb70ce342e812629a9cf1f06/app/src/main/res/drawable-nodpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
18 |
19 |
24 |
25 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values-sw720dp-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 | 128dp
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | NDKOpenGLBackDraw
5 | Settings
6 | Hello world!
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | buildscript {
3 | repositories {
4 | jcenter()
5 | }
6 | dependencies {
7 | classpath 'com.android.tools.build:gradle:1.5.0'
8 | }
9 | }
10 |
11 | allprojects {
12 | repositories {
13 | jcenter()
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/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
19 | android.useDeprecatedNdk=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wysaid/NDKOpenGLOffscreenRendering/092ca356598974e6fb70ce342e812629a9cf1f06/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 21 11:34:03 PDT 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.8-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 |
--------------------------------------------------------------------------------
/import-summary.txt:
--------------------------------------------------------------------------------
1 | ECLIPSE ANDROID PROJECT IMPORT SUMMARY
2 | ======================================
3 |
4 | Ignored Files:
5 | --------------
6 | The following files were *not* copied into the new Gradle project; you
7 | should evaluate whether these are still needed in your project and if
8 | so manually move them:
9 |
10 | * .DS_Store
11 | * NDKOpenGLOffscreenRendering/
12 | * NDKOpenGLOffscreenRendering/.idea/
13 | * NDKOpenGLOffscreenRendering/.idea/.name
14 | * NDKOpenGLOffscreenRendering/.idea/compiler.xml
15 | * NDKOpenGLOffscreenRendering/.idea/copyright/
16 | * NDKOpenGLOffscreenRendering/.idea/copyright/profiles_settings.xml
17 | * NDKOpenGLOffscreenRendering/.idea/misc.xml
18 | * NDKOpenGLOffscreenRendering/.idea/modules.xml
19 | * NDKOpenGLOffscreenRendering/.idea/vcs.xml
20 | * NDKOpenGLOffscreenRendering/.idea/workspace.xml
21 | * NDKOpenGLOffscreenRendering/app/
22 | * NDKOpenGLOffscreenRendering/app/build.gradle
23 | * NDKOpenGLOffscreenRendering/app/lint.xml
24 | * NDKOpenGLOffscreenRendering/app/src/
25 | * NDKOpenGLOffscreenRendering/app/src/main/
26 | * NDKOpenGLOffscreenRendering/app/src/main/AndroidManifest.xml
27 | * NDKOpenGLOffscreenRendering/app/src/main/java/
28 | * NDKOpenGLOffscreenRendering/app/src/main/java/org/
29 | * NDKOpenGLOffscreenRendering/app/src/main/java/org/wysaid/
30 | * NDKOpenGLOffscreenRendering/app/src/main/java/org/wysaid/ndkopenglbackdraw/
31 | * NDKOpenGLOffscreenRendering/app/src/main/java/org/wysaid/ndkopenglbackdraw/GLHelpFunctions.java
32 | * NDKOpenGLOffscreenRendering/app/src/main/java/org/wysaid/ndkopenglbackdraw/MainActivity.java
33 | * NDKOpenGLOffscreenRendering/app/src/main/jni/
34 | * NDKOpenGLOffscreenRendering/app/src/main/jni/Android.mk
35 | * NDKOpenGLOffscreenRendering/app/src/main/jni/Application.mk
36 | * NDKOpenGLOffscreenRendering/app/src/main/jni/NDKOpenGLBackDraw.cpp
37 | * NDKOpenGLOffscreenRendering/app/src/main/jni/org_wysaid_ndkopenglbackdraw_GLHelpFunctions.h
38 | * NDKOpenGLOffscreenRendering/app/src/main/res/
39 | * NDKOpenGLOffscreenRendering/app/src/main/res/drawable-hdpi/
40 | * NDKOpenGLOffscreenRendering/app/src/main/res/drawable-hdpi/ic_launcher.png
41 | * NDKOpenGLOffscreenRendering/app/src/main/res/drawable-mdpi/
42 | * NDKOpenGLOffscreenRendering/app/src/main/res/drawable-mdpi/ic_launcher.png
43 | * NDKOpenGLOffscreenRendering/app/src/main/res/drawable-xhdpi/
44 | * NDKOpenGLOffscreenRendering/app/src/main/res/drawable-xhdpi/ic_launcher.png
45 | * NDKOpenGLOffscreenRendering/app/src/main/res/drawable-xxhdpi/
46 | * NDKOpenGLOffscreenRendering/app/src/main/res/drawable-xxhdpi/ic_launcher.png
47 | * NDKOpenGLOffscreenRendering/app/src/main/res/layout/
48 | * NDKOpenGLOffscreenRendering/app/src/main/res/layout/activity_main.xml
49 | * NDKOpenGLOffscreenRendering/app/src/main/res/menu/
50 | * NDKOpenGLOffscreenRendering/app/src/main/res/menu/main.xml
51 | * NDKOpenGLOffscreenRendering/app/src/main/res/values-sw600dp/
52 | * NDKOpenGLOffscreenRendering/app/src/main/res/values-sw600dp/dimens.xml
53 | * NDKOpenGLOffscreenRendering/app/src/main/res/values-sw720dp-land/
54 | * NDKOpenGLOffscreenRendering/app/src/main/res/values-sw720dp-land/dimens.xml
55 | * NDKOpenGLOffscreenRendering/app/src/main/res/values-v11/
56 | * NDKOpenGLOffscreenRendering/app/src/main/res/values-v11/styles.xml
57 | * NDKOpenGLOffscreenRendering/app/src/main/res/values-v14/
58 | * NDKOpenGLOffscreenRendering/app/src/main/res/values-v14/styles.xml
59 | * NDKOpenGLOffscreenRendering/app/src/main/res/values/
60 | * NDKOpenGLOffscreenRendering/app/src/main/res/values/dimens.xml
61 | * NDKOpenGLOffscreenRendering/app/src/main/res/values/strings.xml
62 | * NDKOpenGLOffscreenRendering/app/src/main/res/values/styles.xml
63 | * NDKOpenGLOffscreenRendering/build.gradle
64 | * NDKOpenGLOffscreenRendering/gradle/
65 | * NDKOpenGLOffscreenRendering/gradle/wrapper/
66 | * NDKOpenGLOffscreenRendering/gradle/wrapper/gradle-wrapper.jar
67 | * NDKOpenGLOffscreenRendering/gradle/wrapper/gradle-wrapper.properties
68 | * NDKOpenGLOffscreenRendering/gradlew
69 | * NDKOpenGLOffscreenRendering/gradlew.bat
70 | * NDKOpenGLOffscreenRendering/local.properties
71 | * NDKOpenGLOffscreenRendering/settings.gradle
72 | * README.MD
73 | * ic_launcher-web.png
74 | * javah
75 | * proguard-project.txt
76 | * screenshot.jpg
77 |
78 | Moved Files:
79 | ------------
80 | Android Gradle projects use a different directory structure than ADT
81 | Eclipse projects. Here's how the projects were restructured:
82 |
83 | * AndroidManifest.xml => app/src/main/AndroidManifest.xml
84 | * jni/ => app/src/main/jni/
85 | * lint.xml => app/lint.xml
86 | * res/ => app/src/main/res/
87 | * src/ => app/src/main/java/
88 |
89 | Next Steps:
90 | -----------
91 | You can now build the project. The Gradle project needs network
92 | connectivity to download dependencies.
93 |
94 | Bugs:
95 | -----
96 | If for some reason your project does not build, and you determine that
97 | it is due to a bug or limitation of the Eclipse to Gradle importer,
98 | please file a bug at http://b.android.com with category
99 | Component-Tools.
100 |
101 | (This import summary is for your information only, and can be deleted
102 | after import once you are satisfied with the results.)
103 |
--------------------------------------------------------------------------------
/screenshot.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wysaid/NDKOpenGLOffscreenRendering/092ca356598974e6fb70ce342e812629a9cf1f06/screenshot.jpg
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------