Thursday, August 20, 2009

Creating Win32 application with Visual C++ Express Edition

I am a C/C++ programmer. C++ programming language is my favourite programming language. There are many programming IDEs (Integrated Development Environment) for C++ programmers such as Microsoft Visual C++, Dev C++, Code::Block C++ IDE, Eclip for C++ development, etc.

Among them, probably the most popular C++ IDE is Microsoft’s Visual C++. Although we cannot get Microsoft Visual C++ Professional Edition for free, we can freely download Visual C++ Express Edition from Microsoft web site. Visual C++ Express Edition is created for beginners, students and hobbyists. However, that Microsoft’s Visual C++ Express Edition is quite enough for OpenGL or DirectX programming and even for simple game projects. The current version of Visual C++ Express Edition is 2008.

The bad thing about Visual C++ Express Edition is that it does not have libraries and headers to create native Win32 applications. Game programs that are based on OpenGL or Microsoft’s DirectX API should be created in pure Win32 style. Win32 project is sufficient for games and real-time graphic rendering programs. We don’t need to use dot NET or MFC (Microsoft Foundation Class) libraries for game and graphic programming.

To create Win32 application with Microsoft Visual C++ Express Edition, we need to download and install Microsoft’s Platform SDK (Software Development Kit) or Windows SDK. For those who are using Windows Vista, I think they should use Windows SDK which is the latest SDK for Win32 creation. After we have downloaded Platform SDK or Windows SDK, all we need to do is to connect their libraries and headers with Visual C++ Express IDE.

To connect Platform SDK or Windows SDK with Visual C++ Express Edition, open the Tools menu and then select Options. You will see Options dialog box. From the left pane, choose VC++ Directories under Projects and Solutions. We need to add the exact path of the installed folder for Platform SDK or Windows SDK for Include and Libraries files. (See the following picture).

Remember that we need to add the path for the Platform SDK for Windows SDK for both Include Files and Library Files. We can only create Win32 applications with Visual C++ Express Edition only after we have correctly connected the Windows SDK to it.

There is one last thing to do before we can create Win32 applications with Visual C++ Express Edition even after we have connected Platform SDK or Windows SDK to it. We need to edit the small file called corewin_express.vsprops under the installed folder of Visual C++ Express. You can open it with Notepad or any other text editing program. You can see the following line in that file - AdditionalDependencies="kernel32.lib". Replace that line with the following line and save the file. AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib". This is needed to add additional Win32 libraries to Visual C++ Express Edition. Otherwise, we might get error in runtime at some points.

After we have connected Platform SDK or Windows SDK with Visual C++ Express and we have edited the corewin_express.vsprops file, we can start to create Win32 graphic applications or games with OpenGL, DirectX or SDL (Simple Direct Media Layer) APIs.

Let’s rock with ATI Mobility graphics

Some of the laptops in current market have very nice graphic processors. Unlike the previous days, we can now play games while we are moving (mobile gaming). There are even some gaming laptops that have very good processors (CPUs), graphic processing units (GPUs) and big LCD screens. Even for some cheap laptops in current market, they are acceptable to play most of the games with medium level graphic details.

Intel's latest graphic media accelerators (GMA) series are enough for the business purposes, desktop publishing (DTP), Internet browsing, Flash-like 2D programming and web page creations. Those Intel's GMAs also use little power and produce less heat than advanced graphic processing units. Some latest series such as GMA 4500MHD are even suitable for HD movie playback. However, the bad thing about them is that they cannot handle graphic intensive tasks and they are bad for games.
For the graphic intensive applications such as AutoCAD, PhotoShop, 3D Studio Max and Maya or games, only two graphic processing unit manufacturers are dominating current market. As most of us know, they are Nvidia and ATI (AMD). Nvidia's Geforce series graphic processors and ATI's Radeon series graphic processors are defined as the top level GPUs among all graphic processors in digital world.

We can buy laptops that come with Geforce or Radeon graphic processors in current market. Although the graphic processors in those laptops are Geforce or Radeon, they are different from their desktop editions. The graphic processing units that come with laptops are mobile version of their desktop families. Basically, mobile graphic processors cannot work as much as their related desktop editions. Mobile versions of those graphic processors are well considered for power usage, heat dissipation and size of the module. Anyway, if we want to play games or doing some graphic rendering tasks, we should consider only Nvidia's Geforce or ATI's Radeon.
Only Geforce 8 and above or ATI RadeonHD series can fully support Microsoft's DirectX 10 and OpenGL 2.0 APIs at hardware level. We should buy at least Geforce 8 or ATI Radeon HD 2000 series if we think to use for few more years in the future.

The most important thing for those advanced graphic processors is the “device drivers” for them. We should use the latest and updated graphic drivers for those GPUs to get maximum performance. We can go to Nvidia or ATI's web site and download the appropriate graphic drivers for our gaphic processors in our laptops.

However, there might be one problem with mobile graphic processors of our laptops especially for ATI Mobility Radeon series. We can search for the latest drivers for most of the ATI's desktop edition GPUs on ATI/AMD web site but it is very difficult to get correct driver for the relevant mobile version of ATI graphic chips. ATI normally does not want to support for its Mobility Radeon processors on its web site and laptop users need to go to laptop manufacturers' web site to get the drivers for their mobile version ATI graphic chips. Another problem for laptop gamers is that most of the laptop manufacturers do not update their graphic drivers very often. Some even rarely give a new drivers for them and laptop users need to use the original driver that comes with the laptops. It is unacceptable for mobile games like me. We need the latest drivers for newer games to play on our laptops.
If you ask me a question about if we can use the desktop graphic drivers from ATI's web site for our Mobility Radeon series, I have to say “NO”. We cannot use the drivers for desktop GPU for our mobility graphic processors. For example, ATI Radeon HD 3450 graphic processor is different from ATI Mobility Radeon HD 3450 and we cannot use driver made for HD 3450 for Mobility 3450. The installer will not even detect your mobile version graphic processor while installing. That is so annoying and of course a problem for mobile gamers and multimedia creators.

DriverHeaven groups tried to solve that problems for ATI Mobility Radeon graphic chip users. They created Mobility Modder program. A small very nice program that can transform the desktop graphic drivers from ATI web site to mobile versions so that we can use them for Mobility Radeon series graphic processors. That small program is a totally free version. We can easily download and install it into our PC for free.
If we want to use the latest graphic drivers for desktop graphic processors from ATI web site for mobile version graphic processors, we first need to download the latest graphic drivers from ATI web site. We might get the single executable (EXE) file to setup the driver automatically. Extract all the files and setup program into one folder from that EXE file. Don't run the installer or cancel the installer even if starts automatically. We cannot use that drivers for now.
After we have installed Mobility Modder program into our machines, all we have to do it run the program and then point to the folder where you put the driver installation files. Then, you just click on the “modify” button and the modder program will modify your desktop drivers for mobile graphic chips. After waiting for a while, you can now use that graphic drivers for Mobility Radeon chips. The usage of that Mobility Modder program is very simple. We can download the program from the following link.

http://www.driverheaven.net/modtool.php

For the mobile gamers and those who are using laptops with good graphic processors, coming out of the Mobility Modder is a good news for them.

Wednesday, August 19, 2009

Mac OS X 10.5.7 on my laptop...

I have successfully installed the latest Mac OS X (Leopard) onto my MSI EX 400 laptop. For me, I had to spend many days for various testing to get final working Mac OS X onto my laptop.
Actually, Mac OS X is not meant to be installed on PC. It is only designed for Apple computers but the good thing for that Mac OS X is that it can be installed on Intel processor based computers. However, the hardware architecture and design of the Apple computers are different from Intel based PCs. Apple computers even do not use BIOS (Basic Input/Output System) like PCs. They use different method and way to load the operating system.
Apple uses Extensible Firmware Interface (EFI) as a boot loader. It is different from BIOS of our Windows PC. Therefore, we need special boot loader that can act as an emulator between our BIOS and Mac OS X operating system so that we can boot Mac OS X on our computers and Mac OS X will think that as it is running on Apple hardware.
The projects that make Mac OS X to be able to run on PC are known as OSX86 projects. There are some amounts of OSX86 projects at outside. The following is a list of the names of the some popular OSX86 projects. Those “hacked” Mac OS X to install onto PCs are also called “Hackintosh”s.
Kalyway
iAtok
IPC
iDeneb
The latest version of Mac OS X (Leopard) that can be installed onto PC is 10.5.7. We should use at least 10.5.5 version on our PC. Mac OS X 10.4 is called Tiger.
Although the above Hackintosh projects can work with PCs, there are so many issues for potential problems and hardware compatibilities with various PC hardware.
My laptop does not work with most of the Hackintosh distributions. For my point of view, Intel based chipsets and most of the Nvidia/Intel graphic cards might properly with Mac OS X. Because my laptop has SIS chipset for motherboard, I got problems in installing it onto my laptop.
One thing to note is that even if your hard disk is a SATA hard disk in your PC. You should change your BIOS setting to IDE mode for SATA configuration. Also, the BIOS setting should be AHCI mode if you have option to change in BIOS. Otherwise, you might get problems in booting the boot loader.
I downloaded and tried many editions of Hackintosh for my laptop. Most of them could not even boot or some kept rebooting while loading the installer. The only distribution that can work with my laptop is iDeneb 1.3 (Mac OS X 10.5.5). For my point of view, that iDeneb distribution is the most compatible one for most of the PC hardware.
Don’t worry if you want the latest 10.5.6 or 10.5.7 version of Mac OS X. We can install the iDeneb upgrade kit for 10.5.6 and 10.5.7. Ok, I will share my experience about installing iDeneb onto my laptop to get the Mac OS X 10.5.7 (Leopard) working on my laptop.
I downloaded iDeneb v1.3 (OSX 10.5.5) from Internet. By the way, please note that I even cannot boot with iDeneb v1.4 (OSX 10.5.6) on my laptop. Therefore, we can’t assume that the new version will likely to work on our PC. It depends on the boot loader, preintalled Kext (Kernel extensions) or drivers and the pre settings of the boot loader and Kernel.
First, I installed iDeneb v1.3 onto my latptop. We need to prepare our hard disk before we can install Mac OS X onto it. (I will post separate article about how to prepare our hard disk for Mac OS X).
I can install that iDeneb v1.3 onto my MSI EX 400 laptop with its installer. However, it can’t detect my ATI graphic card (Radeon HD 3450) and my wireless network adaptor of my laptop. Therefore, I can only run with 1024x768 resolution with no hardware acceleration. After I had installed iDenebv1.3 which is Mac OS X 10.5.5, I downloaded the iDeneb upgrade kit for 10.5.6 and 10.5.7. I don’t want to recommend to upgrade to 10.5.7 directly from 10.5.5. It might crash your operating system and you might need to reinstall the iDeneb v1.3 from start.
Therefore, you should first install iDeneb v1.3 and then upgrade with iDeneb 10.5.6 upgrade kit and then upgrade to 10.5.7 with iDeneb 10.5.7 upgrade kit. Please do not use upgrade kits from other distributions or using Mac OS X built-in software upgrade. For your safety, you should remove some kext (drivers) for Intel CPU power management functions. (I will also post about it separately).
After upgrading to 10.5.7, my laptop is working well but I still cannot find the driver for my Mobility Radeon HD 3450 graphic card. No one has created the driver for that one. ATI Radeon HD 2400/2600/2900 and Radeon HD 3650/3700/3800 series might work with Mac OS X. Some of the drivers can be selected while installing Mac OS X with installer or you can download and install the drivers separately after installing. Most of the Nvidia Geforce graphic cards and Intel GMA 950/X3100 should also work if you have proper drivers installed.
In Mac OS X, most people called CI/QE for hardware accelerated graphic performances. CI means Core Image. If your graphic is supported by Mac OS X with correct drivers, you can see “Core Image = Hardware Accelerated” in system configuration utility. QE means Quartz Extreme which can be though as special functionality of OpenGL hardware acceleration.
Installing Mac OS X onto PC and using it on PC is quite interesting. You can install some SDKs onto it and develop Mac OSX applications or even iPhone games on them. To develop iPhone games, you have to install iPhone SDK. The latest iPhone SDK needs OS X 10.5.7 to install it. Mac OS X uses XCode as primary development IDE and tool. The primary programming language is Objective-C.

I am now using iDeneb Mac OS X 10.5.7 and Windows Vista on my laptop as dual boot.

Lights in OpenGL

When we are preparing to create a virtual 3D world using any graphic rendering API such as OpenGL or DirectX, the role of the lights in that virtual environment need to be thought very carefully. It is very clear that only to determine the 3D objects, their positions, colors and textures is not enough to get the realistic 3D environment. In this article, I want to talk about some ideas and concepts of lights in OpenGL graphic API (application programming interface).

When we consider the lights in virtual 3D world, we will consider about the light that hits and affects the objects in 3D scene. We do not think only for the light itself. We have to think how it will “affect” the objects in 3D world.

The first light we have to think in virtual 3D world is ambient light. Ambient light can come to the object from anywhere and any place. Therefore, we can't determine the exact position and direction of the light. It is also impossible to determine where and in which direction the ambient light will hit the object. The ambient light is also from the surrounding objects in environment. When the ambient light hit the object, it spreads out to all directions equally. An example of the ambient light is light in normal room.

Another light in OpenGL is diffuse light. Diffuse light has particular direction but when it hits the object, it spreads out to all directions. The light itself has specific direction. However, it will spread out to all directions equally when it hits the 3D object. Therefore, the strength of the light intensity for the viewer will not change according to the position of the viewer (eye). The exact position where the light will hit on the surface of the object depends on the position of the light but the feeling for the hitting of light on that position of the surface of the object is the same from wherever the eye position is. It will not change according to the eye point's position.

Specular light is the light that reflects form the object after a light has hit it. In real world substance such as steel and metal have high specular component. Some objects such as cloth, wool have little specular component or specular properties. Specular light depends on both the direction of the light and the specularity of the object. The feeling of the viewer upon the specular light also depends on the position of the eye. The reason is that it depends on the direction and position of the light.

The final type of light in OpenGL is emissive light. As the name implies, the light will be emitted form the objects. The object will have emissive color value in its properties and it will determine the color and intensity of the emissive light from it. One thing to note is that the emissive light from an object will not affect the environment and other objects in 3D world. It is the light that lit up only the object itself.

To determine the overall effect of lights for an object in virtual 3D world, we have to consider all the properties of the above lights for every object plus the object's color values and normal vectors.
OpenGL can supports up to eight light sources in one 3D scene. When the lights are created in OpenGL, we have to consider the their positions, directions (if they have) and the colors of the light sources. We also need to consider the specularity properties of the object, the color of the surface of that object and how the object might react the lights that hit upon it.
Without considering all of the above faces, we will not get the complete and realistic virtual 3D world with lights effects.

Transformations in OpenGL

In OpenGL or similar 3D graphic API (Application Programming Interface), we have to make transformations. The three main components of the transformation that used in 3D rendering are “Translation” (moving from one position to another), “Rotation” and “Scaling” (changing the size). Transformation means applying these three things to 3D models, environment or camera in 3D world.

In OpenGL, the transformations can be categorized into three forms. They are Modeling Transformation, Viewing Transformation and Projection Transformation. To implement these transformations in OpenGL with any programming language, we can use matrices or Quaternions. Normally, OpenGL graphic API only supports matrices. However, calculating in Quaternions is more efficient than using matrices in real implementations.

To understand the transformations in OpenGL, we can imagine and compare with taking a photo in real world.
Imagine what we will do when we are about to take a photo of an object in real world. The first thing we might do is the positioning of the object. We have to place the object that we want to take a photo of it in environment. We have to think about where to place that object (translation), in which orientation (rotate) and what is the size of that object (scale). Based on these faces, we have to decide how we want the photo of that object. In OpenGL, "this is Modeling Transformation”. We are considering about the object (3D model) to render it.
Some of the functions in OpenGL for transformation are glTranslate, glRotate and glScale.

After we have positioned and determined for the object that we want to take a photo, we have to think about our camera. Of course....! We still need to think about the camera. We also need to think about transformations for our camera. We have to place the camera at proper position (or probably the cameraman) and then determine the orientation of the camera. (Camera should be upside down or 90 degree rotated..?). In OpenGL, we called that case as “Viewing Transformation”. The most widely used function for implementing the viewing transformation in OpengL is gluLookAt( ). It has three sets of coordinate values as show below. By setting these three coordinate values for that function, we can define the correct the transformation to our camera.
gluLookAt ( x, y, z, x, y, z, x, y, z)
The first coordinate values (blue) are for the position of the camera or eye coordinates. The second (red) coordinate values are the position that the camera will be looking at (look at). The last three coordinate values are for the camera's “up vector”. It defines the alignment of the camera according to the one of the X, Y, Z axis. For example, gluLookAt (2,3,5, 0, 0, 0, 0, 1, 0) means that our camera is at position (2,3,5) in 3D world. The camera will be looking at the original (0,0,0) and the orientation of the camera is along Y axis (0,1,0). That means that the “up vector” of the camera is in same direction of positive Y axis.

Another transformation in OpenGL is “Projection Transformation”. Projection transformation has two sub categories, perspective projection and orthogonal projection.
Perspective projection is displaying (or rendering) as in the real world. The nearer objects to the viewers will be large and the far objects will be small according to the distance from viewer (or camera). Orthogonal projection is useful for engineering drawing. It has no perspective and all the object in rendered scene will be the same size regardless of the distance from viewer. Therefore, they can be used in blue-print drawing in engineering tasks.
One special thing we need to think in perspective projection is “frustum”. If you don't know about what is the frustum, see the figure to understand about it. Only objects inside that frustum can be seen by viewer in OpenGL rendering API. In other way, only objects (models) inside that frustum will be rendered by OpenGL. There are some components in frustum. Near and far planes are easy to understand. Fovy is an angle of viewing. I hope they can be understood by seeing the picture

If we compare the projection transformation with taking photo at outside, it is defining and setting of the lens of the camera. We can define how much distance the camera's lens will capture and the setting of focus of the lens.

The last transformation we also need to mention in OpenGL is “viewport transformation”. Imagine that after we have taken a photo with camera, we have to print out the photo to photo paper from film. We can define the size and shape ratio of the photo just before it can be transferred to the photo paper from film. This is also called “aspect ratio”. The real photo on the photo paper is the “viewport” of our image. We can also define the viewport in OpenGL rendering (see the figure). Therefore, viewport transformation is defining the aspect ratio and how we can see our rendered 3D scene on the screen.


OK..! This article is the discussion of the basic ideas of transformation in OpenGL. I hope this article is useful for the beginners and junior students in digital media field. I also believe that the ideas and basic concepts in this article is also useful for any other graphic APIs.