Working
codes for free
Terra Gen
About
Terrain Gen
Terrain Data
Map
Texture
Terrain Texture
Generator
Screen
TerraGen Controlls
Code
Code
source
Project
General info.
Terra Gen still in development.
This is free sample and tutorial only not for comercial use.
MFC based Generator to generate and provide fast rendering module
of optimized terrain data actualy for 3D game engines.
Codes used of:
Bryan Turner documentation
Duchaineau et.al.
Boris Jatsenko -Proton2.
Raw
Format:
Engine using raw format data.
Actualy the original format contain header chunk but in our case-we
are using simle format.
The data defined as unsigned chat 8bit array with same xy
dimensions.
The most useful arrays is 512x512.
Each value in array difine for us only the height of terrain(y)
vs. of position in map[x][z].
Reading and also saving this format is prety simple and elegant.
bool ROAM::
LoadMap(const char *FileName, unsigned char *pHeightMap)
{
int x,z;
FILE *File = NULL;
if(!pHeightMap)return false;
if((File =fopen(FileName,"rb"))==NULL)return false;
fread(pHeightMap, 1, square(mxMapSize), File);
int Result = ferror(File);
fclose(File);
if (Result)return false;
// converting to 1D to 2D map
for( x = 0; x < mxAreaSize; x++ ){
for( z = 0; z < mxAreaSize; z++ ){
height_field[x][z] = (pHeightMap[x + mxAreaSize*z]);
}
}
return true;
}
bool ROAM::
SaveMap(const char *FileName, unsigned char *pHeightMap)
{
FILE *File = NULL;
if(!pHeightMap)return false;
if((File =fopen(FileName,"wb"))==NULL)return false;
fwrite(pHeightMap, 1, square(mxMapSize),File);
int Result = ferror(File);
fclose(File);
if (Result)return false;
return true;
}
Radar
General info.
This map helps to us understanding in real time were we
walking in the loaded world.
Actualy it is GrayScaled image that providing for us the height
values.
It can be loaded from primary TGA or generated also from raw.
Win->Dialog
General info.
In next version keyboard controlls will be changed.
By default main window have exclusive controll rights.
To pass controll to dialog press - D
To pass controll to window frame press - Pass
A - FWD
Z - BWD
Mouse left button - UP
Mouse right button - DOWN
Mouce movement controlling vew rotating- left right up and down
F - Terrain texturized
M - Map show
Num + LOD increase
Num - LOD decrease
W - solid mode + wire mode
R - wireframe rendering
Esc - ALT+F4
Classes
Class TGA files operation
class Tga
{
public:
GLubyte * cMap;
GLuint BPP, Width,Height;
// OpenGL GLenum Format;
// GLint Components;
// gl image
GLuint m_ColorTexture;
bool MakeGLtexture(GLuint &ColorTexture,bool makemipap=true);
Tga();//constructor
Tga(Tga&source);//copy constructor
bool CopyFromOther(Tga&source);//copy provider
~Tga();//destructor
void Destroy();//destroy provider
bool Load(const char *FileName);//loading tga
bool ConvertToGS();//converting to gray scaled image
bool ConvertToGS(unsigned char*data,bool inthismap=false);//converting to gray scaled image provider
bool SaveRaw(const char *FileName);//save as raw
bool SaveTGD(const char *FileName);//save as patchcomplect
};
Class ROAM
__mxAreaSize defined as 512
class ROAM
{
protected:
unsigned char hMin, hMax;
public: float Height;
float distance;
int ScaleXZ;
float Dx, Dy;
float TextureWrap;
int nfans;
int ntriangles;
unsigned char HM[512][512];
unsigned char *HMap;
char QTree[__mxAreaSize+1][__mxAreaSize+1];
char Roughness[__mxAreaSize+1][__mxAreaSize+1];
int Correction;
unsigned TotalVertex;
bool WireMode, SpMode, WorkWire, EnableFrustum;
float detailLevel;
Tga m_Image;
GLuint ColorTexture;//terrain texture
Tga m_Image0;
GLuint ColorTexture0;//for ARB_Multitexturing shadow or lightmap
Tga m_Image2;
GLuintColorTextureGS;//8bit radar image<
int mxAreaSize;
int mxHAreaSize;
ROAM();
~ROAM();
bool LoadMap(const char*, unsigned char*);//load raw
bool SaveMap(const char*, unsigned char*);//save raw
bool ConvertToMap(unsigned char*, unsigned char*);//convert RGB/A->GS ->raw
void InitVertex(void);
void set_location(int x, int y, int z );
void recalc_terrain( int cam_x, int cam_y, int cam_z );
void DrawMap(int xUC, int yUC, int g_xUC, int g_yUC,
float X0, float Y0,
cam camera);
void DrawMapTex1(int g_xUC, int g_yUC,cam camera);
bool FrustumWorking(int X, int Y, int Side);
void Init(int v, bool w, bool s, int sc, int ms, int mhs);
void CalculateRoughness(void);
void AddHError( int xmin, int zmin, int xmax, int zmax, float *pmax_error);
void QTreeSetup(int X, int Y, int Side, int cullcode);
void MakeMesh(int, int , int );
void RenderMesh(void);
void ShowBoxes (BBOX *bbox);//for debug using
void Emit(int, int);
void End(void);
void ZoomIn();
void ZoomOut();
};
Are placed in dowload area and will be updated from time to time
Will be continued!!!