10/18/12

OpenGL, Glut in Haskell on Windows

OpenGL, Glut in Haskell on Windows

Okay so you are feeling little adventurous and want to try out some of your functional programming skills in Game and Graphics programming. Well how about Haskell afterall it is a hardcore FP Language which can be compiled or interpreted! Lets try it out with the good old utility library Glut.

We will start with
Haskell Platform which is Haskell distribution with many useful packages of which the most useful for us are the Glut and OpenGL bindings package.
FreeGLut which is the completely open sourced version of Glut. Now we will save ourself a little time and LOT of hassle by downloading prebuild binaries instead of building ourself from Martin Payne's Windows binaries for MingW. Make sure you grab the MingW package as Haskell bindings for Glut seems to be build with MingW gcc.

Now once you have downloaded and installed Haskell Platform, and unzipped the FreeGlut binaries, take the following code and copy to a HelloWorld.hs file.
import Graphics.Rendering.OpenGL
import Graphics.UI.GLUT
 
main :: IO ()
main = do
  (progname, _) <- getArgsAndInitialize
  createWindow "Hello World"
  displayCallback $= display
  mainLoop
 
display :: IO ()
display = do
  clear [ ColorBuffer ]
  flush


On a windows machine compiling this with ghc -package GLUT HelloWorld.hs -o HelloWorld will generate a HellowWorld.exe which will probably complaint and fail with missing dll error on running. Have no worries thats what we downloaded those binaries of freeglut for. Now copy the freeglut/bin/freeglut.dll to the directory containing HelloWorld.exe and rename it to the missingg dll which haskell has been complaining about ( most probably glut32.dll ). That's it. You should be having a working program doing absolutely nothing :).

10/6/11

HBase Setup Guide

There is a hbase setup guide for a single node ubuntu box running on top of hdfs.
Find it at Ubuntu Single Node Hbase Setup

12/7/10

Setting up HSQL 2.0 database

I am going to take a file based HSQL database, mentioning that is
important since HSQL can work as a in memory database too.
An easy way to start multiple hsql databases is by defining then in the
server.properties file. The content for it should look like:

server.database.0=file:./database/mydb
server.dbname.0=mydb

Note that you can defined multiple databases like this with increasing
indexes.
The scripts and properties files for the database are inside the
'database' folder i.e. mydb.script and mydb.properties.
Lets say if you are starting from scratch then, the content for them can
be copied from any test.script and test.properties file.
And these test files are generated automatically when you don't defined
a db to HSQL while starting it.

12/6/10

Configuring HSQL datasources in jetty for j2ee web applications

First an entry has to be put in the WEB-INF/web.xml file


  <resource-ref>
    <res-ref-name>jdbc/mydb</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>

Then for jetty we can use a special config file, which is looked up in every j2ee application deployed in jetty
i.e. jetty-env.xml . We put this in WEB-INF/jetty-env.xml of the webapp. The content of files look like


<Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext">
<New id="mydb" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jdbc/mydb</Arg>
<Arg>
<New class="org.apache.commons.dbcp.BasicDataSource">
<Set name="driverClassName">org.hsqldb.jdbc.JDBCDriver</Set>
<Set name="url">jdbc:hsqldb:hsql://localhost/mydb</Set>
<Set name="username">SA</Set>
<Set name="password">PASSWORD</Set>
</New>
</Arg>
</New>
</Configure>

Please note that jetty is not a full j2ee container. We have to explicitly change the jetty configuration files in order to enable jndi lookups.