Thread: Fast pixel drawing

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    244

    Fast pixel drawing

    hi!
    i wondered if there was a way i can draw pixels on a 640x480 form and reach framerates up to 100+ FPS?
    i've been doing this with C++ and SDL and i reached the maximum framerate. is there an efficient way to plot pixels in c# with pointers on a form?
    speed has most importance on this.

    thanks in advance

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Use a graphics api like DirectX or OpenGL?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    there hadnt been any need to ask if it was that easy...

    i want to port my software renderer to C# originaly written in SDL (c++). i don't need any SDL since it does not seem to be the right solution.

    so if software pixel drawing is as fast as DirectX pixel drawing, i want to do it in software, otherwise how should i do it in directx? any samples?

  4. #4
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    if speed is the major concern why are you using software rendering in the first place let alone porting to c#? Thats just making a bad problem worse.

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Keep a copy of the pixels in a flat array. Process, write, process, write. It doesn't get much faster than that.

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    i'm writing a _software_ renderer just to do it. it has no further use but to be proud of doing it in software :P
    so Sebastiani, how do i handle this pixel writing stuff? i basically need a pointer or an array of 4-byted-colors to write my data to and a flip function. but how?

  7. #7
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    i tried it with directdraw, but couldnt really get a grip on that

  8. #8
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    Use LockBits and GDI to do your drawing.

    Using the LockBits method to access image data

  9. #9
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    If you want fast pixel drawing then do not use C#.

  10. #10
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    i know how to draw pixels on a bitmap with bitmapdata and lock, but thats not fast, it is very slow. what i'm looking for is some realtime 100-fps drawing on a form...

  11. #11
    Registered User
    Join Date
    Jan 2008
    Posts
    244
    ok. it seems fairly fast when I use a picturebox with a bitmap and a pointer to the image.
    if you have any idea how to get this even faster, post it here

    thanks.

  12. #12
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Use a language that allows you lower-level access or use your language of choice the way in which it was designed to be used.

    You are not supposed to do low level pixel manipulation with C# b/c it is abstracted into a much higher level object like an image. Anytime you try to do low-level pixel manipulation in C# it is going to be slow b/c it was not designed for that.

    The whole point of C# is to hide the nitty gritty from you. Whether you agree with that or not is a moot point but if you do not like that you can switch to C++. Personally I find C# is very good for GUI but if you are trying to do something more complex like this you will run into many issues.

    EDIT:
    You could look into XNA in windowed mode for what you want. However I do not know much about XNA so I cannot give you any further advice about it. You may have better luck at some other forums regarding XNA. Gamedev has a lot of C# XNA devs so you might want to try over there.
    Last edited by VirtualAce; 08-29-2009 at 12:31 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 08:55 AM
  2. Slow drawing code
    By tjpanda in forum Windows Programming
    Replies: 5
    Last Post: 05-09-2008, 05:09 PM
  3. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM
  4. DX pixel drawing
    By VOX in forum Game Programming
    Replies: 3
    Last Post: 07-04-2005, 03:59 PM
  5. Drawing a single pixel
    By SMB3Master in forum C++ Programming
    Replies: 14
    Last Post: 05-26-2003, 06:17 AM