2008-10-24

Wine, it always tastes sweet!

Another release of Wine today! So what's new in this one? Other than the usual masses of bug fixes ( and there always are at least 50 ), there is some exciting news on the horizon. The beginning of DirectX 10 implementation! The Wine project is a really great open source project and really is going to be a major help in getting people to use Linux. There are always arguments for and against Wine, so let me do a little summary:

Why people hate Wine:

  1. It discourages the development of Linux native apps
  2. It gives people a reason to want Win32 apps
  3. It opens up security risks
I feel that none of these are really valid. Firstly, i feel that if anything Wine encourages creation of Linux apps. In the sense that if it works on Wine, it's a Linux app. So although it might discourage the development of exclusively Linux apps ( which is still debatable ), it will certainly increase the development of apps that work on Linux. This creates a larger useful Linux app base, and everyone is happy. This also makes it easier for people to migrate from Windows to Linux, since they don't have to change the apps they use for Linux replacements if they exist. It's not that Linux apps are inferior, it's just that people are used to certain things, remove those things and they will bring out the pitch forks and hunt you down. For an example look at the anger toward KDE 4's plasma, a great technology that is "different". Secondly, there are reasons people want Win32 apps. Like it or not, Photoshop, Visual Studio, 3D Studio Max and several other commercial applications are the main hurdle preventing businesses from using Linux. I mean what company wouldn't want free software? But from my experience, most professional artists will NOT work with blender or gimp. I don't understand it since i happily use both for any art work i need done in a personal and professional capacity, but the artists i have worked with refuse. On top of this, you have the gaming community. I know at least 20 current or former colleagues who would switch to Linux if the could play <insert modern game name here> on Linux natively. If FarCry 2 or Crysis worked out of the box on a Linux system a lot more gamers would be interested ( especially considering that most of them know how insecure Windows can be and use Firefox as their main browser ). I can't comment all that much on the security risks issue, but i honestly don't see how it could. An app running under Wine has just as much permission to run as a native Linux app, so how can it be less secure? In fact, giving it some thought, a Wine app might has a seperate registry and file tree that it operates in, so there might be even less of a security issue than in a native Linux app ( since deleting the .wine folder is probably less of a loss that deleting the .kde or .gnome folder for example ). Overall i feel that Wine is a great project, one that i should probably be developing on! After my Android app. And my desktop shell. And my windowmanager. And my kde development. You get the point.

#pragma once

As promised, the next part of my coding in Linux guide. Last time i covered my choice of IDE, and now i'm gonna use it. My intent was to work with Open GL, and that will come in time, but after some research it seems that my blog is more popular amongst KDE users. So, this is the plan. A basic QT app, with Open GL included somewhere :)

In Codeblocks there are many project options. Making sure that you already have qt4-devel packages installed, create a new QT4 project. It'll probably ask for an Environment variable path. Define the Base to /usr and that should be it. Then Codeblocks will hopefully give you a main.cpp containing the basic QT setup. Running this app should give a simple window with a Quit button.

QT reference/tutorials can be found here, its a great thing to keep open if u'r coding an app and your main aim isn't the UI. After all thats why i prefer QT, it lets me focus on my app and not have to deal with really disgusting UI code ( note GTK and Win32 ). In QT there are 2 constructs which you probably won't have seen outside of QT code:

  1. SIGNAL: a sort of event triggered, like clicked() or valueChanged() or anything you want.
  2. SLOT: a response for a signal.

To make use of the SIGNAL/SLOT features of QT, make your object inherit from QObject ( directly or indirectly ) and add Q_OBJECT right at the top of the class declaration ( just after the opening brace ). Then you have access to the slots and signals macros which can be used in an equivalent way to private and public. You also have access to the emit keyword, which allows your app to send a signal to whoever might be listening.

So, time to actually do something.

In Codeblocks, create a new file, selecting a C++ header. Once you've given it a name ( and path ), you'll see that Codeblocks auto generates a header guard word! Note that although usage of #pragma once is pretty standard, it isn't actually in the C++ specification, so it doesn't have to work. Click All on this dialog to add you're new header to all build targets ( another thing i love about Codeblocks, build target config is really simple ). Create this, and create a cpp in a similar way. I made a basic QT app:

myApp.h
#ifndef MYAPP_H_INCLUDED #define MYAPP_H_INCLUDED #include ; class myApp : public QObject {   Q_OBJECT public:   myApp( QObject* parent );   ~myApp(); public slots:   void updateColor( int newValue ); signals:   void colorChanged( int newValue ); private:   unsigned int m_red;   unsigned int m_green;   unsigned int m_blue; }; #endif // MYAPP_H_INCLUDED
myApp.cpp
#include "myApp.h"

myApp::myApp( QObject* parent )

:

QObject( parent ) {   printf("Creating myApp\n"); } myApp::~myApp() {   printf("Killing myApp\n"); } void myApp::updateColor( int newValue ) { }
Now this will not compile ( sadly ). Due to the way QT works, you need to perform a meta-object compilation, using the moc tool. If you look in your project's Build Options, under Pre/Post build steps, we can add custom commands. I added a script to my projects root folder ( called runMoc.sh ), and added the following to the custom commands:
./runMoc.sh
The contents of my script is:
#!/bin/sh grep -l Q_OBJECT *.h > files_to_moc cat files_to_moc | while read line do   echo "Moc'ing file $line";   ext=h   output=${line%h}   moc $line -o "moc_$output""cpp" done
Although the details don't really matter, the script basically finds all .h files with Q_OBJECT in them and calls moc on them. Then the moc call generates a new cpp called moc_.cpp. Now if we do a build, it will run moc on our file and create this new cpp ( and give build errors ). Add this new cpp ( in my case, moc_myApp.cpp ) to the project ( remember to put it in both Debug and Release targets ), and build again! This time, no errors. If we add anymore Q_OBJECT files, all we have to do is add the build generated cpp to the projet. I realise it's a bit annoying having to add the cpp to the project every time we add a new file ( and trust me, i'm looking for a better way of doing this ), but its better than learning about Makefiles! Other IDE's like KDevelop ( and presumably the new QT IDE ) will do these things automatically, but then you wouldn't get all the cool other features Codeblocks gives you.Since this has become a really long article ( mostly due to the code inserts ), i'm going to cut it here. Now we know how to set up a QT project and use the cool features, so next time we should actually do something with them.

2008-10-14

G1 and the struggle on Mac Mountain

The first of the android phones looms close, and what is there to show for it. We have an operating system with a lot of potential, open to developers ( sadly in Java ), and with ability to replace almost any application. And what does the HTC-Dream, er sorry, TMobile G1 have to say for itself?

  • Proprietary ports, no 3.5mm headphone jack
  • No A2DP for bluetooth ( Stereo bluetooth headset support )
  • No MS outlook/Desktop sync
  • 1 GB memory card ( note, the Sony Ericsson W900 avail 2005/2006 had a 2GB card )
  • Virtually no truly custom apps, in the sense that HTC could have taken advantage of replacing some primary apps with amazing stuff

The advantage is the freedom of platform. As a software developer ( who dislikes Java ) i really appreciate the ability to write daemons, and apps that could replace my contacts/sms apps. I keep mentioning the Java issue. My reason for this is as that i am currently an iPhone developer, and altho i dislike the proprietary platform, the performance is amazing. The reason is not the hardware, since they're about the same. Java is the killer. iPhone development happens primarily in C++ or Objective-C (yuck). Both of those are on hardware, low resource languages. When i saw the android demo of a bouncing ball at 40fps ( which he was boasting about ), i laughed. With a full 3D scene, some 3D physics ( including sphere/trimesh collisions ), and about 3000 triangles, we're getting 30fps on the iPhone. 40fps for a 2D sprite is disgusting. I'd have been ashamed, to even admit i was only getting 40fps. 

This all said, i'm still debating whether or not to get the G1, or if i should wait for Samsung, LG or Motorola to release their android models, and get an iPhone now? The G1 is only coming to my ( Netherlands ) shores in Q1 2009 ( along with Germany, Czech Repl, and Austria ), so it's a while to wait. Luckily US consumers get it this month ( 22 Oct ) and it's slated for launch in November in UK.

It's a really tough choice, because the iPhone is an amazing piece of hardware. Again i am very against proprietary formats, but the iPhone is really what they claim, and even though its closed, its the best phone around by a long shot.

Whatever happens, i'll have some interesting news on both iPhone and Android Games soon ;)


2008-10-12

Stackoverflow and the solutions we all seek

As a developer it can be _really_ frustrating looking for solutions to problems. Say you're working with a new library, and you know other people use it, but you have no clue how. This often applies when you're using C++ and get some hardcore C library, that would only make sense to people who have been coding in C in a basement somewhere for the last 10 years.

A common complaint that i have, and it seems i'm not alone, is that you can search for days and mostly get one of 3 things:

  1. nothing,
  2. a site with unanswered questions,
  3. or a site that asks you to sign up to view the answers.

Then i discovered stack overflow! It's a site that allows users to log in ( with any openID account if you have - blogger account is part of it ), and post a programming related question. Anyone can view this, whether you have an account or not. Now i hear what a lot of people will say, its all good to have a forum, but people will have to read it. Well, there are at least 2 people who work for the site that will look over the questions they can answer. But still, no 2 people can know everything right?

My trial of this site shows me that there is more than enough traffic to generate answers to questions. I've posted 3 questions so far, each one generating at least 3 answers within the first week, and getting over 50 user views. All of my questions have had pretty satisfactory answers, 2 of them telling me exactly ( including some code posts ), what i needed to know. The last one, my question was illdirected and badly phrased, and i still got a good answer to my question, even though it wasn't what i was looking for.

So if you're a developer, i really advise having a look, its a great site, and more knowledge never hurt anyone ( except a few organisations ).


Google Docs ftw!!!

It seems that google docs has an options to post from google docs to a given blog, including blogger!!! Since i really hate the blogger interface, and can never get a blog written through it, this is an official test to see if it works. Well done google for realising how much the blogger interface sucks

2008-10-08

#include

In the next few weeks i will be posting a series of blogs about development of applications on linux, 3D graphics, physics, networking and all of my discoveries as a developer. This should include some warnings, tips, tricks, and anything useful to developers who primarily use linux. This first post will focus on tools!

As a developer who has worked commercially in a Windows development environment, i have to admit, Visual Studio is good. Sadly ( although it would benefit Microsoft greatly ), VS is Windows specific. So what to do if you want to develop on a Linux OS? There are many environments out there, and in my opinion most of them suck. I want to be able to develop for anything, i like my graphics and physics based applications, but i don't want to be forced into writing a GUI. Sometimes i want to write a GUI, and something like GTK# really doesnt do it for me ( i much prefer QT ). I want code completion, my typing sucks. Although i've been coding for years, i'm still a bad typist. Makefiles are a pain, but if i want them, they must be accessible. At the same time i want to be able to just quickly create a project without having to worry about setting up makefiles and stuff like that. And Visual Studio solution support wouldn't hurt. And if anyone wants their IDE to be more like XCode, they've been working on a Mac too long and need a break.

My tests taught me this:

  • Monodevelop, which now supports C/C++, crashed randomly, and is too specific to certain tasks. I don't like GTK#, and it took me four hours to create a checkered board on a gui in monodevelop. The C# support and Visual Studio solution importing is nice, although i am not a fan of C#, but for C/C++, the IDE is disappointing
  • Anjuta is not fully featured. I tend to steer clear of GNOME based technologies ( excepting GIMP ), and although i gave this a try, it seems to be more geared to GNOME development, which makes sense. I want a general environment, which i feel Anjuta falls short of.
  • KDevelop has some big advantages. The project support appeals to me, and the fact that is was simple to set up some stuff is also a big plus. It is geared toward KDE development, again this makes sense, and tends to be more specific. It is makefile driven, but the built in automake tools can remove the effort of setting up a makefile. However, being makefile driven still creates it's own problems, and can limit development time in this environment. Productivity is my main goal, i don't want to spend time setting up stuff, i would rather be coding.
  • Eclipse is a big one. I will state here that i am not a fan of java or most things written in it. Speed matters to me, and i have never felt that a Java application or it's interface feels correct. Eclipse is no exception. It uses up way too much of my ram and feels like i have to fight it for the processor.
  • Netbeans is for me the same as Eclipse. Slow and chunky. Altho it would be my second choice. Its C++ features are not bad, and altho it has a lot of polish, it lacks some nice little things.
  • CodeBlocks is a cross platform ( Win/Lin/Mac ) C++ IDE. It is fast, feature packed and surprisingly visual studio compatible. It has a whole bunch of project templates, ranging from Ogre, openGL and irrlicht to QT4, GTK and wxWidgets. The reason i discovered Codeblocks was exactly this, i needed to make an Ogre project ( for a physics engine ), and this IDE was suggested. The latest version supports VS2005 and 2008 solution files, which is great for compatiblity. It supports ( minimally ) makefiles, which is good to know.

Being my choice, Codeblocks is what i will refer to for the rest of this series. You can get it from www.codeblocks.org and installation is pretty simple. Using openSUSE 11.0 linux, all i did was searched the Webpin software repo's and installed the latest version i could find. 

If anyone has any other suggestions for IDE's, please do let me know, i'm always looking for new software to play with!

Next Week i will hopefully cover some basics of 3D graphics in openGL

    Its about choice