Saturday, July 5, 2014

DirectX SDK

Now I'm reading a book Beginning .NET Game Programming in C# [11]. It talks about using the technologies of GDI+ and DirectX. GDI+ is used for 2D, and DirectX for 3D. The book was published in 2004, so it uses VS.NET 2003 and DirectX SDK 9. The book is easy to read, so I was able to quickly skim through in 3 hours. It seems to be clearly written, with 7 chapters and several example games. At the end there is a bonus chapter on porting a game, .Nettrix, to Picket PC. Appendix A gives a list of recommended game programming books for interested readers. Appendices B, C and D are experiences and suggestions on how to make good, successful games by veteran developers.

For a brief idea on the comparison of GDI and DirectX, see [2][3].

DirectX is Microsoft's technology on high performance graphics application development.

The most recent version is DirectX SDK v9.29.1962 released on 06/07/2010, and can be downloaded here [9]. It works on windows XP and above. If you just want the DirectX End-User Runtime, you can download here [10].

Since Windows 8, the DirectX SDK is combined into Windows SDK [1]. If you have VS.NET 2012 installed, it should include it.


== DirectX development in VirtualBox XP ==

Microsoft's Tutorial on DirectX programming is at [4][5] (note tutorial in [4] is on C#, but the SDK downloaded form [9] contains only C++ examples).  I got error "D3DERR_NOTAVAILABLE" when running example programs (from the book [11]) on XP in mac VirtualBox. Don't know this is a limitation of the mac hardware or of the VirtualBox environment. After following the diagnosing procedure in [6] (basically using the dxdiag console command), it seems XP in VirtualBox does not support Display support of Direct3D, DirectDraw might be supported by software.  I found [7], and followed it to install Guest Extension in safe mode, and installed Direct3D support (note after this, running video such as in youtube could have mosaic effect initially, use dxdiag to disable/enable DirectX support, and reboot, the problem then is gone).  After this, when running dxdiag again I got this error in [8], test passes for DirectX 8 and 9, but not 7, which seems to be expected behavior.  The tutorial program can run properly.  For the gaming book examples, some still reports openGL warnings as in the screenshot below (Figure 1). However, the games can run! And some of these are cool games with realistic 3D video and wave sound, such as Space donuts (Figure 2) and Spacewar 3D (Figure 3).

Conclusion is I should be able to do Direct X development in VirutalBox XP :)


Figure 1. OpenGL warnings

Figure 2. Game: Space Donuts

Figure 3. Game: Spacewar 3D


References:

JavaEE and SSH (Struts/Spring/Hibernate)

Java Structs/Spring/Hibernate are used widely to created JEE applications.

Some resources are here:

- A self-contained Java Struts Spring Hibernate Tutorial [1] in pdf to download. About 80 pages.

- mkyong.com [2] has many tutorials. E.g., Struts 2 + Spring + Hibernate Integration Example

- AppFuse [3] is a full-stack framework for building web applications on the JVM. It can generate SSH website template in SSH. This is a demo site of it.

The JEE ecology system is large, complex and distributed. It contains a lot of technology and can build highly professional enterprise web applications. However the distributed nature decides that it is poor to manage. For example, for each new functionality, one needs to go to a website, download another Jar and include it into the lib. This is comparable to adding references in VS.NET. In VS.NET all references come in package out of the box, and is much easier to handle mentally and practically. Another example is the directory structure. JEE directory structure is much more convoluted than ASP.NET, which artificially adds difficulty to the understandability.


== Servlet and JSP ==

Basically, servlet is more primitive, can use different protocols, embed html in java code. JSP is layered above servlet. JSP uses HTTP protocol, embed java code in html.  JSP is compiled into Servlet class automatically by container server (e.g. Tomcat).  JSP is more modern, like ASP and PHP, has better separation of java logic from UI presentation.

See more at [4][5].

== Tomcat ==

Tomcat is an application server for Java servlet.

It is possible to use Tomcat independent from Apache. But Tomcat works only for Java Servlet, and does not have as many other functions as Apache.

This is what happens when Tomcat works together with Apache. When Apache receives a browser request as a long stream of bytes, it passes it to Tomcat, which creates a request object to parse the stream into request parameters, and passes the request object to a (servlet) java class. After the (servlet) java class finishes the processing, and returns a response object, it then interprets this into a http response stream and passes the stream to Apache to be sent back.

To configure Tomcat to work with Apache, a Tomcat-Apache connector module is needed. This is often the mod_jk module using Apache JServ Protocol (AJP). By default Apache uses port 80, Tomcat uses 8080, the mod_jk module uses port 8009.

See more at [6][7][8].

== Development with Eclipse ==

Tomcat uses port 8080. If development and production are on the same machine, as in the case of personal project, Eclipse can do development in a separate Tomcat instance, the port number can be configured in server.xml, e.g., to 8081. At deployment time, it can use the export function (similar to Android project being exported to a apk file) to package the project into a *.war file. The *.war file, when deployed to the Tomcat server in production, is unpacked (you can do this manually with: jar -xvf *.war) and being served. This way, development and production use different Tomcat instances and different ports on the same machine.

To know if a port is being used by any process, say port 8080, type this:
sudo lsof -i :8080
To kill such process and release the port graciously [9], do:
sudo kill -15 <pid>
Here the tomcat pid can be obtained by:
ps -ax | grep tomcat

When running Tomcat with Eclipse, the server path used by Eclipse (similar to wwwroot for IIS, or /var/www/html for Apache, or /var/lib/tomcat7/webapps/ for Tomcat7) is:  workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps

== Issues running Eclipse with Tomcat ==

My feeing with Eclipse JEE development is, many configurations can go wrong. There is no central support, so you just get on google and search for other people's discussions and solutions. The quality of environment integration is less mature as the .NET world. For example:

1) after first creating a project, it may complain the j2se1.4.0 JRE not match installation jdk. So you have to go to Library, and reselect the jdk to use.
2) another example, Tomcat7 installation has one directory at /var/lib/tomcat7/, and another at /usr/share/tomcat7. The latter needs references to many files/folders in the former location, so you need to manually create soft links in the latter place.
3) add a server to the current project may not work, and complains port 8080 already in use, for this you need to change the port number used in server.xml.  Solutions to these problems are found online, e.g., in [9][10][11][12].
4) as one more prominent example, I finished the tutorial project in [1], in the process I need to download lib jar files from 15 different websites to set it up.
5) use the log4j project as an example, in version 1.2, one file log4j-1.2.17.jar can do it. But in version 2.0-rc2, you got a large number of jar files to choose from, for different platforms at least, have to include the api and core jar files, then some others. It's getting way bloated up.

Compared to the IIS world, there are much to worry here, and many need manual setup.  The .metadata folder under the current workspace contains many files and is complicated.  If you kill the Eclipse process before it's properly shutdown, Eclipse may not be able to start, and fix is to remove something corrupted here in .metadata.

== Struts ==

A MVC web framework for JEE development. For more details see [13][14].

== Spring ==

A programming and configuration framework for JEE development. Its principles include IOC (Dependency Injection), AOP, MVC, Convention over configuration etc. It's ambitious. But criticisms say it's just a loose bundle of best-practices.

For more details see [15][16].

== Hibernate ==

An ORM module for JEE development. ORM stands for Object-Relational Mapping. It basically handles all the work connecting to database and hides the details, through the use of configuration files. For more details see [17][18].

Java SSH can be used together. One major reason of their appearing was to address the unnecessary complexity of EJB.

I feel it's too much building up of concepts, which are often old wine packaged in new bottles. Servlet and JSP are the most primitive building blocks of the entire stack. While these technologies aim to provide a framework that's supposed to make enterprise application development easy, they are actually creating layers over layers, and become very much counter-intuitive to pick up.  Tools are just tools, but now just to learn how to use the tools can become a full time job.  In this aspect, LAMP and .NET are much more intuitive.


References:

[1] Java Struts Spring Hibernate Tutorial
[2] mkyong.com - Java related tutorials
[3] AppFuse - a full-stack framework for building web applications on the JVM

[4] Difference of JSP and Servlet
[5] Coding Servlet and JSP from ground up
[6] Can Tomcat run WITHOUT Apache
[7] Tomcat.apache.org: omcat-Apache Howto
[8] Apache 2 with Tomcat 6: How to configure Tomcat to work with Apache

[9] Tomcat startup 8080 port already in use
[10] Eclipse cannot load the tomcat server configuration at serverstomcat-v7-0-server-at-localhost-config
[12] Cannot add a new Tomcat server

[13] struts.apache.org
[14] Wiki: Apache Struts
[15] spring.io
[16] Wiki: Spring Framework
[17] hibernate.org
[18] Wiki: Hibernate (Java)


Apache projects

A full list of Apache projects is here: http://www.apache.org/dist/

For example:

- For httpd web server, it's here: http://www.apache.org/dist/httpd/. This repository contains the source code.

- Here is the Apache Commons project, which aims to provide reusable Java components. Among these is the Java Commons Daemon component for both windows and unix.


Friday, July 4, 2014

Hiren's Boot CD


Hiren's Boot CD is a bundle of system utilities in a bootable CD.  Here is a list of included software tools.

It is highly useful.

For example, my Windows installation on VirtualBox used 2 partitions C: and D:. Unfortunately C: drive is only 6GB. I found the space not enough when I tried to install VS.NET Express 2008 and relevant server development softwares.  Then I used a tool (Partition Wizard Home Edition 7.0 in the Partition Tools section, see here for a short introduction with screenshot) from this CD to shrink D: drive and expand C: drive. Now I have 14GB on C: drive, enough to fit in the softwares I wanted.  It only took 5-10 minutes and 2 automatic reboot, partly because the disks are still quite empty.

Just download the ISO (at the end of this page, or direct link here) and burn it to a CD, or just mount it virtually. The download is about 592.5MB in size.


Thursday, July 3, 2014

Notes on Git and Github

##############################################
# Create a new repository on the command line

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/[username]/[project name]
git push -u origin master

##############################################
# Push an existing repository from the command line

git remote add origin https://github.com/[username]/[project name]
git push -u origin master


##############################################
# Create new local clone from a remote project:
git clone https://github.com/[username]/[project name]

##############################################
# Push to remote repository after update local files (in "git add .", dot "." means all changed files)
git add .
git commit -m "..."
git push -u origin master


##############################################
# Revert to a previous version [5]

# Shows all previous versions with hash value
git log --oneline
# Checkout given version given hash value. Change will be saved to repository
git checkout <hash>
# Checkout individual file. Will be saved to repository as change
git checkout <hash> <filename>
# Checkout most recent version
git checkout master


##############################################
# Other commands

# Show status of local repos
git status

# Update local files from remote repos
git pull

# More commands by usage frequency
git diff
git log
git mv
git rm

git tag
git branch
git merge

git checkout
git fetch
git grep
git reset
git rebase

# In general, get help information.
git help

usage: git [--version] [--exec-path[=]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects]
           [--bare] [--git-dir=] [--work-tree=]
           [-c name=value] [--help]

           <command> [<args>]

The most commonly used git commands are:
   add        Add file contents to the index
   bisect     Find by binary search the change that introduced a bug
   branch     List, create, or delete branches
   checkout   Checkout a branch or paths to the working tree
   clone      Clone a repository into a new directory
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   fetch      Download objects and refs from another repository
   grep       Print lines matching a pattern
   init       Create an empty git repository or reinitialize an existing one
   log        Show commit logs
   merge      Join two or more development histories together
   mv         Move or rename a file, a directory, or a symlink
   pull       Fetch from and merge with another repository or a local branch
   push       Update remote refs along with associated objects
   rebase     Forward-port local commits to the updated upstream head
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index
   show       Show various types of objects
   status     Show the working tree status
   tag        Create, list, delete or verify a tag object signed with GPG

See 'git help <command>' for more information on a specific command.



##############################################
# Difference of git add -A, ., -u [6].



##############################################
# github usage:
[1] https://help.github.com/articles/creating-releases
[2] Git Tutorial
[3] A successful Git Branching Model
[4] Github md file formatting
[5] Undoing git changes
[6] Difference of git add -A, ., -u


Tuesday, July 1, 2014

Birthday Calculator update

Today updated the Birthday Calculator Android App according to the feedback of the friend. Added these functions:

1) Instead of using keyUP() which does not work for real Android phone touch screen event, now it is using OnChange event, actually, TextWatcher is the name here.
2) Tax is added. Check the checkbox in front of Tax, then Tax is included in tip calculation.
3) The settings page is setup now. The tax rate is included in setting.

The new interface is like this:




More iOS and Android programming, and OCR library

In the past month I have followed the book Beginning iOS Programming to build the Bands App, which has many features, such as accessing iPhone's photo album and camera, data storage, sharing band information via email and instant message, searching internet for band information, finding music stores on google map, and using iTunes web service to listen to song previews.

Today I also build my first Android App: the Birthday Calculator. The idea came from a friend, who used to have trouble calculating per person bill for a birthday party, where the person on birthday is free of charge, other people pay. He wanted an App to do the calculation. I did it today, just one day, about 8 hours. It's more just like a Bill calculator, given total bill (plus tax), tip rate, and number of persons, calculate per person bill. When running inside Android simulator, the interface is like this:


The top text box lets one enter the total bill (plus tax). Under this the user can choose from 4 fixed tip rates: 10%, 15%, 20% and 25%.  It also allows the user to enter a customized tax rate, which defaults at 17% when the App initially starts. Under this the user can increase or decrease the number of persons using two buttons, or enter directly in the text box to the right side. The last line in green shows per person bill.  Whenever the user changes anything on the UI, the bill, the tip rate, or the person number, it automatically updates all other fields for the change, so you see all the values instantly update on the interface as you type.

Considerations are made for exception cases. The total bill allows only decimal number input, and there are the cases the user enters something like ".25". When "." is first entered, the number conversion shouldn't crash the App.  The bill should also be limited to at most 2 decimal digits.  The customized tip rate and person number text boxes allow only integer input.  The customized tip rate is limited between 0-99%.  For person number you need to avoid 0, which would lead to divide by 0 error. Listeners are used to monitor keyUP and onFocus events.

A similar calculator is the 9mi web calculator for salary. They are looking for people to make it onto Android and iOS. Feel like I'm ready for that job.

This is the first step towards a new world for me.


== OCR software ==

Another thing, a friend's son wants to build an App with OCR function. A few days ago I did a search on line about OCR library for iOS and Android.

For iOS, the Tesseract OCR iOS library can be used. Tesseract for Android is also available, see here for experience on how to use it.. The Tesseract OCR was developed at HP lab since the 1990s. Between 1995 and 2006 there were few work done, but after that it was improved by google. It is arguably (one of) the most accurate OCR library. It is under the Apache 2.0 license now. Should be handy to use.

When searching for existing OCR products, a quick search on App store using keyword "ocr" found CamScanner, which has 4.5 star rating, but OCR function is available only for premium version, which costs $4.99/month or $49.99 per year.  Most others are not free, like Scanner with OCR by SwissMadeApps, Pixter Scanner OCR by Quanticapps, SmartScan+OCR by AMAXIM APPS, Perfect OCR by Pksoft Inc. etc.  Leadtools OCR Application has 3 star rating and is free. OCR Scanner by Smart Mobile Store is also free. I downloaded these 2 to have a try.

OCR Scanner seems not bad in recognition quality, but it's UI interface is a little off position to the top, so the top header is half covered and can't be seen. There is no way to cancel a conversion in the middle.  It allows 5 free conversions a day.

Leadtools OCR has a more friendly UI, richer functions, can cancel a conversion in the middle. But the recognition quality seems not so satisfying in dim light, and is more sensitive to disturbance.

Blog Archive

Followers