Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

kapru

modifying a texture

This topic is 5311 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

Im trying to write to a texture who format is D3DFMT_R5G6B5 im getting a value from 0 and 255 out of an array this value represents a grayscale color and i want to write this color onto a texture heres the code im using
	//this function will convert the raw blend map into a texture

    D3DLOCKED_RECT lr;
	unsigned int *bits;
	unsigned int pitch;
	int i,j;
	D3DSURFACE_DESC desc;
	char col;
	terrBlendMap[mapnumber]->GetLevelDesc(0, &desc);
	terrBlendMap[mapnumber]->LockRect( 0, &lr, 0, 0 );
	bits=(unsigned int*)lr.pBits;
	pitch=lr.Pitch/4;


	//Copy the data onto the texture

	for(i=0;i<(signed)desc.Width;i++)
		for(j=0;j<(signed)desc.Height;j++)
		{
			if(i<terrSizeX&&j<terrSizeY)
			{
				col=BlendMap[mapnumber][j*terrSizeX+i];
				bits[i+j*pitch]=D3DCOLOR_XRGB(col,col,col);

			}
		}
	
	terrBlendMap[mapnumber]->UnlockRect(0);
i know im messing something up but i cant figure it out [edited by - kapru on January 6, 2004 1:13:31 AM]

Share this post


Link to post
Share on other sites
Advertisement
I see two problems.

1: Int is 32-bit wide variable, but you would need to use 16 bits per pixel (cast the locked data pointer to WORD* instead of int*).
2: D3DCOLOR_XRGB produces a 32-bit (8888) color value; you must convert this to 16-bit (565) representation.

-Nik

EDIT: Look up the D3DCOLOR_XRGB macro definition. With trivial modification, you can make a 16-bit version of it (as it simply consists of a few bit shifts and bitmasks).

[edited by - Nik02 on January 6, 2004 8:10:20 AM]

Share this post


Link to post
Share on other sites

  • 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!