Sign in to follow this  
CIJolly

Plotting pixels in DirectX 8

Recommended Posts

You'd think this would be easy to find online, but for some reason it isn't. I've found and implimented tutorials on alpha blending, billboarding, matrix operations...but something as simple as plotting a coloured pixel to the screen in directx 8 continues to elude me. Does anyone know how to do this efficiently? Or where I could find a good tutorial?

Share this post


Link to post
Share on other sites
Quote:
Original post by CIJolly
You'd think this would be easy to find online, but for some reason it isn't.
I've found and implimented tutorials on alpha blending, billboarding, matrix operations...but something as simple as plotting a coloured pixel to the screen in directx 8 continues to elude me.
Does anyone know how to do this efficiently? Or where I could find a good tutorial?


It's something like tutorial 1 included with the sdk. It teaches you how to draw a triangle to the screen. Instead of using TRIANGLELIST or whatever with your drawprimitive statement, use pointlist.


Share this post


Link to post
Share on other sites
Thanks, I did some google searches on POINTLIST and went through the tutorial, and it proved much more fruitful than my searches for plotpixel.

I am filling the whole screen with white pixels to test how efficient this method is, and am only getting 12fps.
Here is the meat of my render function, it is executed once per frame:


CUSTOMVERTEX g_Vertices[5024];
m_pD3DDevice->SetStreamSource( 0, g_pVB, sizeof(CUSTOMVERTEX) );
m_pD3DDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX );

int xpixel = 0;
int ypixel = 0;

for (int pixelcounter = 0; pixelcounter < 160; pixelcounter ++)
{

for (int ix = 0; ix < 5024; ix++)
{
g_Vertices[ix].x = xpixel;
g_Vertices[ix].y = ypixel;
g_Vertices[ix].z = 0.5f;
g_Vertices[ix].rhw = 1.0f;
g_Vertices[ix].color = 0xffff0000;

xpixel++;
if (xpixel > 1024)
{
xpixel = 0;
ypixel ++;
}

}
}

VOID* pVertices;
g_pVB->Lock( 0, sizeof(g_Vertices), (BYTE**)&pVertices, 0 );
memcpy( pVertices, g_Vertices, sizeof(g_Vertices) );
g_pVB->Unlock();

m_pD3DDevice->DrawPrimitive( D3DPT_POINTLIST, 0, 5025 );




Am I doing anything glaringly obviously wrong? Surely DirectX can plot pixels faster than 12fps.

Share this post


Link to post
Share on other sites
Using a pointlist isn't all that intuitive. If you're looking to render pixel-wise, like we had to back in the day, you may have more luck using D3D Surfaces with direct access. For a simple double-buffered setup you should create an off-screen surface of the appropriate format, draw to it every frame and copy it to the screen. Some methods of interest:
// Upon initialisation
IDirect3DDevice9::CreateOffscreenPlainSurface

// Each frame
IDirect3DSurface9::LockRect
IDirect3DSurface9::UnlockRect
IDirect3DDevice9::StretchRect
Be warned, though, that this sort of thing isn't hardware accelerated and will be a little slow.

Regards
Admiral

Share this post


Link to post
Share on other sites
Quote:
Original post by CIJolly
Thanks, I did some google searches on POINTLIST and went through the tutorial, and it proved much more fruitful than my searches for plotpixel.

I am filling the whole screen with white pixels to test how efficient this method is, and am only getting 12fps.
Here is the meat of my render function, it is executed once per frame:

*** Source Snippet Removed ***

Am I doing anything glaringly obviously wrong? Surely DirectX can plot pixels faster than 12fps.



That does seem a little slow for what it is doing.

How are you setting up your rendering? Are you using double buffering? I'm by no means an expert on this, but it seems like something might be set up in an inefficient way.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this