Jump to content
  • Advertisement
Sign in to follow this  

Texture problem

This topic is 4137 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I am having some trouble with a texture that I am creating
int size = 512;

// handle libnoise initialization
perlinNoiseMapBuilder.EnableSeamless( true );
perlinNoiseMapBuilder.SetSourceModule( perlinModule );
perlinNoiseMapBuilder.SetDestNoiseMap( perlinNoiseMap );
perlinNoiseMapBuilder.SetDestSize( size, size );
perlinNoiseMapBuilder.SetBounds( 2.0, 6.0, 1.0, 5.0 );

perlinRenderImage.SetSourceNoiseMap( perlinNoiseMap );
perlinRenderImage.SetDestImage( perlinImage );
// create texture to use as surface normal map
DXRESULT( D3DXCreateTexture( device, size, size, 0, D3DUSAGE_DYNAMIC, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &mSurfaceNoiseMap ) );

// get surface memory from texture
Surface pSurface;
mSurfaceNoiseMap->GetSurfaceLevel( 0, &pSurface );

// lock memory for writing
D3DLOCKED_RECT rect = { 0 };
pSurface->LockRect( &rect, NULL, NULL );

// get start of memory
DWORD* imageData = ( DWORD* ) rect.pBits;

// write random noise to the surface
for ( UINT i = 0; i < pSurface->Height; ++i )
	for ( UINT j = 0; j < pSurface->Width; ++j )
		int index = i * rect.Pitch / 4 + j;

		noise::utils::Color col = perlinImage.GetValue( i, j );
		imageData[ index ] = D3DCOLOR_XRGB( col.red, col.green, col.blue );

// unlock memory

// write surface to file 
D3DXSaveSurfaceToFile( "Surface.bmp", D3DXIFF_BMP, pSurface, NULL, NULL );

// release memory
RELEASE( pSurface );

Now this is what Surface.bmp looks like: So the surface contains Perlin noise, but when rendered with a simple pixel shader that looks up the color based on position, this is how it looks like: So obviously something goes wrong some where with the texture. What can it be?

Share this post

Link to post
Share on other sites
The bitmap image you posted (which is beautiful, by the way) serves as strong evidence that your Perlin noise algorithm and bitmap exporter are working just fine.

Judging from the results, the texture's lower mip-levels aren't being initialised. When you manually create a texture and fill in its base surface level (as you are), you need to tell Direct3D to create the mip-maps manually, once you're done. A single call to IDirect3DBaseTexture9::GenerateMipSubLevels at the end of the function would be a step in the right direction.


Share this post

Link to post
Share on other sites
Hey thanks for the answer. I just came to the same conclusion after plowing through the docs [smile]. After specifying D3DUSAGE_AUTOGENMIPMAP at creation of the texture and calling GenerateMipSubLevels() afterwards it works out.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!