Sign in to follow this  
Spinewire

Drawing Random Pixels to a Surface **SOLVED**

Recommended Posts

Hi everyone, I'm trying to create a LPDIRECT3DSURFACE9 with a variable number of scattered pixels in a particular random number range. The idea is that the surface would just be a means of moving all of these pixels uniformly, and would be transparent except for where the pixels have been blitted. (This is so I could have several of these 'noise' layers on top of eachother, moving independently.) Once I have the pixels on this surface I never want to change or move any of them individually, I just want to be able to move them as a group. This is my method for making the 'noise' surface with the random pixels, which I then blit onto my backbuffer (another LPDIRECT3DSURFACE9) with StretchRect. Currently, though, when I try to put this surface on the backbuffer, and display it, it only shows up as black, with no pixel dots, no matter what size I make it on the backbuffer. Also, if I place this black surface over a sprite or another surface, it obscures it entirely, with no transparency. Any help? I've been wracking my brain over this. Thanks!
LPDIRECT3DSURFACE9 _makenoisesurf ( int width, int height, int num_pixels, float fade )
{
	RECT    rect;
	int     r,g,b,i;
	HRESULT result;

	LPDIRECT3DSURFACE9 noisemap = NULL;
	result = pD3dDevice->CreateOffscreenPlainSurface( 
		width,           // Width
		height,          // Height
		D3DFMT_A8R8G8B8, // Format
		D3DPOOL_DEFAULT, // Memory Pool
		&noisemap,        // Surface
		NULL);
	
	if ( result != D3D_OK )
		return NULL;

	pD3dDevice->ColorFill( noisemap, NULL, D3DCOLOR_RGBA( 0, 0, 0, 0 ) );

	LPDIRECT3DSURFACE9 pixel = NULL;
	result = pD3dDevice->CreateOffscreenPlainSurface( 
		1,                 // Width
		1,                 // Height
		D3DFMT_X8R8G8B8,   // Format
		D3DPOOL_DEFAULT,   // Memory Pool
		&pixel,            // Surface
		NULL);

	if ( result != D3D_OK )
	{
		noisemap->Release();
		return NULL;
	}

	for( i = 0; i < num_pixels; i++ )
	{
		rect.left   = rand() % width;
		rect.right  = rect.left + 1;
		rect.top    = rand() % height;
		rect.bottom = rect.top + 1;

		r = g = (int) ( ( ( rand() % 155 ) + 100 ) * fade );
		b = (int) ( ( ( rand() % 155 ) + 100 ) * fade );

		pD3dDevice->ColorFill( pixel, NULL, D3DCOLOR_XRGB( r, g, b ) );
		pD3dDevice->StretchRect( pixel, NULL, noisemap, &rect, D3DTEXF_NONE );
	}

	pixel->Release();

	return noisemap;
}



[Edited by - Spinewire on July 4, 2008 2:42:53 AM]

Share this post


Link to post
Share on other sites
I'd suggest using PIX to see what's being rendered. In particular, look at what the pixel surface contains. Also, enable the debug runtime to see if you get an error, and try this with the REF device, to see if it's a driver problem.

Share this post


Link to post
Share on other sites
Oh, I must have deleted my post. Sorry! I actually now ended up switching to textures and using LockRect. The reason I wasn't getting transparency was because I was blitting, not rendering, which was also interfering with displaying these surfaces properly.

As such, as per Evil Steve's suggestion at http://www.gamedev.net/community/forums/topic.asp?topic_id=500088, I switched to using textures and sprites (even though he suggested textured quads). LockRect clears this up so there's no need even for the 1x1 'pixel' surfaces in the first place. Far less overhead to worry about. PIX, too, was incredibly useful.

(**SOLVED**)

Share this post


Link to post
Share on other sites

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

Sign in to follow this