This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

SPower
SPower presents ...

2012/7/31

Fast graphics

This is a demo for some Bresenham algorithms, to draw shapes or lines. Everything is in the Drawer class, the other classes are just for demo.

You're free to use this if you want, but please copy my name from the comment and paste it into your comment/credits, thanks. Also, I'd love to get feedback!

3234 views / 8 in the last 7 days

1 vote | 0 in the last 7 days

Tags: demo with-source graphics fast bresenham

This scenario is a member of: Reusable actors & support classes


open in greenfoot
Your browser does not support the canvas tag.
SPowerSPower

2012/8/3

@Builderboy2005 Line drawing time for Graphics object: 0,002 mills Mine: 0,03 millis or 0,02 mills. Both a line from loc (600,0) to (0,400). So mine is slower :(
UpupzealotUpupzealot

2012/8/4

U can use getAwtImage() to get a BufferedImage of a GreenfootImage creat a Graphics2D on that BufferedImage, and then do your painting on the Graphics2D could be better(I guess :) some set jobs on Graphics 2D could bring the paint jobs to GPU I would chet that out Later
SPowerSPower

2012/8/4

After testing (my above comment), I discovered already that Graphics uses the GPU. And about using the awt Image of a GreenfootImage, 2 things: -I created this scenario to show people some algoritms, being the fastest would be fun, but wasn't my first goal. -I've looked at the code of GreenfootImage, and they use a Graphics2D instance to draw.
UpupzealotUpupzealot

2012/8/4

try sun.java2D.opengl = true; to let openGL work and on windows, Graphics2D world work in DirectX way first try sun.java2d.d3d = true; to get faster maybe
SPowerSPower

2012/8/4

O, didn't know openGL was integrated with java, thanks!
UpupzealotUpupzealot

2012/8/4

It did't work on every OS, but most of them
mjrb4mjrb4

2012/8/4

A note on the performance side of things - if you're trying to go faster than the built in library classes, I can near guarantee that however much work you put in you won't manage it! There's many reasons for this, from the sheer amount of manpower put in, to the close links the guys writing the library code have with the ones implementing the VM, to (as mentioned) the fact that on all common platforms the AWT graphics class will use some form of hardware acceleration. That's not to say this scenario is worthless at all - demonstrating algorithms and how they work is a nice idea for a scenario in all manner of cases. Just don't get too hung up on trying to drive to be the fastest :-)
SPowerSPower

2012/8/4

@mjrb4 I already said that being the fastest wasn't my first goal, but it would be fun if it turned out te be (which will be impossible for me, because as you said, the AWT graphics use hardware). But anyway, thanks for the comment!
A new version of this scenario was uploaded on Thu Aug 23 10:53:55 UTC 2012 -Bug fix in advanched testing -Scenario is now unlocked
A new version of this scenario was uploaded on Thu Aug 23 11:05:32 UTC 2012 Another bug fix in advanched testing

See all comments

Want to leave a comment? You must first log in.

Who likes this?

CrazyGamer1122