Development Environment Setup

quantityforeheadΚινητά – Ασύρματες Τεχνολογίες

10 Δεκ 2013 (πριν από 3 χρόνια και 10 μήνες)

84 εμφανίσεις

Institute for Computer Graphics and Vision
Development
Environment Setup
Mobile Visual Computing
Institute for Computer Graphics and Vision
Development Environment Setup

Copy VCDevEnv to C:\

Install driver for your device

C:\VCDevEnv\drivers

Run C:\VCDevEnv\startEclipse.bat
Institute for Computer Graphics and Vision
Check device

Command line

%adb% device

%adb% commands

push

pull

...
C:\VCDevEnv\examples\01-ogles2Tut01\shader>%adb% devices
List of devices attached
0149CC3807017004 device
Institute for Computer Graphics and Vision
Example programs

Run program ...

Build

Run

Device tap

kill

restart

Logging

log tab
Institute for Computer Graphics and Vision
Own project

Create new Android project

Create Java classes for main types
onCreate
onPause
onResume
Activity
setRenderer
GLSurfaceView
onSurfaceCreated
onSurfaceChanged
onDrawFrame
Renderer
onSurfaceCreated
onSurfaceChanged
onDrawFrame
ExampleRenderer
setRenderer
ExampleView
onCreate
onPause
onResume
ExampleActivity
Institute for Computer Graphics and Vision
interface
GLSurfaceView.Renderer
public

class
ExampleRenderer
implements
Renderer {

public

void
onSurfaceCreated(GL10 gl, EGLConfig config){

// called once at setup
}


public

void
onDrawFrame(GL10 arg0) {

// called to redraw the view
}

public

void
onSurfaceChanged(GL10 gl,
int
width,
int
height){


// called when geometry changes
}
}
Institute for Computer Graphics and Vision
integration in Activity
public

class
GL2Ex1Activity
extends
Activity {


private
GLSurfaceView
glview
;


/** Called when the activity is first created. */

@Override

public

void
onCreate(Bundle savedInstanceState) {

super
.onCreate(savedInstanceState);


glview
=
new
GLSurfaceView(
this
);

glview
.setEGLContextClientVersion(2);

glview
.setRenderer(
new
ExampleRenderer());
setContentView(
glview
);
}


protected

void
onPause(){

super
.onPause();

glview
.onPause();
}


protected

void
onResume(){

super
.onResume();

glview
.onResume();
}
}
Institute for Computer Graphics and Vision
Setup OpenGL ES 2.0

Add to AndroidManifest.xml

Enable 2.0 in GLSurfaceView
<
uses-feature

android:glEsVersion
=
"0x00020000"

android:required
=
"true"

/>

glview
=
new
GLSurfaceView(
this
);

glview
.setEGLContextClientVersion(2);
Institute for Computer Graphics and Vision
JNI - Java Native Interface

Extending Java with native (C/C++) code

NDK

Create

a Java class with native methods

directory
jni

example.cpp
C++ source file

Android.mk
build file

Setup builder for compilation
Institute for Computer Graphics and Vision
Java class with native methods
package
com.android.gl2ex1;
public

class
Example {

static
{

// name of native shared library
System.loadLibrary(
"gl2ex1"
);
}


public

static

native

void
onSurfaceCreated();

public

static

native

void
onDrawFrame();

public

static

native

void
onSurfaceChanged(
int
w,
int
h);
}
Institute for Computer Graphics and Vision
example.cpp
C++ source file
extern

"C"
{
JNIEXPORT
void
JNICALL Java_com_android_gl2ex1_Example_onSurfaceCreated
(JNIEnv * env, jobject obj)
{
printGLString(
"Version"
, GL_VERSION);
printGLString(
"Vendor"
, GL_VENDOR);
printGLString(
"Renderer"
, GL_RENDERER);
printGLString(
"Extensions"
, GL_EXTENSIONS);
glClearColor(0, 0, 1, 1);
}
JNIEXPORT
void
JNICALL Java_com_android_gl2ex1_Example_onDrawFrame
(JNIEnv * env, jobject obj)
{
glClear( GL_COLOR_BUFFER_BIT);
}
JNIEXPORT
void
JNICALL Java_com_android_gl2ex1_Example_onSurfaceChanged
(JNIEnv * env, jobject obj, jint width, jint height)
{
glViewport(0, 0, width, height);
}
}

Naming convention
package_package_Class_method
Institute for Computer Graphics and Vision
Android.mk
build file

setup builder ...
LOCAL_PATH:
=
$(call my-dir)
include

$(CLEAR_VARS)

LOCAL_MODULE :
= gl2ex1 # library name
LOCAL_CFLAGS :
= -Werror
LOCAL_SRC_FILES :
= example.cpp # source files
LOCAL_LDLIBS :
= -llog -lGLESv2 -lstdc++
include

$(BUILD_SHARED_LIBRARY)
Institute for Computer Graphics and Vision
Implement Renderer in native code
public

class
ExampleRenderer
implements
Renderer {

public

void
onSurfaceCreated(GL10 gl, EGLConfig config){

// called once at setup
Example.onSurfaceCreated();
}


public

void
onDrawFrame(GL10 arg0) {

// called to redraw the view

Example.onDrawFrame();
}

public

void
onSurfaceChanged(GL10 gl,
int
width,
int
height){


// called when geometry changes

Example.onSurfaceChanged(width, height);
}
}
Institute for Computer Graphics and Vision
Adding menus

Create a menu resource

res/menu/menu.xml as Android xml

Add menu items

Load menu & handle events

public

class

GL2Ex1Activity
{
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.
menu
, menu);

return

true
;
}

public

boolean
onOptionsItemSelected(MenuItem item) {

switch
(item.getItemId()) {

case
R.id.
hello
:
Log.i(
"menu"
,
"got hello"
);

return

true
;

case
R.id.
test
:
Log.i(
"menu"
,
"got test"
);

return

true
;

default
:

return

super
.onOptionsItemSelected(item);
}
}
}