[quote=“TehJavaDev,post:1,topic:50704”]
just add -Dsun.java2d.opengl=true and -Dsun.java2d.opengl=false or the other way around and see what it does to your game if you use Graphics2D. thats what it is about. either you use this API or you choose another, or what do you mean by “implement” ?
[quote=“TehJavaDev,post:1,topic:50704”]
afaik, switching them at runtime is not supported, also using System.setProperty() is not always working, just use the jvm args and your set.
you can check what implementation is behind Graphics2D at runtime tho by looking into :
graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
primaryDisplay = graphicsEnvironment.getDefaultScreenDevice();
graphicsConfiguration = primaryDisplay.getDefaultConfiguration();
bufferCapabilities = graphicsConfiguration.getBufferCapabilities();
buffer-caps can be a D3DGraphicsConfig or WGLGraphicsConfig or some proxy implementation.
you can pass the caps directly into createBufferStrategy. at least now you know what’s going on and can ask java the right stuff.
edit
just to complete this : after you create the bufferstrategy, you can grab the Graphics2D reference by :
// an overwritten Canvas class around the constructor :
public class Canvas extends java.awt.Canvas
{
[...]
public Canvas()
{
BufferCapabilities caps = primaryDisplay.getDefaultConfiguration().getBufferCapabilities();
createBufferStrategy(2,caps);
buffer = getBufferStrategy();
g = getDefaultGraphics((Graphics2D)buffer.getDrawGraphics()); // use this to paint your stuff
}
[...]
}
the downside of using Graphics2D like that, it’s not possible to access the “data-buffer” of a “buffered-image” cos’ there is simply none. so reading pixels and setting one by one is not gonna fly (too well).
reading pixels works, many to fail tho’ :
private void readBackBuffer()
{
if(buffer instanceof BltBufferStrategy) // the buffer from above
{
BltBufferStrategy _buffer = (BltBufferStrategy)buffer;
try
{
Method m = _buffer.getClass().getSuperclass().getDeclaredMethod("getBackBuffer");
m.setAccessible(true);
Object v = m.invoke(_buffer);
if(v instanceof VolatileImage)
{
backBuffer = (VolatileImage)v; // at least a Image, we get width height etc.
}
}
catch(NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex)
{
// ...
}
}
}
“showing” such buffer should be something like :
public void swapBuffers()
{
if(!buffer.contentsLost()) buffer.show();
}
finally you when you resize/reshape things you might want check if the buffers graphics2D instance changed and update yours in case.