Coder Social home page Coder Social logo

gles30_programmingguide_ndk's Introduction

GLES30_ProgrammingGuide_NDK

C with NDK Android GLES Tutorial

For test & write shader easily ,I use ShaderFrog to write GLSL

For convert Text to C string literal,I use Text -> C/C++ string converter

For convert png/jpg to tga texture format,I use Online-Convert

How to

1.Download or clone this project,inside the folder,create Android Studio Project

2.Add JNI Folder In AS,for AS Load JNILibs easily,my JNI Folder path is:${Project}/app/jni,Drag Android.mk Application.mk(in template) into JNI Folder,also add your Clang files into JNI Folder

3.Edit the Android.mk Files

LOCAL_PATH          := $(call my-dir)
                    //Locate Common Folder
SRC_PATH            := ../../.. 
COMMON_PATH         := $(SRC_PATH)/Common
COMMON_INC_PATH     := $(COMMON_PATH)/Include
COMMON_SRC_PATH     := $(COMMON_PATH)/Source

include $(CLEAR_VARS)
//Module Name
LOCAL_MODULE    := Hello_Triangle
LOCAL_CFLAGS    += -DANDROID


LOCAL_SRC_FILES := $(COMMON_SRC_PATH)/esShader.c \
                   $(COMMON_SRC_PATH)/esShapes.c \
                   $(COMMON_SRC_PATH)/esTransform.c \
                   $(COMMON_SRC_PATH)/esUtil.c \
                   $(COMMON_SRC_PATH)/Android/esUtil_Android.c \
                   //Your Clang Class 
                   $(LOCAL_PATH)/Hello_Triangle.c
                   
                   
                   

LOCAL_C_INCLUDES    := $(SRC_PATH) \
                       $(COMMON_INC_PATH)
                   
LOCAL_LDLIBS    := -llog -landroid -lEGL -lGLESv3

LOCAL_STATIC_LIBRARIES := android_native_app_glue

include $(BUILD_SHARED_LIBRARY)

$(call import-module,android/native_app_glue)

4.Edit the Application.mk

5.Edit the AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.martinrgb.chapter2_hellotriangle">
        <application
            android:label="HelloTriangle"
            android:hasCode="false">
            <activity android:name="android.app.NativeActivity"
                android:label="HelloTriangle"
                android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
                android:launchMode="singleTask"
                android:configChanges="orientation|keyboardHidden">
            
                //The value should be as same as LOCAL_MODULE in android.mk
                <meta-data android:name="android.app.lib_name"
                    android:value="Hello_Triangle" />
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
        <uses-feature android:glEsVersion="0x00030000"/>
        <uses-sdk android:minSdkVersion="18"/>
</manifest>

6.open terminal,direct the JNI Folder, ndk-build

7.in build.gradle

//This snippets will hide the c&mk files
sourceSets.main {
    jniLibs.srcDir 'libs'
    jni.srcDirs = []
}

8.CMD + R,run your project

Further Reading

for C interact With Java,you can read these:

1.Calling OpenGL from C on Android, Using the NDK

2.With Gradle 0.7.2+ you can put your native libraries directly into src/main/jniLibs and it will work automatically. https://stackoverflow.com/a/22488155/1636584 https://stackoverflow.com/a/16993006/1636584

3.How to define NDK_MODULE_PATH

For Example in Android.mk,you need define the local static lib's path

LOCAL_STATIC_LIBRARIES := libpng
...
$(call import-module,third_party/libpng)

In ~/.bash_profile,you need define `NDK_MODULE_PATH':

export NDK_MODULE_PATH=/Users/MartinRGB/Library/Android/sdk/ndk-bundle/sources

also you need download libpng-android,ndk-build to complie,then put it into ${NDK_MODULE_PATH}/third_party

at last,in JNI Folder,ndk-build

4.Secret of android.mk

Concept & Optimization tips

See in the Wiki

gles30_programmingguide_ndk's People

Contributors

martinrgb avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.