Jump to content
  • Advertisement
Sign in to follow this  
Error98

Direct3D manual drawing

This topic is 4772 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
Advertisement
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)

LPDIRECT3DTEXTURE8 Txr;
D3DLOCKED_RECT Rc;
unsigned int* Pntr;
D3DXCreateTexture(D3DDevice,256,256,0,0,D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,&Txr)
Txr->LockRect(0,&Rc,NULL,D3DLOCK_NOSYSLOCK);
Pntr=(unsigned int *)Rc.pBits;
Pntr[(10*256)+80]=0xFF00FF00; //plots a full green pixel at 80,10
//do more drawing
Txr->UnlockRect(0);



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.


(Initialization)

IDirect3DSurface9* surface;
IDirect3DSurface9* backbuffer;

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


(to draw)

D3DLOCKED_RECT lrt;
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);
device->Present(0,0,0,0);



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);

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

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

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

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


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 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!