Advertisement Jump to content
Sign in to follow this  

Direct3D manual drawing

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

Hi! Is it still possible to draw in Direct3D with your own line drawing algorithm? And more genreral is it possible to get pointer to the primary surface and draw manual instead of letting directx do it? Or do i realy have to use DirectX7 DirecDraw to do everything by my self? Thank you for your help!

Share this post

Link to post
Share on other sites
Yes, it's possible. Once all is set up, you can call the GetBuffer function of the D3D Device and get a pointer to a surface object. With the surface, you can call GetDC and use it just like you'd draw in GDI.

Share this post

Link to post
Share on other sites
Yes it's possible to get a pointer to a texture/render-target/buffer and draw pixel-by-pixel. Say you created a 32-bit 256x256 colour texture, you would do something like this:

(might not be 100% correct)

unsigned int* Pntr;
Pntr=(unsigned int *)Rc.pBits;
Pntr[(10*256)+80]=0xFF00FF00; //plots a full green pixel at 80,10
//do more drawing

This only works for power-of-2 textures as I left of the stuff for padding. Also be aware that if you use a 16-bit format like A1R5G5B5 then you would need an unsigned short pointer instead of unsigned int/long.

Share this post

Link to post
Share on other sites
The way I would do it it's pretty much as simple as using directdraw.


IDirect3DSurface9* surface;
IDirect3DSurface9* backbuffer;

device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
device->CreateOffscreenPlainSurface(XRes, YRes, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surface, NULL);

(to draw)

surface->LockRect(&lrt, NULL, D3DLOCK_DISCARD);
unsigned int* ScreenData = (unsigned int*)lrt.pBits;
int Pitch = lrt.Pitch;

ScreenData[x+Y*Pitch] = PixelValue;

device->UpdateSurface(surface, NULL, backbuffer, NULL);

Share this post

Link to post
Share on other sites
Thanks for all you replys!

But .. i still can't make it work :/

Here's the code (btw how can i insert code into text box?)

d3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &mybackbuffer);

d3dDevice->CreateOffscreenPlainSurface(SCREEN_LENGHT, SCREEN_HEIGHT, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &mysurface, NULL);

mysurface->LockRect(&lrt, NULL, D3DLOCK_DISCARD);
unsigned long* screenData = (unsigned long*)lrt.pBits;

char buffer[100];
itoa(lrt.Pitch, buffer, 10);

for(i=100;i<300;i++) // SCREEN_LENGHT and SCREEN_HEIGHT are 1280x1024
screenData[i+(j*lrt.Pitch)] = 255;

d3dDevice->UpdateSurface(mysurface, NULL, mybackbuffer, NULL);

By "it's not working" i mean sometimes it crashes sometimes it's freazing and nothing but reset helps (i'm using Win'XP)!!

I checked pitch value and it's 5120 isn't it too big?

Any idea what it might be?

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!