Hello everyone, I will update my knowledge about android3d from today! I have just been in touch with android3d, so please point out any errors!
When you play 3D games in windows, DirectX acceleration is required for computers. The OpenGL and DirectX mentioned here are actually similar, but they are also quite different:
DirectX is developed by Microsoft. It only supports Microsoft's own platforms, such as Windows, Xbox 360... and contains graphics, sound, input, network, and other modules.
While OpenGL can be cross-platform, it is just a graphics function library.
There is still a history of OpenGL and DirectX!
Google OpenGL to get an explanation: OpenGL (Open graphics library) is a specification that defines a cross-programming language and cross-platform programming interface, it is used for three-dimensional images (two-dimensional images can also be used ). OpenGL is a professional graphical program interface and is a powerful underlying graphics library with convenient calling.
Android uses a subset of OpenGL ES (OpenGL for Embedded Systems (Embedded Systems) as the embedded version of OpenGL.
Let's look at Android ndk again: it allows Android app developers to embed local machine code compiled from C, C ++ source code files into their respective app packages.
JNI: A local programming interface that enables Java code to interact with applications and libraries written in other programming languages (such as C, C ++, and assembly languages.
Using C/C ++ to directly write OpenGL programs is still more efficient. So I use ndk to develop OpenGL. I am a newbie in this regard (I haven't written C for a long time ).
Step 1 download Android ndk:
Windows:
Http://dl.google.com/android/ndk/android-ndk-r4-windows.zip
Linux:
Http://www.ideasandroid.com/android/sdk/android-ndk-r4-linux-x86.zip
I am using the Ubuntu system to develop Android, so I will talk about the configuration in Linux:
Decompress ndk, my path is/home/dev/android-ndk-r4-linux-x86
Open the terminal and execute sudo gedit/etc/profile
Add the following content to the end of the file:
# Set ndk env
Ndkroot =
/Home/dev/android-ndk-r4-linux-x86
Export Path = $ ndkroot: $ path
Note that the ndkroot path corresponds to the decompressed path!
Save and restart the system.
OK. Now the ndk is installed. Let's write the first ndk program.
Open eclipse to create an android project: Activity name hellondk
Create a JNI folder in the root directory and create two files in it:
Android. mk is used to tell ndk which files need to be compiled and which modules are generated.
Hello-ndk.c C Language Program
Copy the following content to Android. mk:
Local_path: = $ (call my-DIR) <br/> include $ (clear_vars) <br/> local_module: = hello-ndk <br/> local_src_files: = hello-ndk.c <br/> include $ (build_shared_library)
Local_path indicates the location of the C source code file
Local_module indicates the name of the generated shared library.
Local_src_files indicates the file of C code written by ourselves.
Then copy the following content to the hello-ndk.c:
# Include <string. h> <br/> # include <JNI. h> <br/> jstring <br/> java_com_ldj_hellondk_hellondk_stringfromjni (jnienv * ENV, <br/> jobject thiz) <br/>{ <br/> return (* env) -> newstringutf (ENV, "hello from ndk! "); <Br/>}
Note: com_example_hellondk_hellondk_stringfromjni:
Com _... hellondk refers to the package name, hellondk refers to the corresponding class name, And stringfromjni refers to the corresponding method name, which can be seen after the Java program is written.
In this step, open the Linux terminal, change the path to the JNI folder directory in your project, and use the ndk-build command. If the command is successful, you will be prompted to refresh the directory of the following project.
There are two more folders in the project: libs and obj. We will discuss the content here later. After this step, you can edit hellondk. Java:
Package COM. ldj. hellondk; <br/> Import android. app. activity; <br/> Import android. OS. bundle; <br/> Import android. widget. textview; <br/> public class hellondk extends activity {<br/> @ override <br/> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> textview TV = new textview (this ); <br/> // set the TV display content to the return value of the C program method <br/> TV. settext (stringfromjni (); <br/> setcontentview (TV ); <br/>}< br/> // method corresponding to the hello-jni.c <br/> Public native string stringfromjni (); <br/> static {<br/> // load the Local Shared Library <br/> system. loadlibrary ("hello-ndk"); <br/>}< br/>}
Relatively simple, see the figure:
Summary:
Generally, errors occur when the class names in the C language are not written. ndk-build is required for each change to the content of the two files in JNI, And then refresh the project, if you have any questions or errors, please leave a message and reply as soon as possible.
The first ndk program came out! Some conceptual questions are still unclear, but I am a little familiar with ndk.