I am trying to modify the androidShaderExample for android to load my own 3D model and vertex and fragment shader for educational purposes. I borrow code from the 3DModelLoaderExample for loading the 3D squirrel model. I am brand new to openFrameworks for android, and any help would be greatly appreciated.
I am getting the following error:
“called unimplemented OpenGL ES API”
Also, I am not sure if my vertex and fragment shaders will work for OpenGL ES and could use some help modifying them so they run on Android. Thank you in advance.
----main.cpp----
#include "ofMain.h"
#include "ofApp.h"
#include "ofGLProgrammableRenderer.h"
int main(){
ofSetCurrentRenderer(ofGLProgrammableRenderer::TYPE);
ofSetupOpenGL(1024,768, OF_WINDOW); // <-------- setup the GL context
ofRunApp( new ofApp() );
return 0;
}
#ifdef TARGET_ANDROID
#include <jni.h>
//======================================
extern "C"{
void Java_cc_openframeworks_OFAndroid_init( JNIEnv* env, jobject thiz ){
main();
}
}
#endif
---- ofApp.h----
#ifndef _TEST_APP
#define _TEST_APP
#include <GLES2/gl2.h>
#include "ofx3DModelLoader.h"
#include "ofxAndroidApp.h"
#include "ofShader.h"
class ofApp : public ofxAndroidApp{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
void keyReleased(int key);
void windowResized(int w, int h);
void touchDown(int x, int y, int id);
void touchMoved(int x, int y, int id);
void touchUp(int x, int y, int id);
void touchDoubleTap(int x, int y, int id);
void touchCancelled(int x, int y, int id);
void swipe(ofxAndroidSwipeDir swipeDir, int id);
void pause();
void stop();
void resume();
void reloadTextures();
bool backPressed();
void okPressed();
void cancelPressed();
ofShader shader;
bool doShader;
ofx3DModelLoader squirrelModel;
};
#endif
----ofApp.cpp----
#include "ofApp.h"
GLfloat lightOnePosition[] = {40.0, 40, 100.0, 0.0};
GLfloat lightOneColor[] = {0.99, 0.99, 0.99, 1.0};
GLfloat lightTwoPosition[] = {-40.0, 40, 100.0, 0.0};
GLfloat lightTwoColor[] = {0.99, 0.99, 0.99, 1.0};
//---------------------------------------
void ofApp::setup(){
ofBackground(0,0,0);
ofEnableAlphaBlending();
ofEnableBlendMode(OF_BLENDMODE_ADD);
squirrelModel.loadModel("shaders/VertibraeCentered.3ds", 10.0);
squirrelModel.setRotation(0, 90, 1, 0, 0);
squirrelModel.setRotation(1, 270, 0, 0, 1);
squirrelModel.setScale(0.9, 0.9, 0.9);
squirrelModel.setPosition(ofGetWidth()/2, ofGetHeight()/2, 0);
shader.load("shaders/x-ray.vert", "shaders/x-ray.frag");
doShader = true;
//---------------------------------------
void ofApp::update(){
squirrelModel.setRotation(1, 270 + ofGetElapsedTimef() * 60, 0, 0, 1);
}
//--------------------------------------
void ofApp::draw(){
//lets tumble the world with the mouse
glPushMatrix();
//draw in middle of the screen
glTranslatef(ofGetWidth()/2,ofGetHeight()/2,0);
//tumble according to mouse
glRotatef(-mouseY,1,0,0);
glRotatef(mouseX,0,1,0);
glTranslatef(-ofGetWidth()/2,-ofGetHeight()/2,0);
ofSetColor(255, 255, 255, 255);
squirrelModel.draw();
if(doShader){
shader.begin();
}
glPopMatrix();
ofSetHexColor(0xFFFFFF);
ofDrawBitmapString("fps: "+ofToString(ofGetFrameRate(), 2), 10, 15);
}
void ofApp::reloadTextures(){
shader.load("shaders/x-ray.vert", "shaders/x-ray.frag");
}
bool ofApp::backPressed(){
return false;
}
----x-ray.vert----
// Application to vertex shader
varying vec3 N;
varying vec3 I;
varying vec4 Cs;
void main()
{
vec4 P = gl_ModelViewMatrix * gl_Vertex;
I = P.xyz - vec3 (0);
N = gl_NormalMatrix * gl_Normal;
Cs = gl_Color;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
----x-ray.frag----
#ifdef GL_ES
/* define default precision for float, vec, mat. */
precision highp float;
#endif
// vertex to fragment shader io
varying vec3 N;
varying vec3 I;
varying vec4 Cs;
// globals
float edgefalloff=.8;
float intensity=.5;
float ambient=.350;
// entry point
void main()
{
float opac = dot(normalize(-N), normalize(-I));
opac = abs(opac);
opac = ambient + intensity*(1.0-pow(opac, edgefalloff));
gl_FragColor = opac * Cs;
gl_FragColor.a = opac;
}