Technology
 

Basic Program

From DarkGDK Programming Wiki

This page talks you through a very, very simple program. It is intended for beginners, and will explain how a DarkGDK program is laid out and how it works. This program moves a cube forwards. Fun!


Contents

[edit] The Program

#include "DarkGDK.h"

void DarkGDK ( void )
{
	dbSyncOn   ( );
	dbSyncRate ( 60 );

	dbMakeObjectCube ( 1, 1);
	
	dbPositionCamera ( 10, 10, -20 );

	while ( LoopGDK ( ) )
	{
		dbMoveObject( 1, 0.5 );

		dbSync ( );
	}

	dbDeleteObject ( 1 );

	return;
}



[edit] void DarkGDK ( void )

This is the start of the function which is run automatically when a GDK program starts. All the commands between the curly braces are run in order until a return statement is found.

[edit] dbSyncOn ( ) and dbSyncRate ( 60 )

Main articles: dbSyncOn and dbSyncRate
dbSyncOn tells windows that it is now in control of the monitor refresh. This means frame rates in your game will be more accurate. The dbSyncRate command tells the computer that it should try and refresh the monitor at around 60 frames per second.

[edit] dbMakeObjectCube ( 1, 1)

Main article: dbMakeObjectCube
I think what this command does is self explanatory, but the first number is an integer which allows you to control other aspects of this object. The second is the width of the cube.

[edit] dbPositionCamera ( 10, 10, -20 )

Main article: dbPositionCamera
This command positions the default camera in 3D space. The numbers are floating point values, and the first is X, second is Y and third is Z.

[edit] while ( LoopGDK ( ) )

This is the start of the GDK loop. All the commands within this are run 60 times a second until the program is exited. The commands after this only run just before the program is ended.

[edit] dbMoveObject( 1, 0.5 )

Main article: dbMoveObject
In DarkGDK every object has a "forwards" direction, and this command tells an object to move in this way. The first number tells the program which object it is about, and we set the cube as object 1 earlier. The second is a floating point value saying how much the move the object forward by.

[edit] dbSync ( )

Main article: dbSync
This is your program's most important function. It tells the screen to update its contents. This should really only occur once within your loop.

[edit] dbDeleteObject ( 1 )

This command will remove object 1 (in this case the box) from memory. If you wish to bring the box back, it must be created again!


P.S. - Whoever edited this part of the wiki and replaced the ORIGINAL (and probably a better explanation than mine) with "you sucks dicks asshole" is the asshole... please stop ruining the wiki, this information is very helpful to the DarkGDK community. Also, try some English courses, for the correct phrase would have been, "You suck dicks, asshole"

Thank you!

-DJRehab