Jump to content
  • Advertisement
Sign in to follow this  
jdub

SlimDX/D3D9 Random texture creation problem?

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

Here is my code:


public RandScreen(Device device)
{
rand = new Random();

//create blank texture with specified size and color depth
texture = new Texture(device, 100, 100, 1, Usage.None, Format.A8R8G8B8, Pool.Managed);
SurfaceDescription textureDesc = texture.GetLevelDescription(0);

DataRectangle dataStream = texture.LockRectangle(0, LockFlags.Discard);
for (int y = 0; y <= textureDesc.Height; y++)
{
for (int x = 0; x < textureDesc.Width; x++)
{
if (x == dataStream.Pitch)
{
x = 0;
continue;
}

dataStream.Data.Write((byte)randomPix(x,y));
}
}
texture.UnlockRectangle(0);
}






The application runs fine when I only write one byte at a time to the buffer (although the texture doesn't look right at all). However, each of my pixels has a size of 4 bytes. To remedy, I tried replacing the code with this:


byte[] buffer = new byte[4]
{
(byte)randomPix(x,y),
(byte)randomPix(x,y),
(byte)randomPix(x,y),
(byte)randomPix(x,y)
};

dataStream.Data.Write(buffer, 0, 4);






However, when the application runs, I get an EndOfStream Exception. If each pixel I am writing to is 4 bytes large, then why can't I write 4 bytes to it?

Also, how can I generate mipmaps for this texture? I tried to set it so that it would automatically create mipmaps but that makes DirectX throw an exception (realized that this makes sense because there is no texture data to create mipmaps for).

[Edited by - jdub on December 8, 2010 10:31:12 PM]

Share this post


Link to post
Share on other sites
Advertisement
Are you sure you're not overstepping the bounds of the locked texture? It's hard to tell from what you've posted what exactly you're trying to run. Do you have a minimally reproducible test case that I can take a look at?

Share this post


Link to post
Share on other sites
Nope... it happens every time I try and run the application. The random texture is generated once at the beginning of the application after the device and renderer have been created.

The length of the stream is 40,000 bytes so it doesn't make sense that in my first write to it, writing 4 random bytes would cause an EndOfStream exception.

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!