Skip to content

Commit

Permalink
porting hello-libs, Teapot, endless-tunnel to cmake branch
Browse files Browse the repository at this point in the history
  known issue: endless-tunnel audio play is broken on Android-N DP3
               will be fixed in DP4 in audio framework
  • Loading branch information
ggfan committed Jun 2, 2016
1 parent 6f57603 commit 56f5266
Show file tree
Hide file tree
Showing 421 changed files with 73,639 additions and 66 deletions.
7 changes: 7 additions & 0 deletions Teapot/.google/packaging.yaml
@@ -0,0 +1,7 @@
status: PUBLISHED
technologies: [Android, NDK]
categories: [NDK]
languages: [C++, Java]
solutions: [Mobile]
github: googlesamples/android-ndk
license: apache2
53 changes: 53 additions & 0 deletions Teapot/README.md
@@ -0,0 +1,53 @@
Teapot
======
Teapot is an Android C++ sample that draws a Teapot mesh using GLES 2.0 API and [NativeActivity](http://developer.android.com/reference/android/app/NativeActivity.html).

This sample uses the new [Gradle Experimental Android plugin](http://tools.android.com/tech-docs/new-build-system/gradle-experimental) with C++ support.

Pre-requisites
--------------
- Android Studio 2.2+ with [NDK](https://developer.android.com/ndk/) bundle.

Getting Started
---------------
1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open the sample directory.
1. Open *File/Project Structure...*
- Click *Download* or *Select NDK location*.
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.

Screenshots
-----------
![screenshot](screenshot.png)

Support
-------
If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).

Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](../CONTRIBUTING.md) for more details.

- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Google+ Community](https://plus.google.com/communities/105153134372062985968)
- [Android Tools Feedbacks](http://tools.android.com/feedback)

License
-------
Copyright 2015 Google, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
32 changes: 32 additions & 0 deletions Teapot/app/build.gradle
@@ -0,0 +1,32 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion = 23
buildToolsVersion = '23.0.2'

defaultConfig {
applicationId = 'com.sample.teapot'
minSdkVersion 17
targetSdkVersion 22
cmake {
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a'
}
}
buildTypes {
release {
minifyEnabled = false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path 'src/main/cpp/CMakeLists.txt'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha2'
}
32 changes: 32 additions & 0 deletions Teapot/app/src/main/AndroidManifest.xml
@@ -0,0 +1,32 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample.teapot"
android:versionCode="1"
android:versionName="1.0" >

<uses-feature android:glEsVersion="0x00020000"></uses-feature>

<application
android:allowBackup="false"
android:fullBackupContent="false"
android:supportsRtl="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name="com.sample.teapot.TeapotApplication"
>

<!-- Our activity is the built-in NativeActivity framework class.
This will take care of integrating with our NDK code. -->
<activity android:name="com.sample.teapot.TeapotNativeActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden">
<!-- Tell NativeActivity the name of or .so -->
<meta-data android:name="android.app.lib_name"
android:value="TeapotNativeActivity" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
47 changes: 47 additions & 0 deletions Teapot/app/src/main/assets/Shaders/ShaderPlain.fsh
@@ -0,0 +1,47 @@
//
// Copyright (C) 2015 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ShaderPlain.fsh
//

#define USE_PHONG (1)

uniform lowp vec3 vMaterialAmbient;
uniform mediump vec4 vMaterialSpecular;

varying lowp vec4 colorDiffuse;

#if USE_PHONG
uniform highp vec3 vLight0;
varying mediump vec3 position;
varying mediump vec3 normal;
#else
varying lowp vec4 colorSpecular;
#endif

void main()
{
#if USE_PHONG
mediump vec3 halfVector = normalize(-vLight0 + position);
mediump float NdotH = max(dot(normalize(normal), halfVector), 0.0);
mediump float fPower = vMaterialSpecular.w;
mediump float specular = pow(NdotH, fPower);

lowp vec4 colorSpecular = vec4( vMaterialSpecular.xyz * specular, 1 );
gl_FragColor = colorDiffuse + colorSpecular;
#else
gl_FragColor = colorDiffuse + colorSpecular;
#endif
}
68 changes: 68 additions & 0 deletions Teapot/app/src/main/assets/Shaders/VS_ShaderPlain.vsh
@@ -0,0 +1,68 @@
//
// Copyright (C) 2015 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ShaderPlain.vsh
//

#define USE_PHONG (1)

attribute highp vec3 myVertex;
attribute highp vec3 myNormal;
attribute mediump vec2 myUV;
attribute mediump vec4 myBone;

varying mediump vec2 texCoord;
varying lowp vec4 colorDiffuse;

#if USE_PHONG
varying mediump vec3 position;
varying mediump vec3 normal;
#else
varying lowp vec4 colorSpecular;
#endif

uniform highp mat4 uMVMatrix;
uniform highp mat4 uPMatrix;

uniform highp vec3 vLight0;

uniform lowp vec4 vMaterialDiffuse;
uniform lowp vec3 vMaterialAmbient;
uniform lowp vec4 vMaterialSpecular;

void main(void)
{
highp vec4 p = vec4(myVertex,1);
gl_Position = uPMatrix * p;

texCoord = myUV;

highp vec3 worldNormal = vec3(mat3(uMVMatrix[0].xyz, uMVMatrix[1].xyz, uMVMatrix[2].xyz) * myNormal);
highp vec3 ecPosition = p.xyz;

colorDiffuse = dot( worldNormal, normalize(-vLight0+ecPosition) ) * vMaterialDiffuse + vec4( vMaterialAmbient, 1 );

#if USE_PHONG
normal = worldNormal;
position = ecPosition;
#else
highp vec3 halfVector = normalize(ecPosition - vLight0);

highp float NdotH = max(-dot(worldNormal, halfVector), 0.0);
float fPower = vMaterialSpecular.w;
highp float specular = min( pow(NdotH, fPower), 1.0);
colorSpecular = vec4( vMaterialSpecular.xyz * specular, 1 );
#endif
}
36 changes: 36 additions & 0 deletions Teapot/app/src/main/cpp/CMakeLists.txt
@@ -0,0 +1,36 @@
#
# Copyright (C) The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

cmake_minimum_required(VERSION 3.4.1)

set(CMAKE_VERBOSE_MAKEFILE on)

# build native_app_glue as a static lib
include_directories(${ANDROID_NDK}/sources/android/native_app_glue)
add_library(app-glue STATIC
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)

# now build app's shared lib
include_directories(./ndk_helper
${ANDROID_NDK}/sources/android/cpufeatures)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -Wall -fno-exceptions -fno-rtti")
file(GLOB_RECURSE teapot_SRCS ./*.c*)
add_library(TeapotNativeActivity SHARED ${teapot_SRCS})

# add lib dependencies
target_link_libraries(TeapotNativeActivity android log EGL GLESv2 atomic app-glue)

0 comments on commit 56f5266

Please sign in to comment.