CIS Logo SVC Logo

   Computing & Information Systems
   Department

 

Schoology Facebook        Search CIS Site      Tutorials

Software Design Using C++



Introduction to Dark GDK



Overview


Thus far in our programs, we have been developing what are known as "console applications." This fact should be obvious not only because our applications have been executing in a console window but also because we have been specifically creating our new projects as "Win32 Console Apps." Throughout our work, we will be creating console applications since their simple interfaces do not require us to be distracted from the main points of the given lesson topic. However, as you probably know (unless you have been isolated from technology or only live on a Linux command prompt), most commercially-available applications are programmed to execute within a Graphical User Interface (Windows Explorer, Macintosh Finder, X11, etc). Programming for such environments will require you to think quite differently from how you approach console applications.

Therefore, we will be looking at various ancillary examples through which you will be taught to work within a graphical environment. Later in the text, we will introduce Windows Forms as one example of this type of programming. However, this section is an introduction to the Dark GDK development platform for Microsoft Visual C++. This platform will provide us with a library of different functions which will allow us to create 2D and 3D programs with relative ease. In particular, this will afford us the opportunity to discuss those topics of interest which arise in programs of increased complexity such as games.



Downloading and Installing Dark GDK


In order to use the Dark GDK example code which we will see throughout these pages, you will first need to download and install the Dark GDK platform. The platform and its prerequisites can be found at http://gdk.thegamecreators.com/?f=downloads. On that page, you will also find a link to the installation page which is included here merely as a quick reference for installing Dark GDK and its prerequisites. Following their simple guide, you will be up and running in no time!

A First Example



In order to create a 2D or 3D Dark GDK Project, you will generally follow the steps that you have been using from the beginning of this text (found here). However, you will select a different project type, namely the Dark GDK - 2D Game or Dark GDK - 3D Game.

/*
 * Author: Br. Isidore Minerd
 *
 * Date: July 16, 2009
 *
 * Description:  This is merely a GDK version of the classic "HelloWorld" example
 */
#include "DarkGDK.h"

void DarkGDK()
{
	// Print at the current cursor location
	dbPrint("Hello, world!");
	// Wait for input from the keyboard
	dbWaitKey();
}


File NameDescription
HelloWorldSimple.cpp Source code for this example
HelloWorldSimple.gif Screen shot of this example in execution


Alright, let's pull this apart a little bit in order to discuss its constitutive parts. On the whole, this should not be too difficult to understand at first glance, although there is one thing missing, namely the main function! Programs made with Dark GDK have an entry point (for our purposes) with the void DarkGDK(void){ ... } function. From here, we can treat it like we treat main in our other applications. Also, you will note that you will also be required to include the definitions contained within "DarkGDK.h" for all programs using Dark GDK.



dbPrint("Hello, world");

Alright, this is our first Dark GDK function call, and thankfully, it is not a very complex one! With our console applications, output was performed from the upper left hand corner to the lower right. With each new line character we moved to the next line on the "grid". For our purposes, it is 80 characters wide and infinitely long (so long as the executing system can "scroll" the output on the screen. Pictorally, it could be represented like this:


A standard 2-Dimensional drawing plane, such as the one we will be drawing onto for our Dark GDK applications, has a similar number pattern, although this number is done for pixels. On a standard Cartesian plane, like you would have used for graphing functions in mathematics, the X-axis increases in value from left to right and the Y-axis increases from bottom to top. Now, just as with the console example, the X and Y values of the 2-Dimensional plane increase left-to-right and top-to-bottom respectively. The image below illustrates this by providing the coordinates for a rectangle which has dimensions of 150 x 50 and has an upper-left corner of (75,50):


After writing the string to the screen, the dbPrint function moves the current location on the screen down the appropriate height (i.e. the height of the text output). Therefore any drawing which will occur will begin from that point unless the current point is changed.

dbWaitKey();

This function merely waits for keyboard input from the user before executing the code any further. Therefore, when it executes, the code stops and does nothing until a key is pressed. The actual value of the key is not captured with this function (though there are others for doing this). In this function, after the key is pressed, the DarkGDK has no more code in it. As you should recall, functions which have no return value (i.e. have a return type of void), do not need an explicit return statement. Therefore, after a key is pressed, the code continues, only to find that the main execution function has ended and thus terminates the program.



A Few More Examples



Please note that there are various functions called within these code samples. While the code itself is documented to a degree to help you understand what these functions are, also be aware that there exists documentation with your Dark GDK install or you may search a third-party output of the Dark GDK documentation which is available here.
Another Hello World Example
File NameDescription
HelloWorld.cpp Source code for another example "Hello, World" application, showing a few other function calls related 2D text output, coloration, and rectangle output
HelloWorld.gif Screen shot of this example in execution.

Smiley Face Example
File NameDescription
Smiley.cpp Source code for a program which outputs a "Smiley" face using basic shape drawing commands.
Smiley.gif Screen shot of this example in execution.

UFO Image Load Example
File NameDescription
UFOImageLoad.cpp Source code for an example of loading images for use in basic sprites as well as loading music files for looped playing.
UFOImageLoad.zip ZIP file containing source code and resources for this example.
UFOImageLoad.jpg Screen shot of this example in execution.
Back to the main page for Software Design Using C++

Author: Br. David Carlson with contributions by Br. Isidore Minerd
Last updated: March 21, 2015
Disclaimer