Skip to main content
gamedev.net
🔒 Locked

Modifying Pixels For A Paint Program

Started by GroZZleR 5 replies 450+ views
Original Post
GroZZleR
GroZZleR
Hey all, What's the most efficient way to modify pixel data directly? I'm looking to write a little MS Paint clone (it actually has an end purpose) and am unsure of what the best way to tackle the problem is. Is just unlocking a surface and changing the pixel data the best way to go about it? Seems like it'd choke eveytime you'd paint.
Agony
Agony
If you insist on using DirectX (and assuming newer versions of DX, Direct3D), then yeah, locking the texture's surface and writing to it, and then unlocking it again , and finally using a quad to draw it would be the best. Make sure that you create the texture with D3DUSAGE_DYNAMIC. Actually, you might consider just locking the backbuffer and writing to that, but I don't know what the speed would be on that, and you'd lose all abilities to do layered effects and such.

As for speed with all the locking, dynamic textures are meant to be locked and unlocked a lot. And since you're only going to be doing this to a single texture at a time, and you're not trying to get 85 FPS out of it, then it probably ain't going to be a speed problem at all.

(Side thought about another benefit to using DirectX: Eventually, you could get around to having fun with pixel shaders to apply hardware accelerated effects to your images.)

However, using a 3D API to write a paint program seems a little odd, unless you find some uses for the API that standard bitmaps can't do, such as really easy alpha blending for layers or something. I'd just recommend sticking with the standard Win32 device contexts and bitmaps, and things like bitblt. But for you, that might require learning new stuff rather than using what you already know. Which isn't necessarily a bad thing, but if you're lazy, I'm no one to criticize you. [smile]
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas nly, and not for things themselves." - John Locke o
sirob
sirob
I know theres an HLSL paint sample in the DX SDK. I'm unsure exactly how it works (a bit over my head), but I'm quite positive it provides better results than the other methods. Assuming your up to it, I'd take a look at how it's done there.
Sirob Yes.» - status: Work-O-Rama.
DrGUI
DrGUI
Quote:
Original post by sirob
I know theres an HLSL paint sample in the DX SDK. I'm unsure exactly how it works (a bit over my head), but I'm quite positive it provides better results than the other methods. Assuming your up to it, I'd take a look at how it's done there.

I know NVidia FX Composer comes with one where you can draw on a teapot.
sirob
sirob
yes, that's the one I mean - got the origin of it mixed up thanks :).
Sirob Yes.» - status: Work-O-Rama.
bit64
bit64
Quote:
However, using a 3D API to write a paint program seems a little odd, unless you find some uses for the API that standard bitmaps can't do, such as really easy alpha blending for layers or something. I'd just recommend sticking with the standard Win32 device contexts and bitmaps, and things like bitblt. But for you, that might require learning new stuff rather than using what you already know. Which isn't necessarily a bad thing, but if you're lazy, I'm no one to criticize you.



Layering (like Adobe PS and PS Pro) would be a very easy task as well.
Don't be afraid to be yourself. Nobody else ever will be.
Kaze
Kaze
you could try GetBitmapBits/SetBitmapBits, but i dont know how fast this is

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.