Hi - I've been attempting to find any 3D examples (ES1.1,2.0 ...) that demo a 3D object (such as a rotating cube) on Android in SDL2. Does anyone know of such?
Writing an example on PC is easy - but there seems to be so many problems on Android (such as setting up the z-buffer) ... I can't seem to work it out. Please help!
Yes, I've got code for animating 3D objects using SDL2 and ES 1.1 on Android. Here's a YouTube video of it running on four devices.
The only snag, from your point of view, is that it's written in BBC BASIC! It would be pretty straightforward to convert it to a more 'familiar' programming language but I expect you would prefer not to have to.
If this is of any interest at all, you can download my Android app from http://www.rtr.myzen.co.uk/BBCBasic.apk
Wow! - Absolutely love the BBC demos on your APK! .. brings back so many memories! (I used to have several BBC computers then an Archimedes etc..... I also remember programming in 6502 (that will give away my age!))
So, I did manage to get a cube rotating but the z-buffer is very limited -1 to +1 in range. This is despite setting zNear and zFar using glFrustumf, glOrthof and glDepthRangef! Is this a bug?
Not that I'm aware of. For example in 'teapot.bbc' the eye-object distance is 9 and zFar is 1000, and everything seems to work as expected. Setting zFar to 9 has the expected effect of clipping the teapot to that plane.
Would you mind checking this code out on my GitHub?
It displays the cuboid, but it clips against -1 to +1 when clearly the range should be -1 to 100 (or whatever I try - it just wont change from the -1 to +1 range)
The project is setup for Visual Studio 2015
I think you need to delete the call to glDepthRangef, then the depth range you set in glFrustumf should work as expected.
I must admit that glDepthRangef was a last ditch attempt to see if it had any effect - it didn't However, I did take it out and it still had no effect.
I'll keep trying - thanks again for looking
As you are - or were - familiar with BBC BASIC you can compare your code with mine. In my Android app tap on @lib$ then long-press on gleslib.bbc and then select Edit from the menu. The relevant code is in PROC_render().
It's been a while (to say the least) - but I'll take a look ...
I'll admit that I'm very impressed with your full-blown BBC code editor on my phone!!
Itself entirely written in BBC BASIC of course (touchide.bbc in the tools folder)!
Looking at your code I can't figure out where the 800 comes from in:
float fov = ((float)h / 2.f) / 800.f;
Seems to be plucked from thin air!
Yes, its a form of perspective scaling - a technique that's used in the Marmalade SDK (although it took me some time to figure it out!) The 800.f value is a little random, but it roughly determines a field of view around 60 deg.
OK - so I managed to get an OpenGLES 2.0 demo working with per-pixel shading on Android
I’ll put it up on the repo once I’ve tidied it up.
I hope it will serve as an SDL2 3D demo for Android as there doesn’t seem to be much out there!