Skip to content

Commit

Permalink
Android fixes (#6446)
Browse files Browse the repository at this point in the history
* Add OpenCV libs for Android Arm64.

* Fix missing semi-colon :/

* Fix shader not displaying in androidShaderExample.

#changelog #android
  • Loading branch information
prisonerjohn authored and arturoc committed Nov 13, 2019
1 parent b1c6ab8 commit 5f191cc
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 85 deletions.
17 changes: 17 additions & 0 deletions addons/ofxOpenCv/addon_config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,23 @@ android/armeabi-v7a:
ADDON_LIBS += libs/opencv/lib/android/armeabi-v7a/libquirc.a
ADDON_LIBS += libs/opencv/lib/android/armeabi-v7a/liblibprotobuf.a

android/arm64-v8a:
ADDON_LIBS =
ADDON_LIBS += libs/opencv/lib/android/arm64-v8a/libopencv_dnn.a
ADDON_LIBS += libs/opencv/lib/android/arm64-v8a/libopencv_photo.a
ADDON_LIBS += libs/opencv/lib/android/arm64-v8a/libopencv_stitching.a
ADDON_LIBS += libs/opencv/lib/android/arm64-v8a/libopencv_calib3d.a
ADDON_LIBS += libs/opencv/lib/android/arm64-v8a/libopencv_features2d.a
ADDON_LIBS += libs/opencv/lib/android/arm64-v8a/libopencv_objdetect.a
ADDON_LIBS += libs/opencv/lib/android/arm64-v8a/libopencv_video.a
ADDON_LIBS += libs/opencv/lib/android/arm64-v8a/libopencv_videoio.a
ADDON_LIBS += libs/opencv/lib/android/arm64-v8a/libopencv_imgproc.a
ADDON_LIBS += libs/opencv/lib/android/arm64-v8a/libopencv_ml.a
ADDON_LIBS += libs/opencv/lib/android/arm64-v8a/libopencv_core.a
ADDON_LIBS += libs/opencv/lib/android/arm64-v8a/libopencv_flann.a
ADDON_LIBS += libs/opencv/lib/android/arm64-v8a/libquirc.a
ADDON_LIBS += libs/opencv/lib/android/arm64-v8a/liblibprotobuf.a

emscripten:
ADDON_LIBS =
ADDON_LIBS += libs/opencv/lib/emscripten/libopencv_dnn.a
Expand Down
2 changes: 1 addition & 1 deletion examples/android/androidCameraExample/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void ofApp::setup(){

// Set the pixel format for getPixels to grayscale
// (other image formats will include heavy colorspace conversion)
grabber.setPixelFormat(OF_PIXELS_GRAY)
grabber.setPixelFormat(OF_PIXELS_GRAY);

// Hint the grabber if you don't need pixel data for better performance
//((ofxAndroidVideoGrabber*)grabber.getGrabber().get())->setUsePixels(false);
Expand Down
27 changes: 0 additions & 27 deletions examples/android/androidShaderExample/bin/data/shaders/Shader.fsh

This file was deleted.

16 changes: 0 additions & 16 deletions examples/android/androidShaderExample/bin/data/shaders/Shader.vsh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ void main(){
//this is the fragment shader
//this is where the pixel level drawing happens
//gl_FragCoord gives us the x and y of the current pixel its drawing

//we grab the x and y and store them in an int
float xVal = gl_FragCoord.x;
float yVal = gl_FragCoord.y;



//we use the mod function to only draw pixels if they are every 2 in x or every 4 in y
if( mod(xVal, 2.0) == 0.0 && mod(yVal, 4.0) == 0.0 ){
gl_FragColor = globalColor;
}else{
if( mod(xVal, 2.0) == 0.5 && mod(yVal, 4.0) == 0.5 ){
gl_FragColor = globalColor;
}else{
discard;
}
}

}
44 changes: 21 additions & 23 deletions examples/android/androidShaderExample/bin/data/shaders/noise.vert
Original file line number Diff line number Diff line change
@@ -1,55 +1,53 @@
#ifdef GL_ES
// define default precision for float, vec, mat.
precision highp float;
#endif

attribute vec4 position;
attribute vec4 color;
attribute vec4 normal;
attribute vec2 texcoord;

uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform mat4 modelViewProjectionMatrix;

varying vec4 colorVarying;
varying vec2 texCoordVarying;

uniform float timeValX;
uniform float timeValY;
uniform vec2 mouse;

//generate a random value from four points
vec4 rand(vec2 A,vec2 B,vec2 C,vec2 D){
vec4 rand(vec2 A,vec2 B,vec2 C,vec2 D){

vec2 s=vec2(12.9898,78.233);
vec4 tmp=vec4(dot(A,s),dot(B,s),dot(C,s),dot(D,s));
vec2 s=vec2(12.9898,78.233);
vec4 tmp=vec4(dot(A,s),dot(B,s),dot(C,s),dot(D,s));

return fract(sin(tmp) * 43758.5453)* 2.0 - 1.0;
}
return fract(sin(tmp) * 43758.5453)* 2.0 - 1.0;
}

//this is similar to a perlin noise function
float noise(vec2 coord,float d){
float noise(vec2 coord,float d){

vec2 C[4];
vec2 C[4];

float d1 = 1.0/d;

C[0]=floor(coord*d)*d1;
C[0]=floor(coord*d)*d1;

C[1]=C[0]+vec2(d1,0.0);
C[1]=C[0]+vec2(d1,0.0);

C[2]=C[0]+vec2(d1,d1);
C[2]=C[0]+vec2(d1,d1);

C[3]=C[0]+vec2(0.0,d1);


vec2 p=fract(coord*d);
vec2 p=fract(coord*d);

vec2 q=1.0-p;
vec2 q=1.0-p;

vec4 w=vec4(q.x*q.y,p.x*q.y,p.x*p.y,q.x*p.y);
vec4 w=vec4(q.x*q.y,p.x*q.y,p.x*p.y,q.x*p.y);

return dot(vec4(rand(C[0],C[1],C[2],C[3])),w);
}
return dot(vec4(rand(C[0],C[1],C[2],C[3])),w);
}


void main(){

//get our current vertex position so we can modify it
vec4 pos = modelViewProjectionMatrix * position;

Expand Down
21 changes: 11 additions & 10 deletions examples/android/androidShaderExample/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ void ofApp::setup(){
shader.load("shaders/noise.vert", "shaders/noise.frag");

auto textShapes = font.getStringAsPoints("openFrameworks");
ofRectangle boundingBox;
for(auto glyph: textShapes){
for (auto glyph : textShapes) {
text.append(glyph);
for(auto outline: glyph.getOutline()){
boundingBox = boundingBox.getUnion(outline.getBoundingBox());
}
}

ofRectangle boundingBox;
for (auto outline : text.getOutline()) {
boundingBox = boundingBox.getUnion(outline.getBoundingBox());
}

boundingBox.alignTo(ofGetCurrentViewport(), OF_ALIGN_HORZ_CENTER, OF_ALIGN_VERT_CENTER);
Expand Down Expand Up @@ -48,21 +49,21 @@ void ofApp::draw(){

}

//finally draw our text
text.draw();
//finally draw our text
text.draw();

if( doShader ){
shader.end();
}
}

//--------------------------------------------------------------
void ofApp::keyPressed (int key){
void ofApp::keyPressed (int key){
}

//--------------------------------------------------------------
void ofApp::keyReleased(int key){
void ofApp::keyReleased(int key){

}

//--------------------------------------------------------------
Expand Down

0 comments on commit 5f191cc

Please sign in to comment.