• Advertisement
Sign in to follow this  

[MDX] SetPixel in Direct3D

This topic is 4345 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 need to create in direct3d a set pixel function. the reason i need this is simple. I am writing a raytracer and need By pixel access. why am i useing direct3d then instead of directdraw or even gdi+? well the main reason is because I need to have in the same frame window rough predraw general image of the scene (think preview view in 3dsmax) then as i render it would overwrite the preview form. Everytime i ask this question I get the same responce 'don't use a set pixel type function to blit a bitmap! no use this method' sorry not blitting a bmp just need to set one pixel at a time. I'm not looking for blazing speed but it has to be at least able to do one pixel per frame at 60 fps. that seems more then reasonable speed considering I will most likely be only able to generate 1 pixel every minute or so with some of my scenes. I tried to do this using a quad that filled the screen poped a texture on to it loaded a texture from a bitmap then I just write one pixel at a time to the bitmap. very round about but it worked.....but it was horribly slow. If you know the unmanaged direct3d way of doign this please do post i can probably figure it out. I tryed using the get backsurface then lock but the graphicsstream object i got i couldn't figure it out <sigh> and the array object version of the function is horribly slow because generating the huge array every frame causes the gc to go hay wire. theres a work around that microsoft is working on for this but not implemented yet.

Share this post


Link to post
Share on other sites
Advertisement
I haven't tried it myself, but a quick idea would be to use GetBackBuffer() to grab the default render target surface, and then use ColorFill with a rectangle that represents a single pixel to draw a pixel to it. Then call Present() to draw the frame. Never call Clear(), and make sure to use the Copy swap effect when specifying your present parameters during device creation, so that the back buffer remains in the same state without getting erased or swapped or anything.

Calling GetBackBuffer(), ColorFill(), and Present() once each per frame doesn't sound like it should be a problem. This is all just hypothetical, though. :-/

Share this post


Link to post
Share on other sites
In unmanaged DirectX, you'd create a lockable backbuffer. Each frame, you'd lock it, obtaining a pointer to its memory that you can write to directly. After you're done, you'd unlock it.

Share this post


Link to post
Share on other sites
Hi LostAgain,
Here is some of my assembler code from my Graphics project using the Flat Assembler(FASM for short). Even though its in assembly, i think you can still figure out whats going on.


proc D2DLockBackBuffer
D3DCALL d3d9device, GetBackBuffer, 0, 0, D3DBACKBUFFER_TYPE_MONO, d3d9BackBuffer
invoke SetRect, rect, 0, 0, [d3d9present.BackBufferWidth], [d3d9present.BackBufferHeight]
D3DCALL d3d9BackBuffer, LockRect, lockedrect, rect, NULL

;create lookup tables
pushad
mov esi, [lockedrect.pBits] ;pointer to surface
mov edi, scanlinetable
mov ecx, 480 ;[d3d9present.BackBufferHeight]
.repeat
mov [edi], esi
add esi, [lockedrect.Pitch] ;<- VERY important! use this value
to get to the next scanline
instead of
"screenwidth*sizeof.pixel"
add edi, 4
dec ecx
.until ecx, l, 0
popad
return
endp

proc D2DUnlockBackBuffer
D3DCALL d3d9BackBuffer, UnlockRect
D3DCALL d3d9BackBuffer, Release
return
endp


Share this post


Link to post
Share on other sites

Why not creating a dynamic texture which you can access pixel by pixel ? Then you wouldn't have to bother with the back buffer and you could keep the raytraced image in the memory even if you decide to change your point of view.

Or why not render the image to some system memory array and when finished just upload to image to the dynamic texture.

I wouldn't poke with the backbuffer.

Cheers

Share this post


Link to post
Share on other sites
all right how would i access and write a single pixel to a dynamic texture. i'm willing to work with people on how to do this but so far i am slamming my face into a wall here. i can lock it all right but atm i have so many wierd and controdictury results i think there is somethign fundamentally wrong with lockrectangle in maanged directx cus is does _not_ work the same as in non managed form. heck it doesn't even work nearlly the same form one overwritten form of the function to another. in one of the forms of the function i couldn't lock anything larger then 255 x 255! on a 500 x 500 form thats a little odd. and considering it's a binary boundry there tells me something is going wrong in the function itself.

Share this post


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

  • Advertisement