• Advertisement
Sign in to follow this  
  • entries
    6
  • comments
    6
  • views
    4802

Ah the fun of generating textures

Sign in to follow this  

233 views

Well, I've been spending the last few months recoding my base code as I had avoided testing return codes and such things and wanted to make the code as multi useable as possible.

A brief breakdown of what I have so far is as follows:

DXBase - Handles the basic requirements of directx.
DXFont - Handles font operations
DXSprite - Use for the 2D element of the graphical interface
DXCamera - Handles the view of the application
DXPrimitive - Handles the drawing of basic objects
DXRay - Handles ray tracing facilities
DXTerrain - Handles anything to do with a terrain

Obviously they are open towards improvement as I learn more in this area. The idea is at some point this base code will become the backbone of any application I choose to create once I've got these basics down pat.

The latest success is the ability to colorise the terrain texture file based on height of the point in question. Its not perfect but is something to work on. Just needs some fine tuning and the picking of more appropriate colors or a better range of heights to test against.

Well for those that are interested here is the current texture generation code that is used in my sample code.


bool DXTerrain::GenerateTexture(void)
{
int TexWidth = m_VertsPerRow;
int TexDepth = m_VertsPerCol;

m_texture = new Texture(m_device,TexWidth,TexDepth,0,Usage::AutoGenerateMipMap,Format::X8R8G8B8,Pool::Managed);
SurfaceDescription sfcd = m_texture->GetLevelDescription(0);
if ( sfcd.Format != Format::X8R8G8B8 ) return false;
int* ImageData = (int*)m_texture->LockRectangle(0,LockFlags::None)->InternalData.ToPointer();
int m_rangeHeight = (int)(m_maxHeight / 5.0f);
Int32 m_Ranges __gc[] = new Int32[5];
for (int i=0; i < 5; i++)
{
m_Ranges = m_minHeight + (m_rangeHeight * i);
}
Random* r = new Random();
for (int i = 0; i < TexDepth; i++)
{
for (int j = 0; j < TexWidth; j++)
{
int c;
int index = (j * m_VertsPerCol + i);
float height = (m_heights[index]);

if (height < 0) c = Color::Aqua.ToArgb();
else if (height < m_Ranges[0]) c = Color::Yellow.ToArgb();
else if (height < m_Ranges[1]) c = Color::Green.ToArgb();
else if (height < m_Ranges[2]) c = Color::DarkGreen.ToArgb();
else if (height < m_Ranges[3]) c = Color::Brown.ToArgb();
else if (height < m_Ranges[4]) c = Color::SlateGray.ToArgb();
else c = Color::Snow.ToArgb();

ImageData[index] = c;
}
}
m_texture->AutoGenerateFilterType = TextureFilter::Anisotropic;
m_texture->GenerateMipSubLevels();
m_texture->UnlockRectangle(0);
return true;
}




Here's the current screenshot of a small map. As you can see its not great but it shows promise.

Sign in to follow this  


3 Comments


Recommended Comments

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement