mentics
mentics

Reputation: 6999

Fastest way to write every pixel on the screen/window in Java

I want to algorithmically specify every pixel on the screen (full screen) or window to paint in a Java application. I want to do an animation this way.

So, for each pixel, I'll run some type of calculation to determine what color it should be. I'll do this every frame for every pixel.

What is the highest performance (capable of highest frames per second) way to do that?

I understand graphics cards are programmable, but I'd like to stick with just coding in Java for this. If there is a straightforward way to code the algorithms in Java such that they run on the graphics card, that would be great, but I want a solution that does not involve another programming language (which I think OpenCL or such does).

Upvotes: 2

Views: 791

Answers (1)

dinox0r
dinox0r

Reputation: 16039

I've done this type of animations before using a the PixelGrabber and MemoryImageSource combination. Here you have some documentation and samples.

Thats the technique with best performance I know. You usually work in the pixel array (do the frame animation transformations) and then render the pixels in the resulting image (Don't need to invoque getPixel/setPixel methods to set individual pixels, which, in old times, was a great optimization).

Don't have any code sample of my own right now, but I can provide one later if you're interested in using this.

As a side note, old editions of the book Java The Complete Reference make plenty use of this techique for image manipulation examples.

Upvotes: 2

Related Questions