Sign in to follow this  

how to plot a pixel to the screen?

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

I'm writing a program that requires plotting individual pixels to the screen. Is there a way to do this without making 1*1 bitmaps (which I assume would be slow) If so, could someone give a detailed explaination of how it's done?

Share this post


Link to post
Share on other sites
It depends on which graphics library you're using as well as what platform you're developing for. Do you want to use Win32 GDI? ... DirectX (DirectDraw or D3D)? ... OpenGL? ... SDL? ... etc.

There are countless articles contained here at Gamedev that cover getting started with these and other graphics libraries.

Share this post


Link to post
Share on other sites

point p; //simple 2d point struct
color c; //simple RGB color struct

...in GDI
HDC dc; //your drawing context
SetPixel(dc,c.x,c.y,RGB(c.red,c.green,c.blue));

...in OpenGL
glBegin(GL_POINTS);
glColor3ub(c.red,c.green,c.blue);
glVertex2i(p.x,p.y);
glEnd();

It is fast to plot multiple point in OpenGL. Let's say you have an array of points and an array of corresponding colors:

point p_array[N];
color c_array[N];

glBegin(GL_POINTS);

for(int i = 0; i<N;++i)
{
glColor3ub(c.red,c.green,c.blue);
glVertex2i(p.x,p.y);
}

glEnd();

I suppose in DirectX the same effect can be achieved by using IDirect3DDevice::DrawPrimitive with D3DPT_POINTLIST as a primitive type.

Hope this would be good to start your search with.

Share this post


Link to post
Share on other sites
I want to do it in directx. This is, after all, the directx
forum.

Use direct3d? I want the speediest way to do this, and my
assumption is that direct3d would probably be pretty slow.
I'm plotting a LOT of pixels.

Share this post


Link to post
Share on other sites
Heh, sorry... I thought it was in the Game Programming forum. I'm a little backwards today.

Anyway, if all you're going to be doing is plotting pixels then there is really no reason to have to harness the power of D3D, or OpenGL really for that matter. DirectDraw, however old, out of fashion, and not really used much, is quick, easy, and powerful to draw pixels as fast as you need them, provided that's all you're going to be doing. But it all comes down to preference and what all you'll be doing.

Share this post


Link to post
Share on other sites
How many points are you going to plot? A standar array can hold up to 32000 vertices and each vertex can be plotted as a pixel.

Anyway, you can easilly plot a pixel with a single vertex. You dont have to use a texture.

There was an article in Gamedev about rendering sprites. You can use the same logic in order to render transformed lit points using the D3DPOINT_LIST primitive.

Luck!
Guimo


Share this post


Link to post
Share on other sites
I'm not sure that DirectDraw will be the best choice.

Plotting even one single pixel in direct draw requires locking of surfaces. This is too slow.

You can allocate some memory for your screen buffer, perform software pixel plotting and then lock some of your surfaces only once to move the contents of the buffer to the surface.

This will be faster but still using Direct3D can be even better. I suppose you are plotting less pixels than your width_resolution*height_resolution.[smile]

Today transfer rates between RAM and GPU is the bottleneck of most applications. Plotting pixels with DrawPrimitive result in transferring less data to the video card. Once your pixels are loaded on GPU they are processed very fast. I think rendering a pixel is even faster then transferring it from RAM.

Even greater optimization is possible if you are plotting pixels from some large non changing set, drawing only part of this set at one time. Then you can preload the entire set on GPU and use DrawIndexedPrimitive to specify which pixels of this set to draw.

Share this post


Link to post
Share on other sites
one aproach to plotting pixels in ddraw, other than locking writing and unlocking a buffer, is to use blt using a colorfill and a dest rectangle of 1x1, this method is likely to be faster if your only plotting a few pixels, if your are setting every pixel each frame, a single lock write unlock is your best choice.

you must be sure that if you go with a lock write unlock, that you dont read from the image, since this is extreamly slow. if you require reading then writing you should use a software surface, which you do your computations on, and then blt to the hardware back buffer.

hope that helps =)

Share this post


Link to post
Share on other sites
Quote:
Original post by jimiwa
I'm writing a program that requires plotting individual
pixels to the screen. Is there a way to do this
without making 1*1 bitmaps (which I assume would
be slow)
If so, could someone
give a detailed explaination of how it's done?


Use VertexBuffers or DrawPrimitiveUp() function and arrays.

Share this post


Link to post
Share on other sites

This topic is 4715 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.

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