Showing posts with label 2d. Show all posts
Showing posts with label 2d. Show all posts

Saturday, February 18, 2012

Episode 4 - Grinding through a Sprite System Prototype

Coordinate woos

Picking a convenient coordinate system for a 2D game environment turned out to be a bit harder than expected. Working purely pixel-based sounds nice in theory (coming from an ancient C64 / VGA background), until you realize that you are designing things to run on a wild variety of screen dimensions.

So then I tried working with pure abstract floating point coordinates, assigning the sprites a completely free scale, only maintaining their ratio.  As it turns out, this doesn't work as well as in a pure 3D environment: rescaling bitmap-based sprites to arbitrary sizes does not always come out pretty.

I ended up with a hybrid solution where viewport coordinates are based around the ratio-adjusted unit square, but individual sprite size is in pixels. We'll have to see if it holds up once I have to implement real game stuff.


Alpha woos

All my alpha-blended sprites had ugly black edges around the corner. As it turns out, Android's default approach to texture loading (GLUtils.texImage2D) premultiplies the alpha channel.

Fixing the texture loading seems a bit tricky to implement efficiently, but as a workaround I simply changed the rendering blend function into (GL_ONE, GL_ONE_MINUTES_SRC_ALPHA). This might come back to hunt me, as premultiplying alpha kills information in the other channels that might be important when using a texture for other purposes than simple alpha-blended display.
Proper alpha-blended sprites go in...
...weird borders come out!

The final result looks like the screenshot below. Notice how the pixel aspect ratio of the physical phone is different, just pretend the screenshot is in proper 16:9 ratio. Also notice how the graphics are all placeholders, just building the technology here...
These sprites move around. That's kinda the point.

Misc
- Created a local Subversion repository for my Android work-in-progress using TortoiseSVN. Man, I'd almost forgotten how Subversion is cool that way. Considered experimenting with Mercurial in stead, but decided not to shoot myself in the (distributed) foot at this point.
- Replaced the default TortoiseSVN merge/diff tool with WinMerge. Seriously, if you are still on TortoiseMerge, make sure to do the same... cause you are missing out! Make sure to set the WinMerge font to something sensible (like Consolas 10), and you'll never want to go back. The syntax highlighting alone is worth the switch.
- Learned that it is really hard to predict how colors will come out on the Samsung Galaxy SII AMOLED screen. The screen of my little Dell Inspiron Laptop literally pales in comparison.
- Learned that it is rather difficult to get a proper movie recorded from an Android application without dedicated hardware. Might end up recording the actual phone with a camera.

Sunday, February 12, 2012

Episode 3 - A foray into Android-Land

Android is awesome!

After my first baby steps into the Android Tutorials, I now took the next step and managed to deploy a home brew Hello World Android application from Eclipse (ADT) onto my physical Samsung Galaxy SII phone. Things just got real!

Getting this to work involved installing Samsung Kies on the laptop, as it seems the only way to get the correct USB drivers. The hardest part was to actually get access to the Kies download from the extremely "helpful" Samsung website.

The debugging experience on the physical device is great, much more responsive than the emulator. Once in a while I do need to restart Eclipse because the debugger will not connect to the device... but even then I can still run on the device, and logging works fine. All in all, not too bad.

Debugging OpenGL ES 2.0 is not awesome!

I'll be making games on android, and for that I'll need sprites. And for performant (yes, I'm aware that is not a real word) sprites, I'll need OpenGL. According to the Device Dashboard, ES 2.0 is very wide spread amongst current Android devices, so it's a safe bet to require it.

Now, I've spent the last couple of years doing mostly DirectX, and I'd forgotten how poor the debugging experience of OpenGL really is... especially on the android device. First of all, you don't get to use the emulator if you want to use ES2.0. Then, everything fails silently without so much as a return code, so the only way to pin point silly mistakes in the calls is by liberally sprinkling your code with glGetError-based checks... and even then the errors reported are not very informative. How about proper GLSL debugging? When hell freezes over, probably.

After a fair bit of sweating and cursing, finally I got the first textured quad up and running... free drinks for everyone!

Now my fingers are itching to abstract away the big fat pile of OpenGL calls it took to get this far. I am trying to focus on moving forward and stay way from over-engineering, but man... talk about a high barrier to entry for new programmers! No wonder the internet is full of badly copy-pasted malfunctioning code fragments.

Misc
- As usual, the freshly installed GIMP insisted to have a Dutch User Interface... because I use Dutch formatting in the Windows Regional Settings. This annoys me every single time I run a GTK application, that is not how locales are handled in Windows. Please show some respect for my platform, guys! Rather than overriding the locale through a LANG environment parameter (again... not how things are done in a Win32 environment), I simply deleted the NL folder from [GIMP Install Folder]\share\locale. Works like a charm, and this way I'm pretty sure it will not revert to Dutch anytime soon.
- Learned how to take proper Android screenshots using Dalvik Debug Monitor (ddms.bat). Tried to spice them up with a Android Phone Template .PSD, but the end result looked too cheap and cheesy. Pure screenshots it is!