Android/iOS & C++
-
- Posts: 386
- Joined: Sun May 11, 2014 12:13 am
Android/iOS & C++
Hello everyone,
I'm trying to accomplish what sounds like a simple task, yet appears to be more difficult than expected.
Firstly, I'm more focused on Android development than iOS development. If I can't figure out the iOS part of it, I will most likely skip it.
However, I am really eager to get an Android project started with C++.
My current compiler is Code::Blocks, but I do have Eclipse downloaded. Just in case. Code::Blocks would be a much better choice for me to use personally, but if I absolutely need to move to Eclipse, I don't mind doing so.
Basically, I have been working on my own game with many features. Now that it is mostly complete, I want to port it to Android (or possibly iOS).
Unfortunately, I was not prepared for mobile project building.
Here are some questions I dearly hope those reading may have answers to:
1.) Is it possible to use Code::Blocks for my Irrlicht, C++, Android development?
1.A) Where do I learn how to set up this android project? (Cannot find anything online).
2.) Do Windows.h and Winsock.h headers work on Android (and/or iOS)? I'm using Windows for multiple reasons, and Winsock for my MMO networking.
2.A) If not, are there some easy-to-migrate alternatives?
I have many questions on this topic, using Irrlicht and C++ for Android development, but have a hard time wording out my more specific questions.
All-in-all, I'm looking for really anything that can help me start turning my current project (Windows compatible) into a mobile application as simple as possible.
Any help would be greatly appreciated.
Thanks!
I'm trying to accomplish what sounds like a simple task, yet appears to be more difficult than expected.
Firstly, I'm more focused on Android development than iOS development. If I can't figure out the iOS part of it, I will most likely skip it.
However, I am really eager to get an Android project started with C++.
My current compiler is Code::Blocks, but I do have Eclipse downloaded. Just in case. Code::Blocks would be a much better choice for me to use personally, but if I absolutely need to move to Eclipse, I don't mind doing so.
Basically, I have been working on my own game with many features. Now that it is mostly complete, I want to port it to Android (or possibly iOS).
Unfortunately, I was not prepared for mobile project building.
Here are some questions I dearly hope those reading may have answers to:
1.) Is it possible to use Code::Blocks for my Irrlicht, C++, Android development?
1.A) Where do I learn how to set up this android project? (Cannot find anything online).
2.) Do Windows.h and Winsock.h headers work on Android (and/or iOS)? I'm using Windows for multiple reasons, and Winsock for my MMO networking.
2.A) If not, are there some easy-to-migrate alternatives?
I have many questions on this topic, using Irrlicht and C++ for Android development, but have a hard time wording out my more specific questions.
All-in-all, I'm looking for really anything that can help me start turning my current project (Windows compatible) into a mobile application as simple as possible.
Any help would be greatly appreciated.
Thanks!
Re: Android/iOS & C++
I've been working with Android using Visual Studio 2010, using NVIDIA's Tegra Nsight tools (works with non-Tegra devices as well). I wrote a guide a long time ago here, though it could be very much out of date or nonfunctional at this point:
http://irrlicht.sourceforge.net/forum/v ... =5&t=48584
I've had some issues with some of their newer packages. I am currently using tadp-3.0r2-windows.exe. The nicest thing about it is that it installs and sets up the entire android work environment automatically.
http://irrlicht.sourceforge.net/forum/v ... =5&t=48584
I've had some issues with some of their newer packages. I am currently using tadp-3.0r2-windows.exe. The nicest thing about it is that it installs and sets up the entire android work environment automatically.
Re: Android/iOS & C++
Windows headers are Windows-only.
Re: Android/iOS & C++
It might be possible in some way with code::blocks, but I did something else. I first got OpenGL ES2 running on my PC. Then I added a define to my game for simulating a touch-input device. So now I could do most of my development and testing on PC. Not alll of it obviously (it's no real touch-input, etc). Then for Android compiling I used the console.
Check example 27 in the Irrlicht ogl_es branch for setting up an Android project. The readme in there describes what you need to do.
For compiling I wrote myself a bunch of aliases for the console, like:
alias n1='ndk-build V=1 NDK_DEBUG=1'
alias n2='ant debug'
alias n3='adb -d install bin/hcraft1-debug.apk'
alias n4='adb -d logcat -c;adb logcat Irrlicht:V DEBUG:V *:S'
alias n1234='n1 && n2 && n3 && n4'
That's using the name of my own game obviously. So when I want a full re-compile and start debugging I type n1234 into the console and it does that. Note that I still work with Code::Blocks otherwise, only the compiling itself is done with console.
I didn't use network on Android yet, so not sure what they have. But probably based on linux sockets.
Check example 27 in the Irrlicht ogl_es branch for setting up an Android project. The readme in there describes what you need to do.
For compiling I wrote myself a bunch of aliases for the console, like:
alias n1='ndk-build V=1 NDK_DEBUG=1'
alias n2='ant debug'
alias n3='adb -d install bin/hcraft1-debug.apk'
alias n4='adb -d logcat -c;adb logcat Irrlicht:V DEBUG:V *:S'
alias n1234='n1 && n2 && n3 && n4'
That's using the name of my own game obviously. So when I want a full re-compile and start debugging I type n1234 into the console and it does that. Note that I still work with Code::Blocks otherwise, only the compiling itself is done with console.
I didn't use network on Android yet, so not sure what they have. But probably based on linux sockets.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 386
- Joined: Sun May 11, 2014 12:13 am
Re: Android/iOS & C++
Hello again,
I finally tried setting up my first Irrlicht Android project.
After downloading all the required files, I was onto building commands through Command Prompt.
On the readme.txt for the ogl-es version, I got to step 4 and have errors.
Here's the console output:
I tried step #5 regardless the #4 errors (before realizing I had errors on #4) and got:
(Not that the above last code has any affect on #4, just though it could possibly be relevant).
Thanks for any help!!
I finally tried setting up my first Irrlicht Android project.
After downloading all the required files, I was onto building commands through Command Prompt.
On the readme.txt for the ogl-es version, I got to step 4 and have errors.
Here's the console output:
Code: Select all
C:\Users\ADMIN\Desktop\AndroidProject\irrlicht-code-5065-branches-ogl-es\examp
les\27.HelloWorld_Android>ndk-build
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
The syntax of the command is incorrect.
process_begin: CreateProcess(NULL, cp jni/../../../media/Shaders/*.* jni/../asse
ts/media/Shaders/, ...) failed.
process_begin: CreateProcess(NULL, cp jni/../../../media/irrlichtlogo3.png jni/.
./assets/media/, ...) failed.
process_begin: CreateProcess(NULL, cp jni/../../../media/dwarf.x jni/../assets/m
edia/, ...) failed.
process_begin: CreateProcess(NULL, cp jni/../../../media/dwarf.jpg jni/../assets
/media/, ...) failed.
process_begin: CreateProcess(NULL, cp jni/../../../media/axe.jpg jni/../assets/m
edia/, ...) failed.
process_begin: CreateProcess(NULL, cp jni/../../../media/fonthaettenschweiler.bm
p jni/../assets/media/, ...) failed.
process_begin: CreateProcess(NULL, cp jni/../../../media/bigfont.png jni/../asse
ts/media/, ...) failed.
[armeabi] Gdbserver : [arm-linux-androideabi-4.8] libs/armeabi/gdbserver
[armeabi] Gdbsetup : libs/armeabi/gdb.setup
[armeabi] Install : libHelloWorldMobile.so => libs/armeabi/libHelloWorldM
obile.so
Code: Select all
C:\Users\ADMIN\Desktop\AndroidProject\irrlicht-code-5065-branches-ogl-es\examp
les\27.HelloWorld_Android>ant debug
Buildfile: C:\Users\ADMIN\Desktop\AndroidProject\irrlicht-code-5065-branches-o
gl-es\examples\27.HelloWorld_Android\build.xml
-set-mode-check:
-set-debug-files:
-check-env:
[checkenv] Android SDK Tools Revision 24.1.2
[checkenv] Installed at C:\Users\ADMIN\AppData\Local\Android\sdk1
-setup:
[echo] Project Name: HelloWorldMobile
[gettype] Project Type: Application
-set-debug-mode:
-debug-obfuscation-check:
-pre-build:
-build-setup:
[getbuildtools] Using latest Build Tools: 21.1.2
[echo] Resolving Build Target for HelloWorldMobile...
BUILD FAILED
C:\Users\ADMIN\AppData\Local\Android\sdk1\tools\ant\build.xml:542: Unable to r
esolve project target 'android-10'
Total time: 1 second
C:\Users\ADMIN\Desktop\AndroidProject\irrlicht-code-5065-branches-ogl-es\examp
les\27.HelloWorld_Android>
Thanks for any help!!
-
- Posts: 386
- Joined: Sun May 11, 2014 12:13 am
Re: Android/iOS & C++
Fixed error on step #4.
Opened the Android.mk file and changed the IRRLICHT_PROJECT_PATH directory.
However, there was no change on the step #5 error above; sadly..
EDIT:
Downloaded the Android 2.3.3 (API 10) files from the Android SDK Manager.
New error on step #5 (ant debug)
Opened the Android.mk file and changed the IRRLICHT_PROJECT_PATH directory.
However, there was no change on the step #5 error above; sadly..
EDIT:
Downloaded the Android 2.3.3 (API 10) files from the Android SDK Manager.
New error on step #5 (ant debug)
Code: Select all
C:\Users\ADMIN\Desktop\AndroidProject\irrlicht-code-5065-branches-ogl-es\examples\27.HelloWorld_Android\build.xml
-set-mode-check:
-set-debug-files:
-check-env:
[checkenv] Android SDK Tools Revision 24.1.2
[checkenv] Installed at C:\Users\ADMIN\AppData\Local\Android\sdk1
-setup:
[echo] Project Name: HelloWorldMobile
[gettype] Project Type: Application
-set-debug-mode:
-debug-obfuscation-check:
-pre-build:
-build-setup:
[getbuildtools] Using latest Build Tools: 21.1.2
[echo] Resolving Build Target for HelloWorldMobile...
[gettarget] Project Target: Android 2.3.3
[gettarget] API level: 10
[echo] ------------
[echo] Creating output directories if needed...
[echo] ------------
[echo] Resolving Dependencies for HelloWorldMobile...
[dependency] Library dependencies:
[dependency] No Libraries
[dependency]
[dependency] ------------------------
[dependency] API<=15: Adding annotations.jar to the classpath.
[echo] ---------------
[echo] Building Libraries with 'debug'...
[subant] No sub-builds to iterate on
-code-gen:
[mergemanifest] Found Deleted Target File
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
[echo] Handling aidl files...
BUILD FAILED
C:\Users\ADMIN\AppData\Local\Android\sdk1\tools\ant\build.xml:653: The following error occurred while executing this line:
C:\Users\ADMIN\AppData\Local\Android\sdk1\tools\ant\build.xml:659: C:\Users\ADMIN\Desktop\AndroidProject\irrlicht-code-5065-branches-ogl-es\examples\27.HelloWorld_Android\src does not exist.
Total time: 1 second
C:\Users\ADMIN\Desktop\AndroidProject\irrlicht-code-5065-branches-ogl-es\examples\27.HelloWorld_Android>
-
- Posts: 386
- Joined: Sun May 11, 2014 12:13 am
Re: Android/iOS & C++
Got it!!
I just added the media folder into the src folder (not sure if that was correct or not...)
I then did the remaining steps, and got everything working on my phone!!!
I'm so shocked at how awesome that is.
I do have one more question though
A game I've been making for a very long while now is Windows-only (due to windows headers, as stated).
I could probably remove the Windows.h include, but this leaves me with Winsock.h
Is there a reliable Winsock.h work-around that works on all operating systems?
Should I scrap all of my Winsock.h progress and move to a different networking system?
-If so, what?
I just added the media folder into the src folder (not sure if that was correct or not...)
I then did the remaining steps, and got everything working on my phone!!!
I'm so shocked at how awesome that is.
I do have one more question though
A game I've been making for a very long while now is Windows-only (due to windows headers, as stated).
I could probably remove the Windows.h include, but this leaves me with Winsock.h
Is there a reliable Winsock.h work-around that works on all operating systems?
Should I scrap all of my Winsock.h progress and move to a different networking system?
-If so, what?
Re: Android/iOS & C++
Not sure why you got the errors, the Android.mk should have cared about most of those. The src folder must only exist - not contain anything. It's for java-sources in case you need any of those (you probably will need those sooner or later).
I personally switched all my libs from Android-10 to Android-13, there have been larger changes between those and while losing a few customers it made some things just easier (especially once advertisement stuff and other libraries were added).
I don't think you can get Winsock working on other systems. Either work with #defines per platform and use the corresponding network libraries on each - or you have to find a cross-platform network library (like enet or raknet) and check if they support all platforms you need.
I personally switched all my libs from Android-10 to Android-13, there have been larger changes between those and while losing a few customers it made some things just easier (especially once advertisement stuff and other libraries were added).
I don't think you can get Winsock working on other systems. Either work with #defines per platform and use the corresponding network libraries on each - or you have to find a cross-platform network library (like enet or raknet) and check if they support all platforms you need.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 386
- Joined: Sun May 11, 2014 12:13 am
Re: Android/iOS & C++
Okay I will take a look at Enet.
However, I'm having a little bit more issues.
It seems everything is working fine for Windows and Android, except some things seem not to work.
For example, I cannot rotate or change mesh positions without the game crashing.
Here's how I've been doing it all other times, but now (probably within the Android libirrlicht.a?) I'm having issues:
My crashing point is directly on the last line (setPosition) in the above code.
Any help as-to why or how I can fix this? Thanks!
However, I'm having a little bit more issues.
It seems everything is working fine for Windows and Android, except some things seem not to work.
For example, I cannot rotate or change mesh positions without the game crashing.
Here's how I've been doing it all other times, but now (probably within the Android libirrlicht.a?) I'm having issues:
Code: Select all
...
IAnimatedMeshSceneNode* mesh = smgr->addAnimatedMeshSceneNode(smgr->getMesh(mediaPath + "dwarf.x"));
//Also tried mesh = (IAnimatedMeshSceneNode*)smgr->getMesh(...); which failed to change results.
if (!mesh)
{
device->closeDevice();
device->drop();
return;
}
smgr->addCameraSceneNode(0, vector3df(15,40,-90), vector3df(0,30,0));
/*
To look at the mesh, we place a camera.
*/
u32 loop = 0; // loop is reset when the app is destroyed unlike runCounter
static u32 runCounter = 0; // static's seem to survive even an app-destroy message (not sure if that's guaranteed).
while(device->run())
{
mesh->setPosition(core::vector3df(0,0,0));
...
Any help as-to why or how I can fix this? Thanks!
-
- Posts: 386
- Joined: Sun May 11, 2014 12:13 am
Re: Android/iOS & C++
Strange.
If, in the loop, I put:
mesh->setCurrentFrame(0);
The background goes green for about 2 seconds, then the program crashes with error: "Render Context switch failed."
In case the error lies within my program somewhere, here's the entire code:
Ugh this is so frustrating right now
It was all just working (without scaling, changing positions, or changing animation frames) on both, Windows and Android.
Now it's only working on Windows for whatever reason. No errors are appearing for the Android crashes.
Did I set something up wrong or is this just an Irrlicht problem?
If, in the loop, I put:
mesh->setCurrentFrame(0);
The background goes green for about 2 seconds, then the program crashes with error: "Render Context switch failed."
In case the error lies within my program somewhere, here's the entire code:
Code: Select all
/** Example 027 Helloworld_Android
This example shows a simple application for Android.
*/
#include <irrlicht.h>
#include <vector>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
void mainloop();
IrrlichtDevice *device;
IVideoDriver* driver;
ISceneManager* smgr;
IGUIEnvironment* guienv;
ILogger* logger;
IFileSystem * fs;
int32_t windowWidth=640,windowHeight=480;
stringc mediaPath = "../irrlicht-code-5065-branches-ogl-es/media/";
enum GUI_IDS
{
GUI_INFO_FPS,
GUI_IRR_LOGO,
};
void initD() {
driver = device->getVideoDriver();
smgr = device->getSceneManager();
guienv = device->getGUIEnvironment();
logger = device->getLogger();
fs = device->getFileSystem();
}
#ifdef _IRR_ANDROID_PLATFORM_
#include <android_native_app_glue.h>
#include "android_tools.h"
#include "android/window.h"
/*
Android is using multitouch events.
We allow users to move around the Irrlicht logo as example of how to use those.
*/
class MyEventReceiver : public IEventReceiver
{
public:
MyEventReceiver(android_app* app )
: Device(0), AndroidApp(app), SpriteToMove(0), TouchID(-1)
{
}
void Init(IrrlichtDevice *device)
{
Device = device;
}
virtual bool OnEvent(const SEvent& event)
{
if (event.EventType == EET_TOUCH_INPUT_EVENT)
{
/*
For now we fake mouse-events. Touch-events will be handled inside Irrlicht in the future, but until
that is implemented you can use this workaround to get a GUI which works at least for simple elements like
buttons. That workaround does ignore multi-touch events - if you need several buttons pressed at the same
time you have to handle that yourself.
*/
SEvent fakeMouseEvent;
fakeMouseEvent.EventType = EET_MOUSE_INPUT_EVENT;
fakeMouseEvent.MouseInput.X = event.TouchInput.X;
fakeMouseEvent.MouseInput.Y = event.TouchInput.Y;
fakeMouseEvent.MouseInput.Shift = false;
fakeMouseEvent.MouseInput.Control = false;
fakeMouseEvent.MouseInput.ButtonStates = 0;
fakeMouseEvent.MouseInput.Event = EMIE_COUNT;
switch (event.TouchInput.Event)
{
case ETIE_PRESSED_DOWN:
{
// We only work with the first for now.
if ( TouchID == -1 )
{
fakeMouseEvent.MouseInput.Event = EMIE_LMOUSE_PRESSED_DOWN;
if (Device)
{
position2d<s32> touchPoint(event.TouchInput.X, event.TouchInput.Y);
IGUIElement * logo = Device->getGUIEnvironment()->getRootGUIElement()->getElementFromId ( GUI_IRR_LOGO );
if ( logo && logo->isPointInside (touchPoint) )
{
TouchID = event.TouchInput.ID;
SpriteToMove = logo;
SpriteStartRect = SpriteToMove->getRelativePosition();
TouchStartPos = touchPoint;
}
}
}
break;
}
case ETIE_MOVED:
if ( TouchID == event.TouchInput.ID )
{
fakeMouseEvent.MouseInput.Event = EMIE_MOUSE_MOVED;
fakeMouseEvent.MouseInput.ButtonStates = EMBSM_LEFT;
if ( SpriteToMove && TouchID == event.TouchInput.ID )
{
position2d<s32> touchPoint(event.TouchInput.X, event.TouchInput.Y);
MoveSprite(touchPoint);
}
}
break;
case ETIE_LEFT_UP:
if ( TouchID == event.TouchInput.ID )
{
fakeMouseEvent.MouseInput.Event = EMIE_LMOUSE_LEFT_UP;
if ( SpriteToMove )
{
TouchID = -1;
position2d<s32> touchPoint(event.TouchInput.X, event.TouchInput.Y);
MoveSprite(touchPoint);
SpriteToMove = 0;
}
}
break;
default:
break;
}
if ( fakeMouseEvent.MouseInput.Event != EMIE_COUNT && Device )
{
Device->postEventFromUser(fakeMouseEvent);
}
}
else if ( event.EventType == EET_GUI_EVENT )
{
/*
Show and hide the soft input keyboard when an edit-box get's the focus.
*/
switch(event.GUIEvent.EventType)
{
case EGET_EDITBOX_ENTER:
if ( event.GUIEvent.Caller->getType() == EGUIET_EDIT_BOX )
{
if( Device->getGUIEnvironment() )
Device->getGUIEnvironment()->setFocus(NULL);
android::setSoftInputVisibility(AndroidApp, false);
}
break;
case EGET_ELEMENT_FOCUS_LOST:
if ( event.GUIEvent.Caller->getType() == EGUIET_EDIT_BOX )
{
/* Unfortunatly this only works on some android devices.
On other devices Android passes through touch-input events when the virtual keyboard is clicked while blocking those events in areas where the keyboard isn't.
Very likely an Android bug as it only happens in certain cases (like Android Lollipop with landscape mode on MotoG, but also some reports from other devices).
Or maybe Irrlicht still does something wrong.
Can't figure it out so far - so be warned - with landscape mode you might be better off writing your own keyboard.
*/
android::setSoftInputVisibility(AndroidApp, false);
}
break;
case EGET_ELEMENT_FOCUSED:
if ( event.GUIEvent.Caller->getType() == EGUIET_EDIT_BOX )
{
android::setSoftInputVisibility(AndroidApp, true);
}
break;
default:
break;
}
}
return false;
}
void MoveSprite(const irr::core::position2d<irr::s32> &touchPos)
{
irr::core::position2d<irr::s32> move(touchPos-TouchStartPos);
SpriteToMove->setRelativePosition(SpriteStartRect.UpperLeftCorner + move);
}
private:
IrrlichtDevice * Device;
android_app* AndroidApp;
gui::IGUIElement * SpriteToMove;
core::rect<s32> SpriteStartRect;
core::position2d<irr::s32> TouchStartPos;
s32 TouchID;
};
/* Mainloop.
*/
/* Main application code. */
void android_main(android_app* app)
{
// Make sure glue isn't stripped.
app_dummy();
/*
The receiver can already receive system events while createDeviceEx is called.
So we create it first.
*/
MyEventReceiver receiver(app);
/*
Create the device.
You have currently the choice between 2 drivers:
EDT_OGLES1 is basically a opengl fixed function pipeline.
EDT_OGLES2 is a shader pipeline. Irrlicht comes with shaders to simulate
typical fixed function materials. For this to work the
corresponding shaders from the Irrlicht media/Shaders folder are
copied to the application assets folder (done in the Makefile).
*/
SIrrlichtCreationParameters param;
// param.DriverType = EDT_OGLES1; // android:glEsVersion in AndroidManifest.xml should be "0x00010000" (requesting 0x00020000 will also guarantee that ES1 works)
param.DriverType = EDT_OGLES2; // android:glEsVersion in AndroidManifest.xml should be "0x00020000"
param.WindowSize = dimension2d<u32>(0,0); // using 0,0 it will automatically set it to the maximal size
param.PrivateData = app;
param.Bits = 24;
param.ZBufferBits = 16;
param.AntiAlias = 0;
param. EventReceiver = &receiver;
/* Logging is written to a file. So your application should disable all logging when you distribute your
application or it can fill up that file over time.
*/
#ifndef _DEBUG
param.LoggingLevel = ELL_NONE;
#endif
device = createDeviceEx(param);
if (device == 0)
return;
receiver.Init(device);
// ANativeActivity_setWindowFlags(app->activity, AWINDOW_FLAG_FULLSCREEN, 0);
initD();
/* Access to the Android native window. You often need this when accessing NDK functions like we are doing here.
Note that windowWidth/windowHeight have already subtracted things like the taskbar which your device might have,
so you get the real size of your render-window.
*/
ANativeWindow* nativeWindow = static_cast<ANativeWindow*>(driver->getExposedVideoData().OGLESAndroid.Window);
windowWidth = ANativeWindow_getWidth(app->window);
windowHeight = ANativeWindow_getHeight(app->window);
/* Get display metrics. We are accessing the Java functions of the JVM directly in this case as there is no NDK function for that yet.
Checkout android_tools.cpp if you want to know how that is done. */
irr::android::SDisplayMetrics displayMetrics;
memset(&displayMetrics, 0, sizeof displayMetrics);
irr::android::getDisplayMetrics(app, displayMetrics);
/* For troubleshooting you can use the Irrlicht logger.
The Irrlicht logging messages are send to the Android logging system using the tag "Irrlicht".
They stay in a file there, so you can check them even after running your app.
You can watch them with the command: "adb logcat Irrlicht:V DEBUG:V *:S"
This means Irrlicht _V_erbose, debug messages verbose (p.E callstack on crashes) and all other messages _S_ilent.
Clean the logging file with: "adb logcat -c".
See http://developer.android.com/tools/debugging/debugging-log.html for more advanced log options.
*/
char strDisplay[1000];
sprintf(strDisplay, "Window size:(%d/%d)\nDisplay size:(%d/%d)", windowWidth, windowHeight, displayMetrics.widthPixels, displayMetrics.heightPixels);
logger->log(strDisplay);
core::dimension2d<s32> dim(driver->getScreenSize());
sprintf(strDisplay, "getScreenSize:(%d/%d)", dim.Width, dim.Height);
logger->log(strDisplay);
// The Android assets file-system does not know which sub-directories it has (blame google).
// So we have to add all sub-directories in assets manually. Otherwise we could still open the files,
// but existFile checks will fail (which are for example needed by getFont).
for ( u32 i=0; i < fs->getFileArchiveCount(); ++i )
{
IFileArchive* archive = fs->getFileArchive(i);
if ( archive->getType() == EFAT_ANDROID_ASSET )
{
archive->addDirectoryToFileList(mediaPath);
break;
}
}
/*
Mainloop. Applications usually never quit themself in Android. The OS is responsible for that.
*/
mainloop();
/* Cleanup */
device->setEventReceiver(0);
device->closeDevice();
device->drop();
}
#elif _WIN32 || _WIN64
class MyEventReceiver : public IEventReceiver
{
public:
// This is the one method that we have to implement
virtual bool OnEvent(const SEvent& event)
{
// Remember whether each key is down or up
if (event.EventType == irr::EET_KEY_INPUT_EVENT)
KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
return false;
}
// This is used to check whether a key is being held down
virtual bool IsKeyDown(EKEY_CODE keyCode) const
{
return KeyIsDown[keyCode];
}
MyEventReceiver()
{
for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
KeyIsDown[i] = false;
}
private:
// We use this array to store the current state of each key
bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
int main() {
// ask user for driver
video::E_DRIVER_TYPE driverType=EDT_OPENGL;
if (driverType==video::EDT_COUNT)
return 1;
// create device
MyEventReceiver receiver;
device = createDevice(driverType,
core::dimension2d<u32>(640, 480), 16, false, false, false, &receiver);
windowWidth=640; windowHeight=480;
initD();
mainloop( );
}
#endif // defined(_IRR_ANDROID_PLATFORM_)
void mainloop( )
{
guienv->addEditBox( L"", rect<s32>(5,40,475,80));
// add irrlicht logo
IGUIImage * logo = guienv->addImage(driver->getTexture(mediaPath + "TestButton.png"),
core::position2d<s32>(5,85), true, 0, GUI_IRR_LOGO);
s32 minLogoWidth = windowWidth/3;
if ( logo && logo->getRelativePosition().getWidth() < minLogoWidth )
{
/* Scale to make it better visible on high-res devices (we could also work with dpi here).
*/
logo->setScaleImage(true);
core::rect<s32> logoPos(logo->getRelativePosition());
f32 scale = (f32)minLogoWidth/(f32)logoPos.getWidth();
logoPos.LowerRightCorner.X = logoPos.UpperLeftCorner.X + minLogoWidth;
logoPos.LowerRightCorner.Y = logoPos.UpperLeftCorner.Y + (s32)((f32)logoPos.getHeight()*scale);
logo->setRelativePosition(logoPos);
}
/*
Add a 3d model. Note that you might need to add light when using other models.
A copy of the model and it's textures must be inside the assets folder to be installed to Android.
In this example we do copy it to the assets folder in the Makefile jni/Android.mk
*/
IAnimatedMeshSceneNode* mesh = smgr->addAnimatedMeshSceneNode(smgr->getMesh(mediaPath + "dwarf.x"));
//mesh->setPosition(core::vector3df(0,0,0));
if (!mesh)
{
device->closeDevice();
device->drop();
return;
}
//smgr->addAnimatedMeshSceneNode( mesh );
smgr->addCameraSceneNode(0, vector3df(15,40,-90), vector3df(0,30,0));
/*
To look at the mesh, we place a camera.
*/
u32 loop = 0; // loop is reset when the app is destroyed unlike runCounter
static u32 runCounter = 0; // static's seem to survive even an app-destroy message (not sure if that's guaranteed).
while(device->run())
{
//mesh->setCurrentFrame(0);
/*
The window seems to be always active in this setup.
That's because when it's not active Android will stop the code from running.
*/
if (device->isWindowActive())
{
/*
Show FPS and some counters to show which parts of an app run
in different app-lifecycle states.
*/
/*if ( infoText )
{
stringw str = L"FPS:";
str += (s32)device->getVideoDriver()->getFPS();
str += L" r:";
str += runCounter;
str += L" l:";
str += loop;
infoText->setText ( str.c_str() );
}*/
device->getVideoDriver()->beginScene(true, true, SColor(0,100,100,100));
device->getSceneManager()->drawAll();
device->getGUIEnvironment()->drawAll();
device->getVideoDriver()->endScene ();
}
device->yield(); // probably nicer to the battery
++runCounter;
++loop;
}
}
/*
**/
It was all just working (without scaling, changing positions, or changing animation frames) on both, Windows and Android.
Now it's only working on Windows for whatever reason. No errors are appearing for the Android crashes.
Did I set something up wrong or is this just an Irrlicht problem?
Re: Android/iOS & C++
I don't know how to solve the problem. But I can give two suggestions below:
You need to have code to close your application
Can you kill an instance that maybe running on the background or android?
Regards
thanh
You need to have code to close your application
Can you kill an instance that maybe running on the background or android?
Regards
thanh
Re: Android/iOS & C++
Can't look at it right now (wrong system and @work), but you can try getting full log-output from android with
"adb -d logcat". Maybe it gives you additional information. On a very quick view, I'd say your media path looks suspicious, but not seeing right now how that would make it crash. Just be aware that it's relative to your "assets" folder on Android.
"adb -d logcat". Maybe it gives you additional information. On a very quick view, I'd say your media path looks suspicious, but not seeing right now how that would make it crash. Just be aware that it's relative to your "assets" folder on Android.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 386
- Joined: Sun May 11, 2014 12:13 am
Re: Android/iOS & C++
Thanks for the suggestion!! However, that isn't the issue in this case. The notes say that the OS (Android) handles the exiting of the application itself.thanhle wrote:I don't know how to solve the problem. But I can give two suggestions below:
You need to have code to close your application
Can you kill an instance that maybe running on the background or android?
Regards
thanh
Hmm. I still don't know the issue.CuteAlien wrote:Can't look at it right now (wrong system and @work), but you can try getting full log-output from android with
"adb -d logcat". Maybe it gives you additional information. On a very quick view, I'd say your media path looks suspicious, but not seeing right now how that would make it crash. Just be aware that it's relative to your "assets" folder on Android.
Everything as far as images and the media path is correct. They were working fine early yesterday until I started testing with changing model positions; after removing the code for setPosition and anything else I added, the project still is crashing on start up.
I've yet to check the logs, as I don't know how -- I couldn't use the adb command in the readme (for some reason, it can't find my device or even any emulator) so I've been clicking the built APK and downloading it to BlueStacks for my testing. Not sure where three logs can be viewed on there.
Re: Android/iOS & C++
I think the readme was missing the -d parameter (to find the hardware device). Otherwise - spend time on getting adb working, it's absolutely essential for Android development. I also had to struggle a little bit with one device until it worked. And forget emulators for 3d development - at least the one from google isn't suited for that (haven't tried others).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 386
- Joined: Sun May 11, 2014 12:13 am
Re: Android/iOS & C++
The readme has the -d parameter.CuteAlien wrote:I think the readme was missing the -d parameter (to find the hardware device). Otherwise - spend time on getting adb working, it's absolutely essential for Android development. I also had to struggle a little bit with one device until it worked. And forget emulators for 3d development - at least the one from google isn't suited for that (haven't tried others).
What does it do? Would it help in my case to find the Android crashing point?
My Android phone is messed up to where of I plug it into my computer, it connects and then disconnects every few seconds - is this a problem also?