Jump to content
  • Advertisement
Sign in to follow this  

How to plot a pixel in Direct3D 9 ?

This topic is 4895 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, I'm currently reading Frank Luna's "Intro to DX9". I've already finished a few chapters but went back to Chapter I to test his pixel plotting code snippet as shown below:
// Assume _surface is a pointer to an IDirect3DSurface9 interface.
// Assumes a 32-bit pixel format for each pixel.

// Get the surface description.
D3DSURFACE_DESC surfaceDesc;

// Get a pointer to the surface pixel data.

D3DLOCKED RECT lockedRect;
      &lockedRect,// pointer to receive locked data
      0,          // lock entire surface
      0);         // no lock flags specified

// Iterate through each pixel in the surface and set it to red.

DWORD* imageData = (DWORD*)lockedRect.pBits;
for(int i = 0; i < surfaceDesc.Height; i++)
      for(int j = 0; j < surfaceDesc.Width; j++)
            // index into texture, note we use the pitch and divide by
            // four since the pitch is given in bytes and there are
            // 4 bytes per DWORD.
            int index = i * lockedRect.Pitch / 4 + j;

            imageData[index] = 0xffff0000; // red

My only problem here is the values of surfaceDesc's (D3DSURFACE_DESC) members. When I ran my program (w/c has already an initialization code to set up a blank window), it goes back. I ran the debugger and there's a problem with: _surface->GetDesc(&surfaceDesc); I know that it's becuase surfaceDesc has not been set yet. Can anyone provide me the needed values for its members? THANKS A LOT IN ADVANCE!!

Share this post

Link to post
Share on other sites
The problem with this approach is that you are trying to use D3D as DirectDraw. Thats a wrong approach as it stalls the pipeline.

Try using some transformed-lit vertices and render using the POINT primitive.


Share this post

Link to post
Share on other sites
Hi again,

You got me there. I actually came from a DirectDraw background that's why I thought the idea is the same. I'll try what you've just said.

Thanks for the tip.

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!