C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 08-25-2009, 10:03 AM   #1
Registered User
 
Join Date: Jan 2008
Posts: 153
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
Devils Child is offline   Reply With Quote
Old 08-25-2009, 10:52 AM   #2
Confused
 
Magos's Avatar
 
Join Date: Sep 2001
Location: Sweden
Posts: 3,122
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.
Magos is offline   Reply With Quote
Old 08-25-2009, 11:05 AM   #3
Registered User
 
Join Date: Jan 2008
Posts: 153
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?
Devils Child is offline   Reply With Quote
Old 08-25-2009, 02:41 PM   #4
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,924
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.
__________________
He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet
abachler is offline   Reply With Quote
Old 08-25-2009, 07:33 PM   #5
Guest
 
Sebastiani's Avatar
 
Join Date: Aug 2001
Posts: 4,923
Keep a copy of the pixels in a flat array. Process, write, process, write. It doesn't get much faster than that.
Sebastiani is offline   Reply With Quote
Old 08-26-2009, 05:25 AM   #6
Registered User
 
Join Date: Jan 2008
Posts: 153
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?
Devils Child is offline   Reply With Quote
Old 08-26-2009, 09:59 AM   #7
Registered User
 
Join Date: Jan 2008
Posts: 153
i tried it with directdraw, but couldnt really get a grip on that
Devils Child is offline   Reply With Quote
Old 08-26-2009, 03:40 PM   #8
Registered User
 
valaris's Avatar
 
Join Date: Jun 2008
Location: RING 0
Posts: 462
Use LockBits and GDI to do your drawing.

Using the LockBits method to access image data
valaris is offline   Reply With Quote
Old 08-26-2009, 07:24 PM   #9
Super Moderator
 
Bubba's Avatar
 
Join Date: Aug 2001
Posts: 7,470
If you want fast pixel drawing then do not use C#.
__________________
If you aim at everything you will hit something but you won't know what it is.
Bubba is offline   Reply With Quote
Old 08-27-2009, 04:32 AM   #10
Registered User
 
Join Date: Jan 2008
Posts: 153
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...
Devils Child is offline   Reply With Quote
Old 08-29-2009, 06:59 AM   #11
Registered User
 
Join Date: Jan 2008
Posts: 153
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.
Devils Child is offline   Reply With Quote
Old 08-29-2009, 11:16 AM   #12
Super Moderator
 
Bubba's Avatar
 
Join Date: Aug 2001
Posts: 7,470
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.
__________________
If you aim at everything you will hit something but you won't know what it is.

Last edited by Bubba; 08-29-2009 at 12:31 PM.
Bubba is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 01:19 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22