Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

knine

Pixel Plotting w/ DirectGraphics 8.1

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

Please forgive the newb question, but can anyone point me to an example of plotting a pixel with DirectGraphics? I''m using the LPD3DXSPRITE functionality, so i''m not setting up a view matrix or setting perspective or anything. Any help is appreciated. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
I used to have tutorial on it somewhere. I think there''s a method where you can lock the memory. Try looking in the SDK under the memory locking section.

I think it''s quite complex and similar to the old super fast pixel plotting method.

It probably goes along these lines.

Lock the memory you''re accessing (i.e. the surface)
Copy the memory into an array (used to have to be a safe array to avoid buggering your system)
do stuff to it.
Copy the memory back?
Unlock...

it''s complex.

HOWEVER: you might get away with using the GDI SetPixelV, SetPixl and GetPixel commands by obtaining a handle to the surface.

Hope this helps a little

~~Tim

Share this post


Link to post
Share on other sites
yep, the super fast way is to switch to directdraw7 and use the right tool for the job. d3d8 is not designed for pixel plotting and is quite slow for that (like openGL). you could allocate some buffers and then Lock() a texture, transfer the data, Unlock() the texture. though beforewarned you wont get any decent speed using high res textures (anything larger then 512x512), nor reading from a texture. then you just draw the texture to the screen. you will probaly complain that there are no pixel plotting finctions worth using, and you cant write to the screen directly with any speed. this is the way things are, so dont stress about it. also, if you are just doing pixel plotting stuff, i urge you to switch to directdraw7 (which yes you can use even if you have th dx8 sdk installed).

Share this post


Link to post
Share on other sites
Actualy its not a problem:

D3DLOCKED_RECT LockedRect;
LPDIRECT3DSURFACE8 pBackSurf = 0;

pDevice->Clear( 0, 0, D3DCLEAR_TARGET, D3DCOLOR_XRGB( r, g, b ), 1.0f, 0 );
pDevice->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pBackSurf );
pBackSurf->LockRect( &LockedRect, NULL, 0 );
DWORD* pData = (DWORD*)(LockedRect.pBits);

Now you have locked the memory and you have a pointer to the memory data.

Then to plot a pixel:

pData[ ((Pitch/4) * y) + x ] = Color;

where Pitch = LockedRect.Pitch and Color = D3DCOLOR_XRGB( r, g, b )

pBackSurf->UnlockRect();
pDevice->Present( NULL, NULL, NULL, NULL );


This is for D3D8......

be careful with pointers and stuff

Share this post


Link to post
Share on other sites
Thanks russian-bear, that was a great help. I would like to add something though, you must release the surface when you''re through or you''ll have a memory leak. So, after you UnlockRect, just call Release() on pBackSurf.

Share this post


Link to post
Share on other sites
Or, you can call DrawPrimitive() with D3DPT_POINTLIST as the primitive type.

------------------------------
BASIC programmers don''t die, they just GOSUB and don''t return.

Share this post


Link to post
Share on other sites
***Depending on what you''re doing***, you might be able to use a vertex buffer of points. For transferring bitmap data, that''s not a great way to go, but for drawing a starfield or something it might be.

What exactly are you trying to do? If you tell us, we can probably give better answers.

Share this post


Link to post
Share on other sites
I am trying to draw a starfield. I tried russian-bears remedy but i crash saying the backbuffer is NULL.

Share this post


Link to post
Share on other sites
For a starfield, creating an array of vertices and drawing points is probably a very good solution. Especially if your card supports sized points. This will also make it a snap to animate them, warp drive, etc.

Share this post


Link to post
Share on other sites

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