TheHunt – The Future

Recently I was struck by a few nice ideas about TheHunt and I’m in a hurry to write them down. Here we go:

  • Knife tool. Been thinking for a while how to deal with fish hiding in a huge algae and now I think I figured it out – using the knife to cut the big into small ones. Should be easy to implement, I give it half a week.
  • Contextual menu on long-click. Long press somewhere, you get a nice pop-up menu where you can change tools, maybe request info about the object picked and other undecided stuff. Navigate in it without releasing the press. Can be tricky, I give it a week.
  • Simplified interface. Just one number in the top middle, showing score. Long press for a menu, maybe pop-ups with more information if needed. After contextual menu is implemented, only pop-ups will be missing.
  • Nicer font. I will experiment, but I’m thinking of something that looks hand-drawn. Easy to implement, but may require some time to find a proper font. I give it a day.

A quick concept to show the simplified interface and the contextual menu (didn’t include the knife and the nicer font)

Image

In a week or two I hope to have made a visible progress towards a more playable TheHunt!

Advertisements

Rendering Text in OpenGL 2.0 ES on Android

Hello all,

I have just finished porting fractious’s Rendering Text in OpenGL on Android to OpenGL ES 2.0 (this is the mobile version of OpenGL 3.0 and the main difference with the older versions OpenGL is having acces to the shaders, which allow us to run code on the GPU).

I had to do this because my project TheHunt uses, you guessed it, the newer version. Reason is that it would allow me to do some nifty shader tricks… some day 🙂

So here is my code – https://github.com/d3kod/Texample2. Feel free to use it for whatever you want as it is licensed under the CC0 1.0 public domain license.

Texample2

The example application, Texample2

Some implementation details:

  • I firstly started by simply converting the OpenGL ES 1 commands to the newer version. The Model, View and Projection matrices were passed using a uniform variable to the shaders, i.e. all the letters used the same matrices. This was good enough to produce horizontal text
  • In TheHunt I use text to label events (fishbone flops, net snatches), and I need this text to be tilted (it would be somewhat boring otherwise). For this I needed to be able to assign individual model matrices to each word. A bit tricky, but using Sprite Batching in OpenGL ES 2.0 | Anton Holmquist as inspiration I managed to do it. In short, instead of an uniform Model-View-Projection matrix, the vertex shader has an uniform array of matrices. I fill this array with an individual matrix for each letter and also pass a matrix index attribute for each vertex (the exact same method suggested by Anton Holmquist.) The result is that each GLText::draw call can tilt the string drawn with a certain angle (it can now receive an angle argument, in degrees).
  • The last catch was drawing color text – at first, all text was coming out black for me. The reason turns out to be that the texture is defined as grayscale, so in the fragment shader we need to multiply the color we want for the text (passed as uniform u_Color) with the grayscale value (called W in OpenGL) of the texture (not with the whole texture color, because it is something like [0, 0, 0, grayscale] which was resulting in the all black text):

gl_FragColor = texture2D(u_Texture, v_TexCoordinate).w * u_Color

— from BatchTextProgram.java

That’s all I can think of, and the result is efficient text drawing in OpenGL ES 2.0, and more importantly in TheHunt, where you can expect a nice GUI to appear soon!

Anatomy of a CSP solver

This is a follow up post to SudokuH – Fast Sudoku Solver in Haskell.

Let’s see how SudokuH is made. I will try to be as little technical as possible, but it may still be a long read.

Haskell

The first surprise! You open up the source code, and what do you see? Pure awesomeness. This has little to do with my pro skills (that’s short for programming skills, if you wonder), and more with Haskell. Let me tell you, I love Haskell. My feelings towards it deserve a separate post, so I will just say that Functional Programming is powerful and elegant. It does take some time to get used to but after this writing in imperative languages (like C, Java) feels… obsolete. If I had to implement the algorithms in SudokuSolver.hs in, say, Java, it might have very well become 500+ lines of code (compared to around 150 right now without the comments). So… if you don’t know Haskell, why not give it a try?

Continue reading

SudokuH – Fast Sudoku Solver in Haskell

GUI might not be beautiful, but it does the job

Edit: You can find out more about how SudokuH works in the separate blog post – Anatomy of a CSP solver

Do you like solving Sudoku? To be honest, I am not a huge fan of it – not sure if I had solved even one by myself. I find it a bit of a waste of time. During an AI course I had in uni, however, we wrote a fancy Constraint Satisfaction Problem (CSP) solver. Mine happened to be the fastest in the class, and despite the fact that I did win some chocolates and fame, I thought I can exploit it further. Thus, SudokuH was born – a GUI Sudoku Solver using MAC+MRV algorithm written in Haskell.

Continue reading