An extremely simple Tsdl (SDL2) demo in OCaml

open Tsdl

type point = {x : int; y : int}

let shutdown win =
Sdl.destroy_window win;
Sdl.quit ()

let initialize () =
match Sdl.init with
| `Error err -> Sdl.log "An error occured while trying to initialize SDL: %s" err; exit 1
| `Ok () ->
match Sdl.create_window ~w:800 ~h:600 "Game" Sdl.Window.opengl with
| `Error err -> Sdl.log "An error occured while trying to create a window: %s" err; exit 1
| `Ok win -> win

let drawFromImg ~imgSurface ~win ~where =
match Sdl.get_window_surface win with
| `Error err -> Sdl.log "An error occured while trying to get the surface of the window: %s" err; exit 1
| `Ok screenSurface ->
let (srcRectW, srcRectH) = Sdl.get_surface_size imgSurface in
let (destRectW, destRectH) = Sdl.get_surface_size screenSurface in
let srcRect = Sdl.Rect.create 0 0 srcRectW srcRectH in
let destRect = Sdl.Rect.create where.x where.y destRectW destRectH in
Sdl.blit_surface imgSurface srcRect screenSurface destRect

let () =
let win = initialize () in
match Sdl.load_bmp "image.bmp" with
| `Error err -> Sdl.log "An error occured while trying to load this bitmap: %s" err; exit 1
| `Ok imgSurface ->
drawFromImg imgSurface win {x = 0; y = 0};
Sdl.update_window_surface win;
Sdl.delay 10000l;
shutdown win;
exit 0

Code in public domain :)

I am currently learning SDL2 (and OCaml too :) ) for using it with the thin OCaml binding Tsdl by Daniel Buenzli to create a 2D game.
And because there aren’t any tutorials for this binding and pretty bare bones documentation, I thought I’d share this extremely basic example, which displays a bitmap image (named image.bmp) located in the same directory as where source code file resides. Make sure the image isn’t larger than 800 * 600 ;)

P.S. : thanks to numerous people on #ocaml (Freenode IRC) for helping me even getting this to compile ;)

Posted in Uncategorized

Indian Rock Python game

As you may have noticed today I added the Indian Rock Python game page to this website.

Indian Rock Python is my first game, you can read more about it on the Indian Rock Python game page.

Posted in Uncategorized

Interview with Jolla [questions and answers][updated!]

I would like to do a short online interview with Jolla about how the workspace of sailors looks like. I’ll post some questions here and if Jolla wants they can answer the questions in the comments area ;) I’m sure the other fans would like something interesting to read about Jolla while they wait for the first device to launch

[UPDATE]:Jolla has replied to the questions. So you can now read the answers :)

[Question 1]: What OS do sailors (mostly) use during working hours?
[Answer 1]: GNU/Linux (I didn’t expect anything else :D ;) )

[Question 2]: If the answer to question 1 is “GNU/Linux”, what desktop environment/window manager do (most) sailors (mostly) use during working hours at Jolla?
[Answer 2]: Basically the 3 biggest Linux DE’s are about equally used within Jolla and some other DE’s/WMs are also used, but less. It looks like the market share of DE’s/WMs within Jolla pretty much reflects that of the whole Desktop Linux landscape.

[Question 3]: If the answer to question 1 is “GNU/Linux”, what distribution/distro do (most) sailors (mostly) use during working hours?
[Answer 3]: Ubuntu wins, but there are lots of Fedora users within Jolla too. And also other distros. It surprises me that Ubuntu (which is Debian (.deb) and apt-get based) wins, where as Mer and Meego (where Sailfish is based on)is RPM based and uses zypper. I’d expect to see openSUSE usage (which is both RPM-based and uses zypper, just like Mer does). But at least it shows that the Jolla guys are quite flexible and can work with both tools.

[Question 4]: What are the favourite editors/IDE’s from (most) sailors? Qt Creator? KDevelop? vim? emacs? kate?
[Answer 4]: Both Qt Creator and vim/emacs commandline editors heavily used within Jolla. This isn’t too surprising.

[Question 5]: Which programming language do (most) sailors prefer during working hours when programming QML apps for Sailfish, JavaScript of C++?
[Answer 5]: Well basically a bit of everything seems to be used inside Jolla. With C++ and QML/JavaScript clearly leading the pack.

[Question 6]: Which language is primarily spoken inside Jolla during working hours? English? Finnish?
[Answer 6]: English is the language that primarily is spoken within Jolla, which makes sense because Jolla seems to employ people from lots of different countries. Jolla was founded by Finnish people and a lot of Jolla employees are Finnish. Therefore it also makes sense that Finnish is spoken too.

Tagged with: , , , ,
Posted in Uncategorized

My new weblog!

This is Superpelican’s new weblog, replacing

Posted in Uncategorized

Get every new post delivered to your Inbox.