Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (492)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  The fastest way to draw a pixel  (Read 4806 times)
0 Members and 1 Guest are viewing this topic.
Offline zingbat

Senior Member




Java games rock!


« Posted 2004-09-24 08:29:25 »

Lets have a little chalenge here ok ?

The chalenge is to make the fastest static method wose semantics is just draw a single pixel using the interface:


Graphics.drawPixel(Component c, int x,  int y, int color);

Whats your best shot.
Grin

PS: The semantics of the method doesn't say the pixel must be drawn immideatly and that no other methods can be used to complement the operation.
Offline crystalsquid

Junior Member




... Boing ...


« Reply #1 - Posted 2004-09-24 15:34:02 »

Write your own software renderer, then the drawPixel becomes a multiply, an add, and a write into an array.
Smiley
Offline zingbat

Senior Member




Java games rock!


« Reply #2 - Posted 2004-09-24 18:23:31 »

Don't you have a more easy solution ?  Grin

How would you put that array on screen without suffering a huge performance penality ?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline crystalsquid

Junior Member




... Boing ...


« Reply #3 - Posted 2004-09-24 20:08:59 »

Theres a load of stuff including some sample code here:
http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=2D;action=display;num=1073992902;start=5#5

And:

http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=Tuning;action=display;num=1089310877;start=10#10

Hope this helps,

- Dom
Offline zingbat

Senior Member




Java games rock!


« Reply #4 - Posted 2004-09-25 08:52:13 »

ok thanks


well back for another round with java sdl  Grin
Offline Linuxhippy

Senior Member


Medals: 1


Java games rock!


« Reply #5 - Posted 2004-11-18 09:22:18 »

thanks for all the info but what is for now the fast ways to  draw pixels. I do not think 1mio drawLines would be more optimal that Imageproducer.

Are BufferedImage typically faster than those old 1.1 (ImageProducer) apis?

The question why I am asking is the fact that I am realizing a software renderer which has serious problems with iamge-rendering throughput.

lg Clemens
Offline krausest

Junior Member


Exp: 15 years


I love YaBB 1G - SP1!


« Reply #6 - Posted 2004-11-18 09:53:04 »

The fastest way to draw a pixel should be like that:
Create an BufferedImage and specify the format.
If you've chosen TYPE_3BYTE_BGR you can get the data array and set the values to your color value. Something like:

byte[] data=((DataBufferByte)img.getRaster().getDataBuffer()).getData();

(There's a bit in the FAQ about that: Then take a look at the FAQ on http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=2D;action=display;num=1097853220 )
Offline Absolution

Senior Newbie




Java games rock!


« Reply #7 - Posted 2004-11-18 17:59:37 »

I get a 5-10 fps increase with my software renderer if I switch from the Producer/Consumer model to the BufferedImage Model (compiled with 1.5).  Do note though that getting direct access to the pixels stops any possibility of hardware acceleration.  Too bad because I seem to always want access to it in my games.   The speed increase seems to be mainly from avoiding that nasty newPixels call although I could be wrong.  I tried implementing my own producer, but didn't notice a difference from the MemoryImageSource so I currently use that for my 1.1 needs.   Anyway, on a 2Ghz system I can easily get 60fps at 500x500 for a fully textured 3D world using a producer and it's not even close to fully optimized so the throughput should be fine for most applications.
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #8 - Posted 2004-11-19 23:12:06 »

Why waste time developing a software renderer?

They are only useful in Applets, and as webstart is a far superior alternative in most cases, Applets in my view are an obsolete technoogy.
The sooner people stop using them, the better.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Linuxhippy

Senior Member


Medals: 1


Java games rock!


« Reply #9 - Posted 2004-11-20 08:40:28 »

Hmm, maybe you want to do something that can not be done in Hardware?
Think of Voxel engines for example, I like voxel engines very much, cause they look much more natural than texture stuff does...

however, everybody should use what he wants to!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 369
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #10 - Posted 2004-11-20 10:24:59 »

I think I saw a recent demo of a voxel engine implemented in OpenGL shaders on opengl.org...

Back to the original question:

fastest way to draw a pixel is as Dom says to supply your own Graphics implementation and write directly into a nice simple array, and when you're all done with that array, blit the whole thing straight to the screen front buffer with one call.

Cas Smiley

Offline EgonOlsen
« Reply #11 - Posted 2004-11-20 14:46:03 »

Quote
Why waste time developing a software renderer?

People are using software renderers for various reasons: no hardware acceleration available, no OpenGL binding, old VMs, rendering takes places on a web server, etc. jPCT can do both, software and hardware, and people are still using the software renderer most of the time. So there definitly is a "market" for software rendering...just maybe not that much in this community, which covers a very tiny niche only.
And arguing that way, almost everything that we're doing here is a waste of time. Who cares for the 1000000th clone of tron or tetris written in Java except for the proud author?

Offline nonnus29

Senior Member




Giving Java a second chance after ludumdare fiasco


« Reply #12 - Posted 2004-11-21 12:48:49 »

Quote
Why waste time developing a software renderer?


Its a good way to learn.  Its fun.  Its interesting. etc....
Offline Absolution

Senior Newbie




Java games rock!


« Reply #13 - Posted 2004-11-21 21:38:57 »

This is getting off topic and this particular off topic has been discussed in extreme depth several times on this board (I can think of 3 right now).
Offline Jeff

JGO Coder




Got any cats?


« Reply #14 - Posted 2004-11-22 00:20:24 »

Keep in mind that the question "what is the fastest way to draw a (single) pixel" has little or mno relevance to the question  "what is the fastest way to draw N pixeles, where N is at all significant in size."

Bsaically, this is the same old (everyone say it with me) microbenchmarking fallacy.

To draw a whole bunch of unique pixels to a fast frame buffer with no applicable hardware assist its likely for instance that simple mapping the frame buffer using NIO and using the main processor will be a good candidate.  OTOH for a single pixel the over-head in setting it up might not be worth it.

Similarly the architecture of your platform and its capabilities will have a big impact on the answer to this question.  

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #15 - Posted 2004-11-22 22:55:17 »

In that regard, I think the fault is with the question =)

Does zingbat realy want to modify just 1 pixel, or does he want to know the fastest way to manipulate many pixels, each individually.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline zingbat

Senior Member




Java games rock!


« Reply #16 - Posted 2004-11-23 13:18:33 »

The question is exactly the question i wanted to make. The fastest way to draw a pixel. This means im stuck with an atomic operation like DrawPixel(x,y).
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #17 - Posted 2004-11-23 21:28:04 »

So this was a hypothetical, not practical question?

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #18 - Posted 2004-11-23 23:42:47 »

Quote
So this was a hypothetical, not practical question?


Yes.

g.fillRect(x,y,0,0); Tongue

弾幕 ☆ @mahonnaiseblog
Offline zingbat

Senior Member




Java games rock!


« Reply #19 - Posted 2004-11-24 07:23:22 »

Quote
So this was a hypothetical, not practical question?


It was a pratical question but in the sense of having restrictions that aren't pratical. Grin

Like the use of the DrawPixel method that is required for the implemention of classic algorithms like drawLine or fillPolygon.
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #20 - Posted 2004-11-24 11:04:43 »

Quote


Yes.

g.fillRect(x,y,0,0); Tongue


0,0? Huh

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #21 - Posted 2004-11-24 11:35:27 »

Quote


0,0? Huh


Yes. 1,1 would be a 2x2 rect. Pixel bounding stuff is funny, isn't it? Wink

弾幕 ☆ @mahonnaiseblog
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #22 - Posted 2004-11-24 12:31:00 »

Quote

Fills the specified rectangle. The left and right edges of the rectangle are at x and x + width - 1. The top and bottom edges are at y and y + height - 1. The resulting rectangle covers an area width pixels wide by height pixels tall. The rectangle is filled using the graphics context's current color.


So width,height of 0,0 will (or atleast *should*) cover no pixels.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (16 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (33 views)
2014-08-22 19:31:30

atombrot (42 views)
2014-08-19 09:29:53

Tekkerue (41 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (26 views)
2014-08-16 06:20:21

Tekkerue (37 views)
2014-08-16 06:12:11

Rayexar (73 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!