JNI: Getting Started

Write something simple in a java class such as below:
package com.sample;

class HelloWorld {
public native void print();
public static void main(String[] args) {
new HelloWorld().print();
}
static {
System.loadLibrary("HelloWorld");
}
}


Compile the java class

javac HelloWorld

Use javah to spit out the JNI header file

javah -jni -classpath "(path.to.src)" com.sample.HelloWorld

ANDROID: Pulling libraries from the android device

adb pull (file) (local)

for example, I pulled the system/lib to my local c:\libs

adb pull system/lib c:\libs

UNIX: Debugging the contents of a Shared Object file

If you just wanted to see basic header info (not even that preceise), then you could use the following unix command to look into a shared object ((filename).so) file.

nm (directory)\(filename).so

If this is still not working. Try appending -C -D at the end like so:

nm (directory)\(filename).so -C -D

I found this info on some google forum:
http://www.mail-archive.com/.../msg00935.html

The guy also mentioned using the following configurations:
arm-none-linux-gnueabi-nm
arm-none-linux-gnueabi-objdump

ANDROID: Starting the Android emulator

here's how to start your android emulator via command prompt:

1. if you haven't already, create an AVD (android virtual device)
android create avd -n (name) -t (targetID) [-(option) (value)]
where the target id (ie. 4 for android 1.6) can be obtained via:

android list targets

2. list available AVDs

(android.tools.directory)\android list avds

3. starting your AVD

(android.tools.directory)\emulator -avd

for more information goto:

http://developer.android.com/.../tools/avd.html

ANDROID: Installation errors

This is a part 2 to the previous post on installation.

During installation I received the following failure:

Failure [INSTALL_FAILED_INSUFFICIENT_STORAGE]

You can turn on Logcat to debug the installation failure:

adb logcat

My Logcat yielded the following errors:

E/PackageParser( 74): Package com.website.mclass has no certificates at entry assets/; ignoring!

To solve this issue, you need to sign the apk file before installing. Here's how:

jarsigner -verbose -keystore
(directory)\debug.keystore (directory)\(filename).apk androiddebugkey

The default passphrase is android

To verify the certification, you can again use jarsigner:

jarsigner -verify -verbose -certs (directory)\(filename).apk

The last command line printout should now read:

jar verified.

ANDROID: Installing application

There are 2 ways to install a pre-built applications:

1. command prompt

adb install (directory)\(filename).apk

2. SD card

A. install the apk to the phone SD card
B. insert SD card to phone
C. goto Android Marketplace, search for Apps Installer application
D. open and click Install
E. open Apps Installer
F. select the application you want to install
G. click on install

ANDROID: adb shell commands

For the times you want to log onto the unix command prompt of the device itself, you want to use the following command:

adb shell

this will convert the prompt into:

#

now you can start using unix commands as usual:

ps = list all processes
kill = kill specific process

OpenGL + OpenVG

Here's my findings on the 2 technologies:

Imagination Technologies:
--------------------------------------------
| OpenVG emulator | OpenGL ES 2.0 emulator |
--------------------------------------------
The two technologies are individually packaged, so there is no support for combining these 2 technologies at this time by imgtec.

AMD:
--------------------------
| OpenGL ES 2.0 emulator |
--------------------------
AMD does not have a OpenVG emulator


So... Theoretically the 2 technologies can only be combined if the following is satisfied: A single emulator/device, that supports BOTH OpenVG and OpenGL, sharing the same EGL libraries. In other words, the EGL must have support for BOTH OpenVG and OpenGL ES 2.0. The EGL is the key.

-----------------------------------
| GL ES 2.0 | VG |
| ----------- |
| | | |
| | E G L | |
-----------------------------------

OpenGL: What is EGL

Taken from Khronos: http://www.khronos.org/egl/

EGL™ is an interface between Khronos rendering APIs such as OpenGL ES or OpenVG and the underlying native platform window system. It handles graphics context management, surface/buffer binding, and rendering synchronization and enables high-performance, accelerated, mixed-mode 2D and 3D rendering using other Khronos APIs.

OpenGL: Toggling the DepthMask

glDepthMask(GL_TRUE/GL_FALSE);

Sometimes in blending, you will want to inter-mix opaque & translucent objects.

Here's the 2 obvious scenarios:
1. If the opaque object is in front of translucent object, we don't need to blend
2. If the translucent object is in front of the opaque object, we need to blend

There's a easy way to ensure the blending always works as expected. This is to render the opaque object FIRST with the writable depth buffer. And then render the translucent object with a read-only depth buffer. This can be done by using glDepthMask.

This way the renderer will automatically compare the translucent object's depth position with that of the read-only opaque object depth position. Blending is done only when needed, and buffer remains unchanged.

OpenGL: Blending Formula

Taken from the Red Book:

Let the source and destination blending factors be (Sr, Sg, Sb, Sa) and (Dr, Dg, Db, Da), respectively, and the RGBA values of the source and destination be indicated with a subscript of s or d. Then the final, blended RGBA values are given by

(RsSr+RdDr, GsSg+GdDg, BsSb+BdDb, AsSa+AdDa)


Expanded:

red = Red(src)*Red(srcBlendFactor) +
Red(dest)*Red(destBlendFactor)
green = Green(src)*Green(srcBlendFactor) +
Green(dest)*Green(destBlendFactor)
blue = Blue(src)*Blue(srcBlendFactor) +
Blue(dest)*Blue(destBlendFactor)
alpha = Alpha(src)*Alpha(srcBlendFactor) +
Alpha(dest)*Alpha(destBlendFactor)

OpenGL: Rendering Pipelines

Here's 2 flow-charts explaining the 2 types of rendering pipelines.



Here are some typical uses for the programmable function pipeline:

Done within the Vertex stage:
- vertex displacement mapping
- morphing
- particle systems

Done within the Pixel stage:
- per pixel lighting
- toon shading (I'm guessing this is cell-shading)
- parallax mapping
- bump mapping
- custom texture filtering
- color kernel applications

OpenGL: Blending

Here's are 2 tabular guides on blending effects:



Win32: Setting up OpenVG

I'm completely new to the OpenVG sphere, so this is the very basic of basics. How to run the openVG RI from Khronos site...

First, I downloaded the RI from the site at: http://www.khronos.org/files/openvg_1_0_ri

Unzip the package, and attempt to run the bin\wind32\tiger.exe file

If you got a MSVCRTD.dll is missing, this is because you aren't using Visual Studio 6 (or some other prehistoric version).

I don't recommend this, but you CAN find MSVCRTD.dll online, and throw it into your System32 directory. I found the dll inside some symbian directory... threw it in my System32 directory, and the tiger popped up like a charm... after 2 minutes of loading...

The second, and preferred method, is to recompile the project using your version of Visual Studio (mine is V9). Well I got stumped again when I tried compiling. The application couldn't find GL\glext.h

To solve this download the glext.h from: http://www.opengl.org/resources/faq/technical/extensions.htm

Throw this file inside the VC/include/GL folder (create the GL directory if it doesn't already exist).

The full path of said directory is at (for Visual Studio V9):
C:\Program Files\Microsoft Visual Studio 9.0\VC\include\GL

Inside this directory I now have the following:
- glut.h
- glext.h
- glxext.h
- wglext.h

If you also need glut.h, you should refer to an earlier post I wrote about setting up GLUT on your system.

3D: Shaders

did some research on shaders:

FROM: http://en.wikipedia.org/wiki/Shader
A shader is a set of software instructions, which is used to calculate rendering effects on GPU. Shaders can program the GPU's programmable rendering pipeline (as opposed to Fixed Function Pipeline, or FFP). Shaders replaces the FFP.

Shaders help determine the traits of a vertex or pixel. There are 3 types of shaders:
1. Vertex shaders: these are run once per vertex. manipulates position, color and tex-coordinates of vertices.
2. Geometry shaders: can add or remove vertices from a mesh (caused by plane-clipping, etc).
3. Pixel/fragment shaders: determines trait of a single pixel (color, z, alpha). typically used in scene lighting, bump-mapping, color toning.

Programming shaders can be done in the following 3D languages: OpenGL, DirectX.
1. DirectX for ATI uses HLSL (high level shader language)
2. DirectX for NVidia uses Cg (C for graphics, very similar to HLSL)
3. OpenGL uses GLSL (OpenGL Shading Language)

IPHONE: User-defined constructor/destructor

This is actually the second time I've come across this issue. Unfortunately I did not post the solution last time, so I had to go look it up again...

The WARNING:
type 'SomeClassType' has a user-defined constructor
tyep 'SomeClassType' has a user-defined destructor

The SOLUTION:
convert object declarations into pointer declarations. for example:
@interface myclass {
@private
SomeClassType myInstance;
}

change to:
@interface myclass {
@private
SomeClassType* myInstancePtr;
}

Of course, this also means you will have to manually control the instantiation & destruction of the object with new & free.

ANDROID: logcat on device

Here's another gripe. When you have both the emulator & device running, the adb logcat doesn't know which to listen to, and as a result outputs NOTHING.

to solve you'd simply close the emulator or device, whichever you aren't currently using.

also, as an added bonus, I found out how to cue up logcat via command prompt:

adb logcat -s DEVICE_NAME

ANDROID: Cannot create linked resource...

Here's the second error today. While attempting to import the Android project, or attempting to create a new Android project, I kept getting the error:

Cannot create linked resource '/.org.eclipse.jdt.core.external.folders/.link0'. The parent resource is not accessible.

Solution:
Unfortunately, this means it's time to ditch your workspace and create a new one... save your preferences (esp your key bindings), and move your Eclipse workspace to a new location. This should fix the issue.

Other solutions I've found online:
- Reinstalling Eclipse (overkill)
- Reinstalling Android SDK (probably won't help)
- eclipse.exe -clean (doesn't clean the workspace)

Nevertheless, you should try the -clean method, just in case it works for you.


ANDROID: Could not find *.apk!

SEVERAL very annoying errors popped up today as I was dev-ing for Android. This post describes & solves the first of these errors.

Description of Error:
While attempting to build the android project the following message will pop up in the Console

[2009-11-02 16:28:51 - AndroidGL]Android Launch!
[2009-11-02 16:28:51 - AndroidGL]adb is running normally.
[2009-11-02 16:28:51 - AndroidGL]Could not find ********.apk!

Solution:
Make sure your project imported the Android 1.6 library correctly. That is, under your project, you should see 'Android 1.6', which expands and displays 'android.jar'.

If it says Referenced Libraries > android.jar, you will need to fix this by manually altering the .classpath for the project.

Open .classpath for the project and type the following:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<kind="src" path="src">
<kind="src" path="gen">
<kind="con" path="com.android.ide.eclipse.adt.
ANDROID_FRAMEWORK">
<kind="output" path="bin">
</classpath>

The important line is the 3rd classpathentry, which is the actual link to the Android SDK libraries.