Skip to content

My PHP , Wordpress and Linux Lab

JOGL : OpenGL with Java

Apr 22
Posted by : Sabeen Malik in JOGL, Java

Java does not natively support accessing the OpenGL API. A wrapper library called “JOGL” was introduced to ease the pain of making this integration happen. JOGL allows access to most features available to C programming language programmers, with the notable exception of window-system related calls in GLUT (as Java contains its own windowing systems, AWT and Swing), and some extensions.

JOGL homepage is located at http://kenai.com/projects/jogl/pages/Home. The JOGL team has made the wrapper available for all widely popular platforms Windows, Linux, Solaris and Mac. There nightly builds can be obtained from http://download.java.net/media/jogl/builds/nightly/ you can download the platform specific JOGL package from here. The zip downloaded should be extracted and the installation instructions can be found in Userguide.html included in the zip.

The basic install procedure requires setting environment variables. On the windows platform this can be achieved by going to Control panel > System > Advanced tab.

environment

Extract the contents of the zip downloaded to lets say c:\jogl, inside it you will find the “lib” folder. If a value for CLASSPATH doesn’t already exist in the environment variables, then create one and you in the paths for these files jogl.all.jar, nativewindow.all.jar, gluegen-rt.jar and optionally newt.all.jar. The path might eventually look something like the following:

.;c:\jogl\lib\jogl.all.jar;c:\jogl\lib\nativewindow.all.jar;c:\jogl\lib\gluegen-rt.jar;c:\jogl\lib\newt.all.jar

Make sure there is a “.” at the start or end of the path, this is required for java applications to work properly.

The next step is to put the lib path in the PATH environment variable, just find the PATH environment variable, click edit and then append “;c:\jogl\lib” to it.

There is a sample code attached at the end of the tutorial which should work once the above steps have been completed.

Normally this is what is required to setup JOGL however the easiest and speedier method to get started is to use Netbeans.

Using Netbeans

Download Netbeans, probably the best IDE for java developers from http://www.netbeans.org, make sure the package you download includes “Java SE”. Once the download is complete, follow the installation instructions to complete the install.

Now download the Netbeans OpenGL pack from http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=3260, once the download is complete extract the contents of the zip.

If you are using Windows vista or Windows 7, you will need to start Netbeans as an administrator, you can do this by right clicking on the Netbeans icon and clicking on “Run as Administrator”. Once Netbeans has been fully loaded go to the “Tools” menu and click “Plugins”. Now in the dialogue box click the Settings tab and tick the option “force install into shared directories”. Now goto the “Downloaded” tab and click “Add plugins” and browse for the extracted folder contents, select all the files in the folder and click open.

After that click the install button and follow instructions to complete the install procedure, you will be required to restart Netbeans after the plugin installations are complete.

The following screenshot shows how the plugin files are selected and opened.

plugins

After restart, now Netbeans is ready for you to start coding away amazing OpenGL based applications.

To test your installation, click on File menu in Netbeans, click “New Project”, select Java from the list and then select “JOGL Application” from the second list, click next and set your project preferences and click Finish. This will load a simple JOGL project, which can act as a guide for you to get started with OpenGL development in Java. Just build and run the application to see OpenGL in action. Some more sample JOGL projects are also available for testing in the “Samples” section of the Project type list.

Obtaining Help

As JOGL is a work in progress, it is recommended to follow the wiki and the forum on regular basis to keep you updated with the latest developments. A lot of source code found around the internet would be obsolete as it would belong to the earlier versions of the JOGL.

User Guide: http://download.java.net/media/jogl/doc/userguide/

Java Docs for JOGL 2.x: http://download.java.net/media/jogl/jogl-2.x-docs/

JOGL Demos: http://download.java.net/media/jogl/demos/www/

Forum: http://www.javagaming.org/index.php?board=25.0

Sample Code Download

A couple of users thankfully pointed out the issues with the paths, as i am stuck with windows as a development platform,  case sensitive directory names mess things up on Linux. So very minor updates to a few files.

Also PLEASE read the README file provided in the zip for the instructions on how to set up the application.  PHP Viz needs a database for storing the configurations and settings, so that must be created by using the SCHEMA.sql provided.

Download PHP Viz 0.2.1

Full text searches have been the one part which would always worry me in any project which will hold a reasonable amount of data with a decent traffic.  Not anymore!

I have been using Sphinx for a while and i have been really impressed. Easy deployment, easy integration and its pretty flexible as well. I cant say that i have explored everything it has to offer but whatever I needed it to do, it surely did for me.

Among other features you can use it to rank , filter ,  group , sort and query to targeted columns. It even supports “Sounds like” searches ….. wonderful! .  With several different matching and ranking modes , ones got to be right for you.

The PHP Client is a pure PHP implementation, so no deployment headaches. The PHP client API is included in the download package, hook it up with your DB wrapper and you are ready to battle with those Full Text Searches. What it would do is .. it would return to you the ranked record IDs, along with weights and then you can bring the full record of that ID directly from MySQL. Response times from Sphinx are amazing, So far I haven’t seen it take more than 0.7 seconds to return the resultset. Best of all, you can scale as much as you need, without any problems.

Here are the key features taken from their site directly:

  • high indexing speed (upto 10 MB/sec on modern CPUs)
  • high search speed (avg query is under 0.1 sec on 2-4 GB text collections)
  • high scalability (upto 100 GB of text, upto 100 M documents on a single CPU)
  • supports distributed searching (since v.0.9.6)
  • supports MySQL natively (MyISAM and InnoDB tables are both supported)
  • supports phrase searching
  • supports phrase proximity ranking, providing good relevance
  • supports English and Russian stemming
  • supports any number of document fields (weights can be changed on the fly)
  • supports document groups
  • supports stopwords
  • supports different search modes (“match all”, “match phrase” and “match any” as of v.0.9.5)
  • generic XML interface which greatly simplifies custom integration
  • pure-PHP (ie. NO module compiling etc) search client API

Amazing stuff! So if you are in the business of developing high volume traffic and/or data sites … you have to check it out for sure! Its available for both Linux and Windows platforms!

2 Thumbs Up for these guys!

It brings me tremendous pleasure to announce the first public release of PHP Viz.

PHP Viz is an open source PHP code generator , which is also written in PHP 5 , released under the GPL license. It allows you to create MySQL based sites rather than just pages. The resulting sites follow a very simplified MVC pattern, which allows re-usability and partitioning of code.

The best feature PHP Viz provides is the linking of Primary keys to Foreign keys and allows you to display records from linked tables. You can create modules for adding , editing , deleting and viewing data. Once you have created your modules, you can create pages which hold one or more of your modules. Reusing these modules in custom code is pretty easy as well and allows you create independant entities which can be plugged into any page.

The application is in a very early stage of development and I am hoping to get alot of feedback, based on which I will prioritize the features that need to go in there.  Soon I will make available an online demo version as well for quick viewing of all the features.

Please read the README file found in the zip to find the install instructions.

Please feel free to put in any comments and feedback in the comments area.

Download PHP Viz 0.2


Update : Sorry guys the link was broken earlier , thanks to some nifty logic in WordPress , should be working now!

Some screenshots below:

Main Screen

Site Modules And Pages

Module Settings

Generated Site Login Screen

Generated Site View Data Screen


UPDATE: Please turn on “short open tags” in php.ini .. i will try to remove all the short tags in the next release.  My apologies for this oversight.

I have been so busy over the past 2 years that I almost forgot about this code generator that I started to write. But recently i resumed work on this and created a new version from scratch.  and I am very happy with the results so far :)

PHP Viz is written in PHP and lets you create MySQL driven PHP sites. A prime feature it provides is the support to link up multiple tables (based on foreign and primary keys) and create views from them.

The application lets you create “sites” rather than simple pages. You can even have Login protection on your site if you have a users table in there somewhere in your database. All the basic functions are there , you can create tabular views, single record view , add and edit view. The generated code is very clean , simple and based on a very very simplified MVC architecture. This allows for expansion and code re-usability with ease.

The application code itself  is very rough at this point and i just want to see some feedback from the community to make sure that i am heading in the right direction. I am hoping to add some more advanced level features down the line and hoping to make this an every day tool for the PHP developer.

PHP Viz 0.2 should be publicly available within the next week. I am hoping that the next Site Admin you make is built by PHP Viz :)

IEEE CS offers Free Brainbench Tests

Jun 16
Posted by : Sabeen Malik in Uncategorized

IEEE CS in agreement with Brainbench , is offering free tests for members. This is an amazing offering, even if you are not interested in transcripts, you guys can still go in there to prepare for professional exams like MCSE , Cisco certifications etc. You can consider these are free practice tests. The e-Learning campus not only offers these free tests but you also get access to 600 online books relevant to Computer Science and alot of free courses.

This is a great chance to improve your CV.

This is something which I must share with everyone. Microsoft in agreement with IEEE , offers quite a few free softwares to IEEE student members. The offering includes (but is not limited to ) :

  • Windows Vista Business and Enterprise Editions
  • Windows 7 Ultimate RC and Beta
  • Windows XP ( SP 3)
  • SQL Server Enterprise and Developer Editions ( 2000 , 2005 , 2008)
  • Windows Server 2003 and 2008
  • Visual Studio 2003, 2005 and 2008
  • Access 2003 and 2007
  • Virtual PC
  • Office Grove
  • Project Professional
  • Visio Professional 2007
  • Expression Studio
  • ISA Server 2006 Enterprise Edition
  • Biz talk
  • Infopath
  • OneNote
  • SharePoint

……. and that is all for free and this is not even the complete list but that i believe are the most important ones.

Once you signup as student member of IEEE Computer society or IEEE ( each costs $12.50 for students ) , after appox. 7 days you get the Login information for the e-academy member area , from there you can purchase all those softwares for $0 and then download them.

Another limited list of Free Microsoft software for student is available at www.dreamspark.com

All you CS students, what are waiting for!

SVN and MySQL Schema Synchronization

Sep 29
Posted by : Sabeen Malik in MySQL, PHP, SVN, Web Development

When I started to work in a virtual team comprising of 6 developers , I felt that the most time consuming task was syncing the database changes amongst team members. As we were using SVN , we didn’t have to worry about the files but the DB schema was always an issue. So I started to look into something solid which we could couple of with SVN client in order to make this process as smooth as possible. Blame it on my search capabilities or eye sight but honestly i didn’t come across something I liked. So i devised a mechanism which might be far from ideal but which is working well for us. Keep in mind that we all are working in Windows environment (as the client is using Windows server) , so some steps might be slightly different for people in the Linux camp.

Here is what I did :

Step 1:
I located a ready made script which would let me sync 2 databases. I found a well written class by “Diogo Resende” here

Step 2:
I modified the class , so that instead of actually syncing the databases , it would just return the queries which it is going to run in order to sync the databases.

Step 3:
Now I created an exact copy of my current database , lets call this database “test”. The called the copy i created “svn_test”.  Keep in mind that my working database is still “test”. After this point I never touched “svn_test”.

Step 4:
I created a small database on my online server with a table called “changes” with  change_id , change_set , submit_time fields. “change_id” was set to be primary and auto increment. I created a one page management script for this and placed the script on the remote server to be easily accessible by all. Lets say the location of this script is http://something.com/changes_list.php. This script lists all the records in descending order. I can edit , delete and add records from this script as well.

Step 5:
I created a PHP script called “pre_hook.php”, which would compare “test” and “svn_test” and return to me all the queries. These queries were stored in the remote database table called “changes” , it would store the last returned “change_id” in a file called “change-id.txt”. It would also generate a file called “changed.txt”, if there was no changes ,  nothing would be submited to the remote DB  and  the  file “changed.txt” will be deleted if it were present. This script also created a file called “run.bat” , if there were any new queries , the script would insert explorer “http://something.com/changes_list.php in the “run.bat” file , otherwise it would just insert “exit” in it.

Step 6 :
I created another script called “post_hook.php” , it would check if “changed.txt” was present , if so it would replace the database “svn_test” with “test”.

Step 7:
I created yet another script called “post_update.php” , which would connect to the remote database and tried to find query the records which were entered after its last run. The script stores the highest “change_id” it got in a text file. So next time it would only try to query for records which are higher than the stored “change_id”. If the script got any new records from the remote database. It would parse the queries in each record and run them on database “test”.

Step 8:
As we all use Tortoise SVN , I created 4 hooks. A hook on “start commit” , this hook would run the “pre_hook.php” script. Hook 2 was created on “pre commit” which would run the “run.bat” file created by pre_hook.php. Hook 3 was created on “post commit”, this would run the “post_hook.php” script. Hook 4 was created to on “post update” , this would run the “post_update.php” script.

How it works (or is supposed to work):
After all the above steps. I goto the database “test” and make a change to xyz table. Now remember that “svn_test” DOESNT have this change. So now i continue to work on php scripts and I decide to commit to SVN. So what will happen is when the commit starts the “pre_hook.php” will gather all the schema changes (if any) , send them to the remote MySQL database , place the link to the remote script I deployed at http://something.com/changes_list.php inside the “run.bat” file. BEFORE actually sending the files to the SVN , the” run.bat” would be executed and it would show me the list of changes that were just submitted , so that i can view them manually as well and adjust if needed , which is rare . After the commit is complete , the “test” database is copied over “svn_test” by “post_hook.php”. Next time someone updates the repository , the “post_update.php” script will kick in after the update is complete and return all the new changes submitted to the remote database. Now that persons database has the changes I made to mine as well. The remote DB management script also lets us input other queries as we may please.  So that on next update everyone can get the changes those queries reflect.

This system is not perfect, but it saves us plenty of time.  I am still thinking/searching for a better solution , which takes care of the changes in the data as well but for now this is what I have.

Hoping that this would help someone else as well.

PHP Code Cleaner : Download

Jul 25
Posted by : Sabeen Malik in PHP

Alot of people have been asking me regarding the installable version so I just zipped up the files I had on my hard drive for PHP Code Cleaner. The files include a script which helps you clean up multiple files at the same time. Just go through the “readme.txt”.

Please understand that the code is a very raw attempt on solving the problem of cleaning and indentation , so it does have its problems. Please report the bugs you can find and i will try to fix them as soon as i find some time.

Download

Mars , The Red PlanetThe universe is so full of surprises , plenty of buzz around regarding the new photo released by NASA which shows a female like figure on the Red Planet. Brilliant!

But on careful examination, its anyones guess really, it could just be like the faces of Mars we saw a few years ago. But i found really interesting were the ripple effects we see in the picture. Amazing , they just seem like there was a river flowing there. The curve in the surface indicates it as well. I have marked the interesting regions in red boxes , you should click on the thumbnail to see the interesting areas , i have reduced the size of the picture and then download the full picture to feel the full effect.

Honestly , if I wasn’t told this was a picture from Mars, me the ignorant would have thought, this is a picture of the rocky mountains or something. :)

You can download the full 44MB picture from NASA by clicking on this link.