pixel

Started by
8 comments, last by ed209 16 years, 2 months ago
how do I draw a single pixel onto the screen?
Advertisement
1. Define a vertex format
2. Create a vertex and vertex buffer
3. In your render loop, set the vertex buffer appropriately
4. In DrawUserPrimitive(), set the primitive type to D3DPT_POINTLIST
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...
Quote:Original post by ed209
how do I draw a single pixel onto the screen?
By issuing a series of commands to the graphics API.

A more serious answer would be:
What language? What DirectX version? What API (D3D or DDraw)? Why do you want to draw a single pixel? Do you want to draw it once, or every frame? Do you want to only ever draw 1 pixel, or will you want to call your DrawPixel() function several times per frame? Are you sure you want to draw a pixel and not a more complex shape like a textured triangles?
I'm using managed directx for vb and I want to eventually be able to make a chip-8 emulator with it, so I will probably have to know how to draw pixels to the screen.
Couldn't I just make a sprite of size 1x1 and change the color when necessary or would that be stupid?
For my emulators, I have a 32-bit texture made to the resolution of the screen and an equally sized 2D array or integers. When the system draws something it sets the array. For each frame I just lock the texture, write the whole array to it and the draw the whole texture across the screen.

Quote:Original post by u235
1. Define a vertex format
2. Create a vertex and vertex buffer
3. In your render loop, set the vertex buffer appropriately
4. In DrawUserPrimitive(), set the primitive type to D3DPT_POINTLIST


Quote:Original post by ed209
Couldn't I just make a sprite of size 1x1 and change the color when necessary or would that be stupid?


Both of these would be so slow, you'd fall asleep at the keyboard.
I'm unsure of how to write to a texture in Dx, let alone managed Dx. Could someone please show me?
Why use DirectX for something so simple? A DIB and BitBlt would more than suffice for what you are doing. Just make sure it's double-buffered to avoid flicker. You won't be able to sync to the vertical retrace, so you may get some shear, but I don't imagine that having any great effect on the type of display you're going to have.

throw table_exception("(? ???)? ? ???");

I'd go GDI+ only if you're going to keep it in windowed mode. If you want to be able to switch between fullscreen and windowed then I'd use DirectX.

In either situation the high performance method is to create a bitmap/texture, lock/unlock it once per frame, and write pixels to it as if it were an integer array using pointer access (not sure what VB supports as far as that goes but C++ and C# will let you do extremely high speed access in this manner).
Quote:Original post by ravyne2001
Why use DirectX for something so simple? A DIB and BitBlt would more than suffice for what you are doing. Just make sure it's double-buffered to avoid flicker. You won't be able to sync to the vertical retrace, so you may get some shear, but I don't imagine that having any great effect on the type of display you're going to have.


Yea, bitblt would have way too much tear.

This topic is closed to new replies.

Advertisement