Copy bitmap to texture

Hi, I was looking to methods to have a texture out into plugin, I saw in template that texture is created by a shaderlike method.
In my work I have a fixed size bitmap actually builded in a custom thread, is it possible to copy that bitmap data, or build up a bitmapdatarray that can just be copied to texture out ?

Thank u :)

yes, the ‘UpdateTexture’ method is called each frame. there you can copy the bytes into the texture. you can look into the TextureUtils.cs to see how you can lock a texture and fill it with data, for example the ‘CreateColoredTexture’ method is a good start.

thank for pointing me to some docs, btw that method accept just a single value, so will create a one color texture, how can i fill the pixel onebyone ?

sorry but i’m totally new to this :)

you shouldn’t use the method, but understand the code to modify it for your own purpose…

a hint would be to change the line:


to something like


Oh sure, now is something familiar and easy thank u :)

I think hierro and I are working on the same thing here…

I made this hacky code and it seems to almost work, except it is slow and makes some horizontal lines on the image. Check out the screenshot. Renderer.png

unsafe private void FillTexure(uint* data, int row, int col, int width, int height)
            ushort* pDepth = (ushort*)this.depth.GetDepthMapPtr().ToPointer();
            ushort* pix = pDepth+col+row*width;
			byte depthPixel = (byte)this.histogram[*pix](*pix);
            //a pixel is just a 32-bit unsigned int value
            var pixel = UInt32Utils.fromARGB(255, depthPixel, depthPixel, depthPixel);

            //copy pixel into texture
            TextureUtils.SetPtrVal2D(data, pixel, row, col, width);

You can DL the buggy plugin .cs file here

Any thoughts on why the lines are showing up? I am sure this is the wrong way to do it for framerate, but the lines stump me. (4.3 kB)

hey, I’m happy to see u left my messy comments :D by the way didnt have time to take a look at texture, I will soon, and keep upadtes , here my skype add :


Ok, I am trying this:

unsafe protected override void UpdateTexture(int Slice, Texture t)
        	ushort* pDepth = (ushort*)this.depth.GetDepthMapPtr().ToPointer();
        	var rect = t.LockRectangle(0, LockFlags.None).Data; 
            for(int y = 0; y > 480; y++) 
	        	for(int x = 0; x > 640; x++, pDepth++)
	        		byte depthPixel = (byte)this.histogram[*pDepth](*pDepth);
	        		uint pixColor = UInt32Utils.fromARGB(255,255,depthPixel,depthPixel);
            FCurrentSlice = Slice;
            //TextureUtils.Fill32BitTexInPlace(texture, FillTexure);

But I get a black screen. Any thoughts?

mmmhhh, this is my third project in c# so im a littl bit confused , or better not skilled.

Anyway the histogram u are using with unsafe code is inside a locked loop or something by that, in my first view will be easier just to copy bitmapdata from the bitmap builded in openNi thread into a texture, seems to be easier :D

mhh some blackv screens too, should i have studied c# at high school , ahahahhahha :D

Ok I got rid of the lines, was a problem of sync between the vvvv thread and the openNI thread.

Can someone help move the pointer get outside of the iteration function? I think this is what is killing the framerate, it is getting the pointer of the frame every pixel. Renderer.png

Any help would be awesome, I know there are some C# gurus that can do some pointer magic out there… (79.5 kB)

what i got so far, is the texture coming out, but colors are wrong, it always dispaly striped blue, like im coping values only into blue channel or soemthign like that, well als o something else is strange, by the way framerate is normal and smooth :D

the bitmap im trying to copy is a 640x480 Format24bppRgb

i do this in updatetexture :

unsafe protected override void UpdateTexture(int Slice, Texture texture)
             FCurrentSlice = Slice;
             var rect = texture.LockRectangle(0, LockFlags.Discard).Data;
             rect.WriteRange(bitmapPointer, 640 * 480 * 3);

the border of grey shape are pixeled coloured…funny :)

and i have to create a texture 480x480to have the result of image…well it’s kinda late :D at least greys are there :D

i can’t test your code, but just a few hints:

  • why do you need a 32bit argb texture if you just write 255, depth, depth, depth to it?

  • use System.Array.Clear to clear your histogram. see:

  • FillTexure is called for each pixel. probably better to do it in your own loop so you only need to fetch the pointer once. like you show it in the out-commented code in UpdateTexture.

  • you can save a few comparisons and increments by using one loop intead of two (minor).

  • change the datatype of you’re histogram array to avoid calling UInt32Utils.fromARGB for each pixel and write something like


I got it.

I made it into a 32 bit bitmap (told you hierro :p) and now I read the depth data in evaluate. It seems a little slow but still around 30fps. With color 8D

Will try copying bytes from the other thread next year. (81.7 kB)

Ok, got it running in the other thread now. 60fps.

Also I just realized that the other one won’t work unless you have my quad2x module.

Happy new year! (81.7 kB)

well well seems we got it finally, will take a loook as soon as i’ll open my eyes :

anyway i wanna underline Jon heroic coding, with notepad :) was a nice skype time , happy new year and happy birthday for usa guy :D

ps. what is quad2x? where is it located ?