Hi,
When I run the said command it crashes my application, with an error code of 6???
So I did a search and found one post! it suggested putting the executable one directory above the media, so I did, now it doesn't give me the error 6 jargon but instead locks up my machine.
Has anybody found a way around this, or is AT just another no-go-area for GDK?
Here is the entire code file that uses the advanced terrain commands.
#include "resource.h"
#include <DarkGDK.h>
#include "globstruct.h"
#include <windows.h>
#include "Globals.h"
//------ GLOBALS AND CONSTANTS ------//
OPENFILENAME ofn; // this is used for the open file dialog
char base_texture[MAX_PATH]; // these are used to store file names of the textures
char detail_texture[MAX_PATH];
char heightmap[MAX_PATH];
int terrain_size; // and this stores the terrain size
//------ PROTOTYPES ------//
BOOL CALLBACK NewTerrainProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); // the new terrain dialog callback procedure
//------ DEFINITIONS ------//
// this function initialises and displays the new terrain dialog
void ShowNewTerrainDlg( ) {
// firstly lets show the new dialog
int result = DialogBox( NULL, MAKEINTRESOURCE(IDD_NEW_TERRAIN_DLG), g_pGlob->hWnd,(DLGPROC)NewTerrainProc );
if( result == IDOK ) {
// ok we need to create the new terrain
if( g_terrain.ObjectID != 0 )
if( dbObjectExist( g_terrain.ObjectID ) )
dbDeleteObject( g_terrain.ObjectID );
// now build the new terrain
g_terrain.ObjectID = GetFreeObject( );
dbSetupTerrain( );
dbMakeObjectTerrain( g_terrain.ObjectID );
dbSetTerrainSplit( g_terrain.ObjectID, 8 );
dbSetTerrainHeightmap( g_terrain.ObjectID, heightmap );
dbSetTerrainTexture( g_terrain.ObjectID, LoadImage( base_texture ), LoadImage( detail_texture ) );
dbSetTerrainScale( g_terrain.ObjectID, 50 * terrain_size, 10.0, 50 * terrain_size );
dbSetTerrainLight( g_terrain.ObjectID, 1.0f, -0.25f, 0.0f, 1, 1, 0.78f, 0.5f ); // set the light
dbBuildTerrain( g_terrain.ObjectID );
// set the terrain properties
strcpy_s( (char*)&g_terrain.BaseTexture, MAX_PATH, (char*)&base_texture );
strcpy_s( (char*)&g_terrain.DetailTexture, MAX_PATH, (char*)&detail_texture );
strcpy_s( (char*)&g_terrain.Heightmap, MAX_PATH, (char*)&heightmap );
g_terrain.Size = terrain_size * 50;
}
}
// the callack procedure for the new terrain dialog
BOOL CALLBACK NewTerrainProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_INITDIALOG:
// set the default values
SetDlgItemText( hwndDlg, IDC_BASETEXTURE, "Textures\cmap.bmp" );
SetDlgItemText( hwndDlg, IDC_DETAILTEXTURE, "Textures\dmap.bmp" );
SetDlgItemText( hwndDlg, IDC_HEIGHTMAP, "Textures\hmap.bmp" );
SendMessage( GetDlgItem( hwndDlg, IDC_TERRAINSIZE ), CB_ADDSTRING, 0, (LPARAM)"Small" );
SendMessage( GetDlgItem( hwndDlg, IDC_TERRAINSIZE ), CB_ADDSTRING, 0, (LPARAM)"Medium" );
SendMessage( GetDlgItem( hwndDlg, IDC_TERRAINSIZE ), CB_ADDSTRING, 0, (LPARAM)"Large" );
SendMessage( GetDlgItem( hwndDlg, IDC_TERRAINSIZE ), CB_SELECTSTRING, -1, (LPARAM)"Medium" );
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK: // the ok button
GetDlgItemText( hwndDlg, IDC_BASETEXTURE, base_texture, MAX_PATH );
GetDlgItemText( hwndDlg, IDC_DETAILTEXTURE, detail_texture, MAX_PATH );
GetDlgItemText( hwndDlg, IDC_HEIGHTMAP, heightmap, MAX_PATH );
terrain_size = SendMessage( GetDlgItem( hwndDlg, IDC_TERRAINSIZE ), CB_GETCURSEL, 0, 0 ) + 1;
EndDialog(hwndDlg, wParam);
return true;
case IDCANCEL: // the cancel button
EndDialog(hwndDlg, wParam);
return true;
case IDC_BROWSE_BASETEXTURE: // browse for a base texture
ZeroMemory( &ofn, sizeof( ofn ));
ofn.lStructSize = sizeof( OPENFILENAME );
ofn.hwndOwner = hwndDlg;
ofn.lpstrFilter = "Image Files.*.bmp;*.tga;*.png;*.dds;*.jpg";
ofn.lpstrFile = (LPTSTR)&base_texture;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
if( GetOpenFileName(&ofn) )
SetDlgItemText( hwndDlg, IDC_BASETEXTURE, (LPTSTR)&base_texture );
break;
case IDC_BROWSE_DETAILTEXTURE: // browse for a detail texture
ZeroMemory( &ofn, sizeof( ofn ));
ofn.lStructSize = sizeof( OPENFILENAME );
ofn.hwndOwner = hwndDlg;
ofn.lpstrFilter = "Image Files.*.bmp;*.tga;*.png;*.dds;*.jpg";
ofn.lpstrFile = (LPTSTR)&detail_texture;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
if( GetOpenFileName(&ofn) )
SetDlgItemText( hwndDlg, IDC_DETAILTEXTURE, (LPTSTR)&detail_texture );
break;
case IDC_BROWSE_HEIGHTMAP: // browse for a heightmap
ZeroMemory( &ofn, sizeof( ofn ));
ofn.lStructSize = sizeof( OPENFILENAME );
ofn.hwndOwner = hwndDlg;
ofn.lpstrFilter = "Image Files.*.bmp;*.tga;*.png;*.dds;*.jpg";
ofn.lpstrFile = (LPTSTR)&heightmap;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
if( GetOpenFileName(&ofn) )
SetDlgItemText( hwndDlg, IDC_HEIGHTMAP, (LPTSTR)&heightmap );
break;
}
}
return false;
}
The
LoadImage function is my replacement dbLoadImage function that finds a free number for you, just to prevent any ambiguity.
Thanks in advance
The Sun is trying to kill me!