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  
  Why render pixel by pixel?  (Read 1551 times)
0 Members and 1 Guest are viewing this topic.
Offline VaPS
« Posted 2013-08-03 18:54:54 »

Watching through some Java beginner game development videos, at least four out of five of them are rendering their game pixel by pixel (using rasters, data buffers and what have you).
My question is exactly why that is, since I haven't been able to find a straight answer by myself.
Thanks in advance from a wondering newbie!

Offline ClickerMonkey

JGO Coder


Medals: 20


Game Engineer


« Reply #1 - Posted 2013-08-03 18:59:02 »

That's odd you found such a high frequency of videos using that method.

It's not a method I would ever recommend to a beginner, but I've written a few [unreleased] libraries that deal with everything at the pixel level... draws images, lines, polygons, etc.

It's really cool and easy to create effects as well, blurring is stupid easy, writing shaders is fun.... it's a waste of time but fun nonetheless.

Offline VaPS
« Reply #2 - Posted 2013-08-03 19:19:03 »

That's odd you found such a high frequency of videos using that method.

It's not a method I would ever recommend to a beginner, but I've written a few [unreleased] libraries that deal with everything at the pixel level... draws images, lines, polygons, etc.

It's really cool and easy to create effects as well, blurring is stupid easy, writing shaders is fun.... it's a waste of time but fun nonetheless.
Is there no performance to gain from it neither? Thanks for the reply

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline relminator
« Reply #3 - Posted 2013-08-04 08:44:59 »

Nope. Hardware is still faster.

www.rel.phatcode.net/junk.php?id=54

There are two simillar effects in there.  1 is a lightet textured twisting cylinder using opengl, the other is just a flat shaded  twisting cylinder using pure software rasters.

The one that uses opengl beats the crap out of the software rendered one.
Offline jonjava
« Reply #4 - Posted 2013-08-04 17:03:56 »

It's potentially a lot faster than java2d - and also in its own way - fun.

OpenGL, which uses the gpu (hardware), is hundreds even thousands of times faster.

Offline ClickerMonkey

JGO Coder


Medals: 20


Game Engineer


« Reply #5 - Posted 2013-08-05 01:12:41 »

The coolest pixel-by-pixel library I've ever used is by far Pulp Core.... VERY fast and had tons of sweet effects... also loved the API. Very powerful.

Offline supaFool

Junior Member


Projects: 2



« Reply #6 - Posted 2013-08-05 03:03:29 »

Rendering Pixel by Pixel, isn't all this happening behind the scenes during Buffering? And really doesn't all rendering happen Pixel by Pixel?
Offline jonjava
« Reply #7 - Posted 2013-08-05 06:35:03 »

Rendering Pixel by Pixel, isn't all this happening behind the scenes during Buffering? And really doesn't all rendering happen Pixel by Pixel?

Yes. But what the OP is referring to is rendering through the CPU having the programmer hands on control over the rendering pixel by pixel.

Of course you can have pixel control with OpenGL as well but it isn't as straightforward and requires OpenGL know-how as opposed to "how do I loop through an array" know-how.

Offline nerb
« Reply #8 - Posted 2013-08-05 07:12:38 »

Manipulating pixels has its place. Take the classics Worms & Lemmings as good examples. You can also use it to achieve some fancy effects whilst using 2d, such as lighting or colourising sprites on the fly. It can be a better, faster, easier and a less restrictive option than lots of Java2d Graphics method calls.

Of course it's not going to be faster than using hardware, but at the end of the day if you are using 2d you are using 2d.

The first half of jonjava's post makes a great point:

It's potentially a lot faster than java2d - and also in its own way - fun.

I particularly agree with the 'fun' part. It is fun, and great to play around with. If you are adept at 2d graphics, and not yet a 3d master, you should have a play around with pixel manipulation.

nerb.  Smiley

Offline gouessej
« Reply #9 - Posted 2013-08-05 10:12:36 »

Of course you can have pixel control with OpenGL as well but it isn't as straightforward and requires OpenGL know-how as opposed to "how do I loop through an array" know-how.
Pixel control with OpenGL is very simple with glDrawPixels, it becomes more complicated with more modern methods (pixel shaders, ...). I used glDrawPixels (JOGL) when mixing raycasting with OpenGL, I passed a direct NIO buffer instead of an array, it was really simple but slower than letting OpenGL handle the rasterization.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ClickerMonkey

JGO Coder


Medals: 20


Game Engineer


« Reply #10 - Posted 2013-08-05 11:32:00 »

Yeah glDrawPixels is slow unfortunately =/

Offline gouessej
« Reply #11 - Posted 2013-08-05 20:56:15 »

glDrawPixels is slow but you still get a noticeable speedup compared to pure Java2D.

Offline relminator
« Reply #12 - Posted 2013-08-06 01:23:53 »

Speaking of which?  What is a good way to do a fullscreen pixel by pixel effect in java2d?

Has to be fast.  I'm going to try some oldskool demo effects in java.

Thanks.
Offline davedes
« Reply #13 - Posted 2013-08-06 03:25:20 »

Probably more realistic for performance to render per-pixel to a small image, and scale it (hoping that Java2D will use hardware scaling).

You can access the backing pixels like so: (for int type images)
1  
int[] argb = ((DataBufferInt)image.getData().getDataBuffer()).getData();

Offline relminator
« Reply #14 - Posted 2013-08-06 04:37:31 »

Thanks! Works with BufferedImage too right?

Also yo nerb below. Smiley
Offline nerb
« Reply #15 - Posted 2013-08-06 04:41:59 »

Thanks! Works with BufferedImage too right?

Yep.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 784
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #16 - Posted 2013-08-06 11:53:04 »

You can access the backing pixels like so: (for int type images)
1  
int[] argb = ((DataBufferInt)image.getData().getDataBuffer()).getData();

That's a copy of the pixels.

Use this instead:
1  
int[] argb = ((DataBufferInt)image.getRaster().getDataBuffer()).getData();

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline ClickerMonkey

JGO Coder


Medals: 20


Game Engineer


« Reply #17 - Posted 2013-08-06 12:07:42 »

Here's my code to efficiently modify the pixels of an image which is drawn on the screen. I think it's the most efficient way.

Initialization at the start of the application or resize of window
1  
2  
3  
4  
5  
6  
int backWidth = ....
int backHeight = ....
int[] pixels = new int[backWidth * backHeight]; // use this
MemoryImageSource renderBufferSource = new MemoryImageSource( backWidth, backHeight, pixels, 0, backWidth );
renderBufferSource.setAnimated( true );
Image renderBuffer = Toolkit.getDefaultToolkit().createImage( renderBufferSource );


After you're done writing to pixels, this updates the image:

1  
renderBufferSource.newPixels();


And drawing of course:

1  
gr.drawImage( renderBuffer, 0, 0, null );


I hope that helps.

Offline relminator
« Reply #18 - Posted 2013-08-06 16:22:24 »

Thanks @riven and @clicker.
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 (15 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 (41 views)
2014-08-19 09:29:53

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

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

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

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

Rayexar (72 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!