I decided to start a new project for what might be a game (i get bored easy) and this is what i've got so far.
// AshTek
// GDK Includes
#include "DarkGDK.h"
// MY Includes
#include "Main.h"
// LUA Includes
#include "lua_plugin.h"
#pragma comment ( lib, "Barnski'sLuaPlugin_debug.lib" )
// Dark Shader includes
#include "ShaderData.h"
#pragma comment ( lib, "shaderdata.lib" )
// the main entry point for the application is this function
void DarkGDK(void)
{
// set up initial variables
// this MUST be at the top of the DarkGDK() function
Set_Initial_Variables();
// load main app settings
Load_App_Settings();
dbShaderDataStart();
MakeCube();
// now we come to our main loop, we call LoopGDK so some internal
// work can be carried out by the GDK
while (LoopGDK())
{
SpinCube();
dbSyncMask(0x001);
// update screen
dbSync();
// if the error report function sez theres an error, better to stop and report it rather than
// run with undesired effects.
if (true == Error_Report.bError) return;
}
// and now everything is ready to return back to Windows
return;
}
void MakeCube(void)
{
dbMakeObjectCube(1,50);
//dbLoadEffect("test.fx",1,1);
//dbSetObjectEffect(1,1);
dbSetEffectOn(1,"test.fx",1);
}
void SpinCube(void)
{
dbYRotateObject(1,dbWrapValue(dbObjectAngleY(1))+0.2);
}
// set up all initial variables and constructors for structures .ect
void Set_Initial_Variables(void)
{
Error_Report.bError = false;
}
// function to find free gdk numbers
int Free_Number(int iType)
{
// set up intial increment variable
int iInc = 1;
// begin the loop
do
{
// if type is 0 (zero), then check to see if there is a free IMAGE number
if (0 == iType)
{
if (0 == dbImageExist(iInc)) return iInc;
}
// if type is 1 (one), then check to see if there is a free FILE number
if (1 == iType)
{
if (0 == dbFileOpen(iInc)) return iInc;
}
// increment the variable so we can check again
iInc++;
}
// if after searching for a free number nothing is found, then exit once the loop reaches the maximum
// search range - this prevents an infinite loop - i think.
while (iInc <= iMaxFreeNumberSearch);
// if the loop check fails to find a free number, then we have to return a default value of 0 (zero)
// and tell the user that we failed.
return 0;
}
// error reporting function
void Report_Error(char* cError, int iType)
{
// check to see if the error file exists, if so, delete it
int iFileExist = dbFileExist("crash.txt");
if (1 == iFileExist) dbDeleteFile("crash.txt");
// make the crash file
int iCrashFile = Free_Number(1);
dbOpenToWrite(iCrashFile, "crash.txt");
// write the error
dbWriteString(iCrashFile, cError);
// write additional error info
if (0 == iType)
{
dbWriteString(iCrashFile, "File does not exist!");
}
// close the file when we're finished
dbCloseFile(iCrashFile);
// let the main app loop know we have a problem so the program can exit
// this is because sometimes the error is defaulted by the gdk so the program still
// runs but with crappy results, this could trick us so its best to just exit and say what stuffed up
Error_Report.bError = true;
}
// Set up the general application settings
void Load_App_Settings(void)
{
// get the screen resolution settings from the config file and set it
int iScreenResX = LUA_Get_Int("config.cfg", "Screen_Res_X");
int iScreenResY = LUA_Get_Int("config.cfg", "Screen_Res_Y");
int iScreenDepth = LUA_Get_Int("config.cfg", "Screen_Depth");
dbSetDisplayMode(iScreenResX, iScreenResY, iScreenDepth);
// position the app window at the top left
dbSetWindowPosition(0, 0);
// set window title
dbSetWindowTitle("AshTek - 0.0.1b");
// background on
dbBackdropOn();
// turn off autocam
dbAutoCamOn();
// turn on manual screen syncing
dbSyncOn();
dbSyncRate(0); // <--- set this to 60 in final, leave at 0 for developing
// randomize the timer so we get more random results when using it???
dbRandomize(dbTimer());
}
int LUA_Get_Int(char* cFile, char* cField)
{
// make the LUA interface
lua::make();
// check to see if the config file exists, otherwise exit and report error.
int iErrorCheck = dbFileExist(cFile);
if (1 == iErrorCheck)
{
// load the file
lua::load_file(cFile);
}
else
{
// report the error
//std::string sReport = " - File does not existo!";
Report_Error(cFile, 0);
return 0;
}
// get the value from the file variable
int iReturn = lua::get_int(cField);
// close the LUA interface
lua::terminate_lua();
// return the file variable value
return iReturn;
}
When I run it, the cube doesn't show. But if i remark the dbSetEffectOn function the cube shows up. I've got the textures and .fx file in the right dir, can you see what i've done wrong?
ps. ignore my noob coding