Starting SDL !!!

Comment

Its been quite sometime since I started to study SDL with my friend. I am going to summarise somethings about SDL as a beginner.

First let me tell the steps for configuring SDL with DevC++ IDE 4.9.9.2. After installing DevC++ IDE, download the SDL Library

Download the SDL development library for Mingw32
http://libsdl.org/release/SDL-devel-1.2.12-mingw32.tar.gz
(might be changed in the future)
SDL Library official site is www.libsdl.org

Place it in your C:\ Drive root.

You can also place it whereever you want to store, but here I am going to make further explanation assuming that we are extracting the downloaded file in C:\. If you are extracting at a different location make changes in the path as necessary in the below example

  • Extract the contents.
    It will create a folder called SDL-1.2.12.
    Rename the folder to 'SDL' for simplicity sake.
    Now extracted contents are in C:\SDL
  • To verify check if there are folders by name
    bin, build-scripts, lib, include etc.
    under the path C:\SDL
  • Now open the DevC++ IDE
    Go to Tools Compiler Options.
    • Under Compiler Tab
      Check the 'Add these commands to the linker command line' checkbox.
    • Then enter
      '-lmingw32 -lSDLmain -lSDL'
      in that textbox without the single quotes.
  • Next go to Directories Tab.
    • Under Libraries add the path C:\SDL\lib
    • Under C/C++ includes add the path 'C:\SDL\include\SDL'

Now you are all set to begin SDL !!

How to begin game programming ??

Comment
I remember I asked my father how games were made when I was in UKG after I got my ATARI 2600, and has been always trying to find out since then.

(Throughout my school life, I never owned a computer at home, only thing they taught in school was LOGO and very very limited amount of Basic. When I was in 9th or 10th standard I met this awesome thing called "Flash" which was Flash 5 then, and Flash CS4 now !)

This is something that I took years to find out. The first thing I started was to program with Flash. Soon I realized Flash's capabilities.I agree that you can make decent games with flash too. But still how do these people program real AAA titles like Half Life, Quake 3 etc ??

Then I came to world of turbo C, started ambitiously later found its slow and screen was flickering, then came Java with double buffering, I got a tutorial about tile based games and realized this is how games like Super Mario was made. Used it in Java, got some smooth scrolling, but could not make other things happen, too many bugs and I was not clear about many other tile concepts much.

That time my classmate, a super cool brainy guy started out with the same set of tutorials, and made a mixture of Contra, Mario (I had the sprites there !!) But finally the game after all those efforts was too slow. Then I learn t that people make use of something called hardware acceleration to create those super fast high graphics games. I learn t that
there are APIs to use the H/W acceleration and create games.

You can click links to learn more the terms, they all link to Wikipedia pages. Then I started to learn DirectX, the first step in becoming a real game programmer. Fortunately even though I am a diploma holder, I got job in a company to program CAD Applications, I learnt DirectX.NET there and realised it was hard to use it for CAD applications there, then came the world of OpenGL. I liked it mainly because of three things
  • Its a open industry based standard as opposed to DirectX which was Microsoft's.
  • John Carmack, my role model uses that to create Quake 3, Doom 3 etc.
  • Its really simple and powerful, and better than DirectX in many ways.
  • OpenGL code is very very portable.
Then came SDL, when I started to program games in ubuntu linux. I made a small tetris clone, playable but no scores etc. Remember I told I am lazy.

Now I like SDL, I am planning to learn and make some platformers using it, make is open source and make binaries for linux as well as windows. Lets see whether I am able to do it ???

Adding a printer in VB.NET

Comment
I took some time for me before I found out that API AddPrinter can be used to add printer whose driver is already installed. All I wanted to do was to add a Printer if its not present and the driver was built-in Windows XP itself.

First I finished adding the printer in VC++ using MFC Application then I wanted to add it using VB.NET either using Declare Function or DllImport by wrapping it in a dll. Then i had to google for a long time when i last arrived at a code that really worked !!!

Module Printer_Module
'declare the API in VB
Private Declare Function AddPrinter Lib "winspool.drv" Alias "AddPrinterW" _
(ByVal pName As IntPtr, ByVal Level As Int32, _
<MarshalAs(UnmanagedType.LPStruct)> ByVal pPrinter As PRINTER_INFO_2) As Int32

'http://www.vbforums.com/archive/index.php/t-263437.html
'still dont know why PRINTER_INFO_2 is Class instead of a Structure

<StructLayout(LayoutKind.Sequential)> _
Public Class PRINTER_INFO_2
<MarshalAs(UnmanagedType.LPTStr)> Public pServerName As String
<MarshalAs(UnmanagedType.LPTStr)> Public pPrinterName As String
<MarshalAs(UnmanagedType.LPTStr)> Public pShareName As String
<MarshalAs(UnmanagedType.LPTStr)> Public pPortName As String
<MarshalAs(UnmanagedType.LPTStr)> Public pDriverName As String
<MarshalAs(UnmanagedType.LPTStr)> Public pComment As String
Public pDevMode As IntPtr
<MarshalAs(UnmanagedType.LPTStr)> Public pLocation As String
<MarshalAs(UnmanagedType.LPTStr)> Public pSepFile As String
<MarshalAs(UnmanagedType.LPTStr)> Public pPrintProcessor As String
<MarshalAs(UnmanagedType.LPTStr)> Public pDatatype As String
<MarshalAs(UnmanagedType.LPTStr)> Public pParameters As String
Public pSecurityDescriptor As IntPtr
Public Attributes As Integer
Public Priority As Integer
Public DefaultPriority As Integer
Public StartTime As Integer
Public UntilTime As Integer
End Class

Function AddMyPrinter() As Boolean

Dim PI2 As New PRINTER_INFO_2()
'only printer name, driver name, port name and print processor need to be filled
With PI2
.pServerName = String.Empty
.pPrinterName = "Apple Color LW 12/660 PS"
.pShareName = String.Empty
.pPortName = "FILE:"
.pDriverName = "Apple Color LW 12/660 PS"
.pComment = String.Empty
.pLocation = String.Empty
.pDevMode = 0
.pSepFile = String.Empty
.pPrintProcessor = "WinPrint"
.pDatatype = String.Empty
.pParameters = String.Empty
.pSecurityDescriptor = 0
.Attributes = 0
.Priority = 0
.DefaultPriority = 0
.StartTime = 0
.UntilTime = 0
End With

Dim x As Integer = AddPrinter(IntPtr.Zero, 2, PI2)
If x = 0 Then
MsgBox("Failed !!!")
MsgBox(Err.LastDllError)
End
End If
Return True
End Function

End Module