• Advertisement
Sign in to follow this  

Problem in D3D textures plz help

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

I am using managed direct3d with c#. I loaded a bitmap in texture Texture t=new Texture(Device,bitmap,Usage,Pool); Then i need to change some pixels in the texture, i noticed that I should change what i want in the bitmap and load it again with the same function(above). I worked but too slow. The second solution i found is using saving the bitmap into memorystream and loading the texture from it. Bitmap bmp; MemoryStream ms = new MemoryStream(); bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); ms.Seek(0, 0); Texture texture = TextureLoader.FromStream(device, ms); It also worked but when the bitmap is big, it is too slow.. is there a way to access the image data in the texture directly ? If someone knows plz respond ASAP, thnx.

Share this post


Link to post
Share on other sites
Advertisement
Look into the Texture::LockRectangle(...) function. There are some contraints to using it. The Texture must be created with the Usage.Dynamic flag, for instance.

I'm not sure if that forces it out of video memory or not. If it doesn't work or is still too slow, try Device::UpdateSurface(...) or Device::UpdateTexture(...).

Sorry if that's no help. I'm not too familiar with managed direct X.

Share this post


Link to post
Share on other sites
thnx for response, but i am afraid the problem is not solved. If use

Texture t;
t.LockRectangle(level,LockFlags);

what should i do then ?

or if i use Surface, how should i use it with texture ? plz tell me how..

and also i dont know what to do with updatesurface,

device.UpdateSurface(sourcesurface, destinationsurface);

or UpdateTexture(...) plz helps ASAP, thnx..

Share this post


Link to post
Share on other sites
Quote:
Original post by radiationz
thnx for response, but i am afraid the problem is not solved. If use

Texture t;
t.LockRectangle(level,LockFlags);

what should i do then ?

or if i use Surface, how should i use it with texture ? plz tell me how..

Look at the docs for this function. Depending on which overload you use, you get back a GraphicsStream of pixels or an Array of them. You modify that data as you wish, then call UnlockRectangle()

Btw, you can only bump after 24 hours.

Share this post


Link to post
Share on other sites
well that's nice, but how can i use GraphicsStream ? how can i change pixels in the image stored in the graphics stream ?

Share this post


Link to post
Share on other sites
Well i want to know how to read or write from GraphicsStream or Array that is returned from LockRectangle(...), actually i want to use Graphics class functions like DrawEllipse(...) on it . plz some one help ASAP, thnx.

Share this post


Link to post
Share on other sites
Here's an example from the sdk documentation that uses a graphics stream to alter a vertex buffer. The Lock function of the Texture class is the same basic concept, hopefully this will get you going in the right direction.


using System;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

public struct PositionNormalTexVertex
{
public Vector3 Position;
public Vector3 Normal;
public float Tu0, Tv0;
public static readonly VertexFormats FVF = VertexFormats.Position | VertexFormats.Texture1;
}
public class Example
{
public unsafe void GraphicsStreamReadWrite()
{
//Create a vertex buffer in the managed pool
VertexBuffer vb = new VertexBuffer(typeof(PositionNormalTexVertex), 100, device, Usage.None, PositionNormalTexVertex.FVF, Pool.Managed);

//First, fill an array of PositionNormalTexVertex elements with data.
PositionNormalTexVertex[] vertices = new PositionNormalTexVertex[50];
for(int i=0; i<50; i++)
{
//fill the vertices with some data...
vertices[i].Position = new Vector3(3f,4f,5f);
}

//The size of the verticies are 32-bytes each (float3 (12) + float3 (12) + float(4) + float(4))
//To lock 50 verticies, the size of the lock would be 1600 (32 * 50)
GraphicsStream vbData = vb.Lock(0,1600, LockFlags.None);

//copy the vertex data into the vertex buffer
vbData.Write(vertices);

//Unlock the VB
vb.Unlock();


//This time, lock the entire VertexBuffer
vbData = vb.Lock(0, 3200, LockFlags.None);

//Cast the InternalDataPointer (a void pointer) to an array of verticies
PositionNormalTexVertex* vbArray = (PositionNormalTexVertex*) vbData.InternalDataPointer;

for(int i=0; i<100; i++)
{
//perform some operations on the data
vbArray[i].Tu0 = i;
vbArray[i].Tv0 = vbArray[i].Tu0 * 2;

Console.WriteLine(vbArray[i].Tv0.ToString());
}

//Unlock the buffer
vb.Unlock();
vb.Dispose();
}
}

Share this post


Link to post
Share on other sites
Use the TextureLoader class. Next time use the docs/FAQ/gd search/tutorials/google first plz thx asap

Share this post


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

  • Advertisement