From Jorge Ciges, "two clean example viewers (GLES1/2) that permit load models withouth recompiling by options in the menu and some basic options. basic options.
As Rafa and I told you earlier this can't be integrated in the CMAKE chain. It needs to be compiled by the user out of the OSG standard compilation. It could be stored in the examples. That way users will not come here asking for the examples. Main characteristics are: -Menu with loading and unloading by path. -Return to home view -Keyboard capabilities with manipilator switch and basic state changing. -Change color screen. -Osg log bypassed to LogCat (This comes practically straight from Marcin Hajder example I've only added personal TAG) -Earmbi / Earmbi V7 -Install to SD (if the device supports the feature) And that's all. Now I'm looking to fix the environmental mapping with true GLES (it does not work well in Android) I will try to make it in time for 3.0. The other work that i'm studying Dynamic build with Android but that will need a lot of time to test.
This commit is contained in:
67
examples/osgAndroidExampleGLES1/jni/Android.mk
Normal file
67
examples/osgAndroidExampleGLES1/jni/Android.mk
Normal file
@@ -0,0 +1,67 @@
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := osgNativeLib
|
||||
### Main Install dir
|
||||
OSG_ANDROID_DIR := < type your install directory >
|
||||
LIBDIR := $(OSG_ANDROID_DIR)/obj/local/armeabi
|
||||
|
||||
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
|
||||
LOCAL_ARM_NEON := true
|
||||
LIBDIR := $(OSG_ANDROID_DIR)/obj/local/armeabi-v7a
|
||||
endif
|
||||
|
||||
### Add all source file names to be included in lib separated by a whitespace
|
||||
|
||||
LOCAL_C_INCLUDES:= $(OSG_ANDROID_DIR)/include
|
||||
LOCAL_CFLAGS := -Werror -fno-short-enums
|
||||
LOCAL_CPPFLAGS := -DOSG_LIBRARY_STATIC
|
||||
|
||||
LOCAL_LDLIBS := -llog -lGLESv1_CM -ldl -lz
|
||||
LOCAL_SRC_FILES := osgNativeLib.cpp OsgMainApp.cpp OsgAndroidNotifyHandler.cpp
|
||||
LOCAL_LDFLAGS := -L $(LIBDIR) \
|
||||
-losgdb_dds \
|
||||
-losgdb_openflight \
|
||||
-losgdb_tga \
|
||||
-losgdb_rgb \
|
||||
-losgdb_osgterrain \
|
||||
-losgdb_osg \
|
||||
-losgdb_ive \
|
||||
-losgdb_deprecated_osgviewer \
|
||||
-losgdb_deprecated_osgvolume \
|
||||
-losgdb_deprecated_osgtext \
|
||||
-losgdb_deprecated_osgterrain \
|
||||
-losgdb_deprecated_osgsim \
|
||||
-losgdb_deprecated_osgshadow \
|
||||
-losgdb_deprecated_osgparticle \
|
||||
-losgdb_deprecated_osgfx \
|
||||
-losgdb_deprecated_osganimation \
|
||||
-losgdb_deprecated_osg \
|
||||
-losgdb_serializers_osgvolume \
|
||||
-losgdb_serializers_osgtext \
|
||||
-losgdb_serializers_osgterrain \
|
||||
-losgdb_serializers_osgsim \
|
||||
-losgdb_serializers_osgshadow \
|
||||
-losgdb_serializers_osgparticle \
|
||||
-losgdb_serializers_osgmanipulator \
|
||||
-losgdb_serializers_osgfx \
|
||||
-losgdb_serializers_osganimation \
|
||||
-losgdb_serializers_osg \
|
||||
-losgViewer \
|
||||
-losgVolume \
|
||||
-losgTerrain \
|
||||
-losgText \
|
||||
-losgShadow \
|
||||
-losgSim \
|
||||
-losgParticle \
|
||||
-losgManipulator \
|
||||
-losgGA \
|
||||
-losgFX \
|
||||
-losgDB \
|
||||
-losgAnimation \
|
||||
-losgUtil \
|
||||
-losg \
|
||||
-lOpenThreads
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
11
examples/osgAndroidExampleGLES1/jni/Application.mk
Normal file
11
examples/osgAndroidExampleGLES1/jni/Application.mk
Normal file
@@ -0,0 +1,11 @@
|
||||
#ANDROID APPLICATION MAKEFILE
|
||||
APP_BUILD_SCRIPT := $(call my-dir)/Android.mk
|
||||
#APP_PROJECT_PATH := $(call my-dir)
|
||||
|
||||
APP_OPTIM := release
|
||||
|
||||
APP_PLATFORM := android-7
|
||||
APP_STL := gnustl_static
|
||||
APP_CPPFLAGS := -fexceptions -frtti
|
||||
APP_ABI := armeabi armeabi-v7a
|
||||
APP_MODULES := osgNativeLib
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* OsgAndroidNotifyHandler.cpp
|
||||
*
|
||||
* Created on: 31/05/2011
|
||||
* Author: Jorge Izquierdo Ciges
|
||||
*/
|
||||
|
||||
#include "OsgAndroidNotifyHandler.hpp"
|
||||
#include <iostream>
|
||||
|
||||
void OsgAndroidNotifyHandler::setTag(std::string tag){
|
||||
_tag = tag;
|
||||
}
|
||||
void OsgAndroidNotifyHandler::notify(osg::NotifySeverity severity, const char *message){
|
||||
|
||||
switch ( severity ) {
|
||||
case osg::DEBUG_FP:
|
||||
__android_log_write(ANDROID_LOG_VERBOSE,_tag.c_str(),message);
|
||||
break;
|
||||
case osg::DEBUG_INFO:
|
||||
__android_log_write(ANDROID_LOG_DEBUG,_tag.c_str(),message);
|
||||
break;
|
||||
case osg::NOTICE:
|
||||
case osg::INFO:
|
||||
__android_log_write(ANDROID_LOG_INFO,_tag.c_str(),message);
|
||||
break;
|
||||
case osg::WARN:
|
||||
__android_log_write(ANDROID_LOG_WARN,_tag.c_str(),message);
|
||||
break;
|
||||
case osg::FATAL:
|
||||
case osg::ALWAYS:
|
||||
__android_log_write(ANDROID_LOG_ERROR,_tag.c_str(),message);
|
||||
break;
|
||||
default:
|
||||
__android_log_write(ANDROID_LOG_DEBUG,_tag.c_str(),message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* OsgAndroidNotifyHandler.hpp
|
||||
*
|
||||
* Created on: 31/05/2011
|
||||
* Author: Jorge Izquierdo Ciges
|
||||
*/
|
||||
|
||||
#ifndef OSGANDROIDNOTIFYHANDLER_HPP_
|
||||
#define OSGANDROIDNOTIFYHANDLER_HPP_
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
#include <osg/Notify>
|
||||
|
||||
#include <string>
|
||||
|
||||
class OSG_EXPORT OsgAndroidNotifyHandler : public osg::NotifyHandler
|
||||
{
|
||||
private:
|
||||
std::string _tag;
|
||||
public:
|
||||
void setTag(std::string tag);
|
||||
void notify(osg::NotifySeverity severity, const char *message);
|
||||
};
|
||||
|
||||
#endif /* OSGANDROIDNOTIFYHANDLER_HPP_ */
|
||||
205
examples/osgAndroidExampleGLES1/jni/OsgMainApp.cpp
Normal file
205
examples/osgAndroidExampleGLES1/jni/OsgMainApp.cpp
Normal file
@@ -0,0 +1,205 @@
|
||||
#include "OsgMainApp.hpp"
|
||||
|
||||
|
||||
OsgMainApp::OsgMainApp(){
|
||||
|
||||
_lodScale = 1.0f;
|
||||
_prevFrame = 0;
|
||||
|
||||
_initialized = false;
|
||||
_clean_scene = false;
|
||||
|
||||
}
|
||||
OsgMainApp::~OsgMainApp(){
|
||||
|
||||
}
|
||||
void OsgMainApp::loadModels(){
|
||||
if(_vModelsToLoad.size()==0) return;
|
||||
|
||||
osg::notify(osg::ALWAYS)<<"There are "<<_vModelsToLoad.size()<<" models to load"<<std::endl;
|
||||
|
||||
Model newModel;
|
||||
for(unsigned int i=0; i<_vModelsToLoad.size(); i++){
|
||||
newModel = _vModelsToLoad[i];
|
||||
osg::notify(osg::ALWAYS)<<"Loading: "<<newModel.filename<<std::endl;
|
||||
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile(newModel.filename);
|
||||
if (loadedModel == 0) {
|
||||
osg::notify(osg::ALWAYS)<<"Model not loaded"<<std::endl;
|
||||
} else {
|
||||
osg::notify(osg::ALWAYS)<<"Model loaded"<<std::endl;
|
||||
_vModels.push_back(newModel);
|
||||
|
||||
loadedModel->setName(newModel.name);
|
||||
_root->addChild(loadedModel);
|
||||
}
|
||||
}
|
||||
|
||||
_viewer->setSceneData(NULL);
|
||||
_viewer->setSceneData(_root.get());
|
||||
_manipulator->getNode();
|
||||
_viewer->home();
|
||||
|
||||
_viewer->getDatabasePager()->clear();
|
||||
_viewer->getDatabasePager()->registerPagedLODs(_root.get());
|
||||
_viewer->getDatabasePager()->setUpThreads(3, 1);
|
||||
_viewer->getDatabasePager()->setTargetMaximumNumberOfPageLOD(2);
|
||||
_viewer->getDatabasePager()->setUnrefImageDataAfterApplyPolicy(true, true);
|
||||
|
||||
_vModelsToLoad.clear();
|
||||
|
||||
}
|
||||
void OsgMainApp::deleteModels(){
|
||||
if(_vModelsToDelete.size()==0) return;
|
||||
|
||||
osg::notify(osg::ALWAYS)<<"There are "<<_vModelsToDelete.size()<<" models to delete"<<std::endl;
|
||||
|
||||
Model modelToDelete;
|
||||
for(unsigned int i=0; i<_vModelsToDelete.size(); i++){
|
||||
modelToDelete = _vModelsToDelete[i];
|
||||
osg::notify(osg::ALWAYS)<<"Deleting: "<<modelToDelete.name<<std::endl;
|
||||
|
||||
for(unsigned int j=_root->getNumChildren(); j>0; j--){
|
||||
osg::ref_ptr<osg::Node> children = _root->getChild(j-1);
|
||||
if(children->getName() == modelToDelete.name){
|
||||
_root->removeChild(children);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_vModelsToDelete.clear();
|
||||
osg::notify(osg::ALWAYS)<<"finished"<<std::endl;
|
||||
}
|
||||
//Initialization function
|
||||
void OsgMainApp::initOsgWindow(int x,int y,int width,int height){
|
||||
|
||||
__android_log_write(ANDROID_LOG_ERROR, "OSGANDROID",
|
||||
"Initializing geometry");
|
||||
|
||||
//Pending
|
||||
_notifyHandler = new OsgAndroidNotifyHandler();
|
||||
_notifyHandler->setTag("Osg Viewer");
|
||||
osg::setNotifyHandler(_notifyHandler);
|
||||
|
||||
osg::notify(osg::ALWAYS)<<"Testing"<<std::endl;
|
||||
|
||||
_viewer = new osgViewer::Viewer();
|
||||
_viewer->setUpViewerAsEmbeddedInWindow(x, y, width, height);
|
||||
|
||||
_root = new osg::Group();
|
||||
|
||||
_viewer->realize();
|
||||
|
||||
_state = _root->getOrCreateStateSet();
|
||||
_state->setMode(GL_LIGHTING, osg::StateAttribute::ON);
|
||||
_state->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
|
||||
_state->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
|
||||
|
||||
_viewer->setSceneData(_root.get());
|
||||
|
||||
_viewer->addEventHandler(new osgViewer::StatsHandler);
|
||||
_viewer->addEventHandler(new osgGA::StateSetManipulator(_viewer->getCamera()->getOrCreateStateSet()));
|
||||
_viewer->addEventHandler(new osgViewer::ThreadingHandler);
|
||||
_viewer->addEventHandler(new osgViewer::LODScaleHandler);
|
||||
|
||||
_manipulator = new osgGA::KeySwitchMatrixManipulator;
|
||||
|
||||
_manipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() );
|
||||
_manipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() );
|
||||
_manipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() );
|
||||
_manipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() );
|
||||
_manipulator->addMatrixManipulator( '5', "Orbit", new osgGA::OrbitManipulator() );
|
||||
_manipulator->addMatrixManipulator( '6', "FirstPerson", new osgGA::FirstPersonManipulator() );
|
||||
_manipulator->addMatrixManipulator( '7', "Spherical", new osgGA::SphericalManipulator() );
|
||||
|
||||
_viewer->setCameraManipulator( _manipulator.get() );
|
||||
|
||||
_viewer->getViewerStats()->collectStats("scene", true);
|
||||
|
||||
_initialized = true;
|
||||
|
||||
}
|
||||
//Draw
|
||||
void OsgMainApp::draw(){
|
||||
//Every load o remove has to be done before any drawing
|
||||
loadModels();
|
||||
deleteModels();
|
||||
|
||||
_viewer->frame();
|
||||
}
|
||||
//Events
|
||||
void OsgMainApp::mouseButtonPressEvent(float x,float y,int button){
|
||||
_viewer->getEventQueue()->mouseButtonPress(x, y, button);
|
||||
}
|
||||
void OsgMainApp::mouseButtonReleaseEvent(float x,float y,int button){
|
||||
_viewer->getEventQueue()->mouseButtonRelease(x, y, button);
|
||||
}
|
||||
void OsgMainApp::mouseMoveEvent(float x,float y){
|
||||
_viewer->getEventQueue()->mouseMotion(x, y);
|
||||
}
|
||||
void OsgMainApp::keyboardDown(int key){
|
||||
_viewer->getEventQueue()->keyPress(key);
|
||||
}
|
||||
void OsgMainApp::keyboardUp(int key){
|
||||
_viewer->getEventQueue()->keyRelease(key);
|
||||
}
|
||||
//Loading and unloading
|
||||
void OsgMainApp::loadObject(std::string filePath){
|
||||
Model newModel;
|
||||
newModel.filename = filePath;
|
||||
newModel.name = filePath;
|
||||
|
||||
int num = 0;
|
||||
for(unsigned int i=0;i<_vModels.size();i++){
|
||||
if(_vModels[i].name==newModel.name)
|
||||
return;
|
||||
}
|
||||
|
||||
_vModelsToLoad.push_back(newModel);
|
||||
|
||||
}
|
||||
void OsgMainApp::loadObject(std::string name,std::string filePath){
|
||||
|
||||
Model newModel;
|
||||
newModel.filename = filePath;
|
||||
newModel.name = name;
|
||||
|
||||
for(unsigned int i=0;i<_vModels.size();i++){
|
||||
if(_vModels[i].name==newModel.name){
|
||||
osg::notify(osg::ALWAYS)<<"Name already used"<<std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_vModelsToLoad.push_back(newModel);
|
||||
}
|
||||
void OsgMainApp::unLoadObject(int number){
|
||||
if(_vModels.size() <= number){
|
||||
osg::notify(osg::FATAL)<<"Index number error"<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
Model modelToDelete = _vModels[number];
|
||||
_vModels.erase(_vModels.begin()+number);
|
||||
_vModelsToDelete.push_back(modelToDelete);
|
||||
}
|
||||
void OsgMainApp::clearScene(){
|
||||
_vModelsToDelete = _vModels;
|
||||
_vModels.clear();
|
||||
}
|
||||
//Other Functions
|
||||
int OsgMainApp::getNumberObjects(){
|
||||
return _vModels.size();
|
||||
}
|
||||
std::string OsgMainApp::getObjectName(int number){
|
||||
return _vModels[number].name;
|
||||
}
|
||||
void OsgMainApp::setClearColor(osg::Vec4f color){
|
||||
osg::notify(osg::ALWAYS)<<"Setting Clear Color"<<std::endl;
|
||||
_viewer->getCamera()->setClearColor(color);
|
||||
}
|
||||
osg::Vec4f OsgMainApp::getClearColor(){
|
||||
osg::notify(osg::ALWAYS)<<"Getting Clear Color"<<std::endl;
|
||||
return _viewer->getCamera()->getClearColor();
|
||||
}
|
||||
138
examples/osgAndroidExampleGLES1/jni/OsgMainApp.hpp
Normal file
138
examples/osgAndroidExampleGLES1/jni/OsgMainApp.hpp
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* OsgMainApp.hpp
|
||||
*
|
||||
* Created on: 29/05/2011
|
||||
* Author: Jorge Izquierdo Ciges
|
||||
*/
|
||||
|
||||
#ifndef OSGMAINAPP_HPP_
|
||||
#define OSGMAINAPP_HPP_
|
||||
|
||||
//Android log
|
||||
#include <android/log.h>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <math.h>
|
||||
|
||||
//Standard libraries
|
||||
#include <string>
|
||||
|
||||
//osg
|
||||
#include <osg/GL>
|
||||
#include <osg/GLExtensions>
|
||||
#include <osg/Depth>
|
||||
#include <osg/Program>
|
||||
#include <osg/Shader>
|
||||
#include <osg/Node>
|
||||
#include <osg/Notify>
|
||||
//osgText
|
||||
#include <osgText/Text>
|
||||
//osgDB
|
||||
#include <osgDB/DatabasePager>
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/WriteFile>
|
||||
//osg_viewer
|
||||
#include <osgViewer/Viewer>
|
||||
#include <osgViewer/Renderer>
|
||||
#include <osgViewer/ViewerEventHandlers>
|
||||
//osgGA
|
||||
#include <osgGA/GUIEventAdapter>
|
||||
#include <osgGA/MultiTouchTrackballManipulator>
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/FlightManipulator>
|
||||
#include <osgGA/DriveManipulator>
|
||||
#include <osgGA/KeySwitchMatrixManipulator>
|
||||
#include <osgGA/StateSetManipulator>
|
||||
#include <osgGA/AnimationPathManipulator>
|
||||
#include <osgGA/TerrainManipulator>
|
||||
#include <osgGA/SphericalManipulator>
|
||||
//Self headers
|
||||
#include "OsgAndroidNotifyHandler.hpp"
|
||||
|
||||
//Static plugins Macro
|
||||
USE_OSGPLUGIN(ive)
|
||||
USE_OSGPLUGIN(osg)
|
||||
USE_OSGPLUGIN(osg2)
|
||||
USE_OSGPLUGIN(terrain)
|
||||
USE_OSGPLUGIN(rgb)
|
||||
USE_OSGPLUGIN(OpenFlight)
|
||||
USE_OSGPLUGIN(dds)
|
||||
//Static DOTOSG
|
||||
USE_DOTOSGWRAPPER_LIBRARY(osg)
|
||||
USE_DOTOSGWRAPPER_LIBRARY(osgFX)
|
||||
USE_DOTOSGWRAPPER_LIBRARY(osgParticle)
|
||||
USE_DOTOSGWRAPPER_LIBRARY(osgTerrain)
|
||||
USE_DOTOSGWRAPPER_LIBRARY(osgText)
|
||||
USE_DOTOSGWRAPPER_LIBRARY(osgViewer)
|
||||
USE_DOTOSGWRAPPER_LIBRARY(osgVolume)
|
||||
//Static serializer
|
||||
USE_SERIALIZER_WRAPPER_LIBRARY(osg)
|
||||
USE_SERIALIZER_WRAPPER_LIBRARY(osgAnimation)
|
||||
USE_SERIALIZER_WRAPPER_LIBRARY(osgFX)
|
||||
USE_SERIALIZER_WRAPPER_LIBRARY(osgManipulator)
|
||||
USE_SERIALIZER_WRAPPER_LIBRARY(osgParticle)
|
||||
USE_SERIALIZER_WRAPPER_LIBRARY(osgTerrain)
|
||||
USE_SERIALIZER_WRAPPER_LIBRARY(osgText)
|
||||
USE_SERIALIZER_WRAPPER_LIBRARY(osgVolume)
|
||||
|
||||
#define LOG_TAG "osgNativeLib"
|
||||
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
|
||||
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
|
||||
|
||||
struct Model{
|
||||
std::string filename;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
class OsgMainApp{
|
||||
private:
|
||||
osg::ref_ptr<osgViewer::Viewer> _viewer;
|
||||
osg::ref_ptr<osg::Group> _root;
|
||||
osg::ref_ptr<osg::StateSet> _state;
|
||||
osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> _manipulator;
|
||||
|
||||
float _lodScale;
|
||||
unsigned int _prevFrame;
|
||||
|
||||
bool _initialized;
|
||||
bool _clean_scene;
|
||||
|
||||
OsgAndroidNotifyHandler *_notifyHandler;
|
||||
|
||||
std::vector<Model> _vModels;
|
||||
std::vector<Model> _vModelsToLoad;
|
||||
std::vector<Model> _vModelsToDelete;
|
||||
|
||||
void loadModels();
|
||||
void deleteModels();
|
||||
|
||||
public:
|
||||
OsgMainApp();
|
||||
~OsgMainApp();
|
||||
|
||||
//Initialization function
|
||||
void initOsgWindow(int x,int y,int width,int height);
|
||||
//Draw
|
||||
void draw();
|
||||
//Events
|
||||
void mouseButtonPressEvent(float x,float y,int button);
|
||||
void mouseButtonReleaseEvent(float x,float y,int button);
|
||||
void mouseMoveEvent(float x,float y);
|
||||
void keyboardDown(int key);
|
||||
void keyboardUp(int key);
|
||||
//Loading and unloading
|
||||
void loadObject(std::string filePath);
|
||||
void loadObject(std::string name,std::string filePath);
|
||||
void unLoadObject(int number);
|
||||
void clearScene();
|
||||
//Other functions
|
||||
int getNumberObjects();
|
||||
std::string getObjectName(int nunmber);
|
||||
|
||||
void setClearColor(osg::Vec4f color);
|
||||
osg::Vec4f getClearColor();
|
||||
};
|
||||
|
||||
|
||||
#endif /* OSGMAINAPP_HPP_ */
|
||||
113
examples/osgAndroidExampleGLES1/jni/osgNativeLib.cpp
Normal file
113
examples/osgAndroidExampleGLES1/jni/osgNativeLib.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
#include <string.h>
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "OsgMainApp.hpp"
|
||||
|
||||
OsgMainApp mainApp;
|
||||
|
||||
extern "C" {
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_init(JNIEnv * env, jobject obj, jint width, jint height);
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_step(JNIEnv * env, jobject obj);
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_clearContents(JNIEnv * env, jobject obj);
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_mouseButtonPressEvent(JNIEnv * env, jobject obj, jfloat x, jfloat y, jint button);
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_mouseButtonReleaseEvent(JNIEnv * env, jobject obj, jfloat x, jfloat y, jint button);
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_mouseMoveEvent(JNIEnv * env, jobject obj, jfloat x, jfloat y);
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_keyboardDown(JNIEnv * env, jobject obj, jint key);
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_keyboardUp(JNIEnv * env, jobject obj, jint key);
|
||||
JNIEXPORT jintArray JNICALL Java_osg_AndroidExample_osgNativeLib_getClearColor(JNIEnv * env, jobject obj);
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_setClearColor(JNIEnv * env, jobject obj, jint red, jint green, jint blue);
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_loadObject(JNIEnv * env, jobject obj, jstring address);
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_unLoadObject(JNIEnv * env, jobject obj, jint number);
|
||||
JNIEXPORT jobjectArray JNICALL Java_osg_AndroidExample_osgNativeLib_getObjectNames(JNIEnv * env, jobject obj);
|
||||
};
|
||||
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_init(JNIEnv * env, jobject obj, jint width, jint height){
|
||||
mainApp.initOsgWindow(0,0,width,height);
|
||||
}
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_step(JNIEnv * env, jobject obj){
|
||||
mainApp.draw();
|
||||
}
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_clearContents(JNIEnv * env, jobject obj){
|
||||
mainApp.clearScene();
|
||||
}
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_mouseButtonPressEvent(JNIEnv * env, jobject obj, jfloat x, jfloat y, jint button){
|
||||
mainApp.mouseButtonPressEvent(x,y,button);
|
||||
}
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_mouseButtonReleaseEvent(JNIEnv * env, jobject obj, jfloat x, jfloat y, jint button){
|
||||
mainApp.mouseButtonReleaseEvent(x,y,button);
|
||||
}
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_mouseMoveEvent(JNIEnv * env, jobject obj, jfloat x, jfloat y){
|
||||
mainApp.mouseMoveEvent(x,y);
|
||||
}
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_keyboardDown(JNIEnv * env, jobject obj, jint key){
|
||||
mainApp.keyboardDown(key);
|
||||
}
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_keyboardUp(JNIEnv * env, jobject obj, jint key){
|
||||
mainApp.keyboardUp(key);
|
||||
}
|
||||
JNIEXPORT jintArray JNICALL Java_osg_AndroidExample_osgNativeLib_getClearColor(JNIEnv * env, jobject obj){
|
||||
|
||||
jintArray color;
|
||||
color = env->NewIntArray(3);
|
||||
if (color == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
osg::Vec4 vTemp1 = mainApp.getClearColor();
|
||||
|
||||
jint vTemp2[3];
|
||||
|
||||
vTemp2[0] = (int) (vTemp1.r() * 255);
|
||||
vTemp2[1] = (int) (vTemp1.g() * 255);
|
||||
vTemp2[2] = (int) (vTemp1.b() * 255);
|
||||
|
||||
std::cout<<vTemp2[0]<<" "<<vTemp2[1]<<" "<<vTemp2[2]<<" "<<std::endl;
|
||||
|
||||
env->SetIntArrayRegion(color, 0, 3, vTemp2);
|
||||
|
||||
return color;
|
||||
}
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_setClearColor(JNIEnv * env, jobject obj, jint red, jint green, jint blue){
|
||||
osg::Vec4 tVec((float) red / 255.0f, (float) green / 255.0f, (float) blue / 255.0f, 0.0f);
|
||||
mainApp.setClearColor(tVec);
|
||||
}
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_loadObject(JNIEnv * env, jobject obj, jstring address){
|
||||
//Import Strings from JNI
|
||||
const char *nativeAddress = env->GetStringUTFChars(address, false);
|
||||
|
||||
mainApp.loadObject(std::string(nativeAddress));
|
||||
|
||||
//Release Strings to JNI
|
||||
env->ReleaseStringUTFChars(address, nativeAddress);
|
||||
}
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_loadObject(JNIEnv * env, jobject obj, jstring address, jstring name){
|
||||
//Import Strings from JNI
|
||||
const char *nativeAddress = env->GetStringUTFChars(address, false);
|
||||
const char *nativeName = env->GetStringUTFChars(name, false);
|
||||
|
||||
mainApp.loadObject(std::string(nativeName),std::string(nativeAddress));
|
||||
|
||||
//Release Strings to JNI
|
||||
env->ReleaseStringUTFChars(address, nativeAddress);
|
||||
env->ReleaseStringUTFChars(address, nativeName);
|
||||
}
|
||||
JNIEXPORT void JNICALL Java_osg_AndroidExample_osgNativeLib_unLoadObject(JNIEnv * env, jobject obj, jint number){
|
||||
|
||||
mainApp.unLoadObject(number);
|
||||
|
||||
}
|
||||
JNIEXPORT jobjectArray JNICALL Java_osg_AndroidExample_osgNativeLib_getObjectNames(JNIEnv * env, jobject obj){
|
||||
|
||||
jobjectArray fileNames;
|
||||
unsigned int numModels = mainApp.getNumberObjects();
|
||||
fileNames = (jobjectArray)env->NewObjectArray(numModels,env->FindClass("java/lang/String"),env->NewStringUTF(""));
|
||||
|
||||
for(unsigned int i=0;i < numModels;i++){
|
||||
std::string name = mainApp.getObjectName(i);
|
||||
env->SetObjectArrayElement(fileNames,i,env->NewStringUTF(name.c_str()));
|
||||
}
|
||||
|
||||
return fileNames;
|
||||
}
|
||||
Reference in New Issue
Block a user