Hi, Im thinking of how java uses the GPU to process graphics or if it even does it at all and im not to familiar with the subject. This is just java no libraries.
For the moment it doesn’t. You have to use libraries.
Java (the JRE) has the Java2D library included, which does some hardware acceleration behind the scenes. That’s all.
How would I implement java2d into a buffered image renderer?
what do you mean ?
are we talking about rendering buffered images? because if so its just as simple as using a Graphics2D object to g.drawImage(yourbufferedImage,0,0,null);
but if you ofcourse are talking about the infamous pixel rendering method of getting individual pixel data and modifying it i would highly advise against it. It is really slow and you will get stuck using low resolutions.
Would it work with this code.
private void render() {
for(int i = 0; i < pixels.length;i++){
pixels[i] = 0;
}
c.render();
BufferStrategy bs = getBufferStrategy();
if (bs == null) {
createBufferStrategy(2);
return;
}
Graphics g = bs.getDrawGraphics();
screen.clear();
screen.render(xoffset, yoffset);
g.drawImage(image, 0, 0,WIDTH * SCALE, HEIGHT * SCALE, null);
g.dispose();
bs.show();
}
very hard to say from that code snippet as you do not define where pixels[] come from, nor how image instance is defined.
In short, if you are manipulating pixels of an image per tick and rendering that image then you will not get acceleration.
However if you are manipulating pixels in frequently and render that image to an image that has been created via a getCompatibleImage() method and it is that second image that is rendered per tick, it is likely you will get acceleration
Ok , thanks for the help. Does the acceleration improve performance on a large sum or not worth it unless its a large project?
I recently found the following “ancient” tutorial from Chet Hasse (author of “Filthy Rich Clients”).
https://weblogs.java.net/blog/chet/archive/2004/08/toolkitbuffered.html
It is a pretty great entry, going into the various types of images, loading (including from jars), creating from scratch, and use cases such as BackBuffer. I’ve never seen another single article where all this is laid out so clearly.
I’m not confident of my knowledge of what now defines state-of-the-art, but I think that acceleration now includes translucent and transparent graphics, whereas when this was written gpu acceleration of BufferedImages may have only been for opaque images. (Someone correct me if I am wrong here!)
In this Q&A article Haase talks a bit about the underlying architecture and performance of accelerated images/volatile images.
https://weblogs.java.net/blog/chet/archive/2003/09/volatileimage_q.html
If any of this is badly out of date (beyond the obvious case of using Java2D instead of OpenGL), I hope someone points out the short-comings!