Moin
I started to write a 2D engine for Games/Appz a few days before.
First I did was to create a window, get the GraficsConfiguration and build some Bufferstrategy.
I read some books about 3D grafics in C for an basic understanding of technics to be used for fast and smooth moving pics, so I decided to build the BufferStrat with PageFlipping.
To do that I set the window I used to exklusiv fullscreenmode.
After that I wrote a simple FPS counter and start the application.
Code of the method which draws (and sry for german comments, but I think all of u will understand the code without them g):
`
public void run()
{
long lTime = System.currentTimeMillis();
int nOldFPS = 0;
int nFPS = 0;
Color ClrBack = GrfxScreen.getColor();
while(bRunning)
{
if(Backbuffer.getCapabilities().getFlipContents()!=BufferCapabilities.FlipContents.BACKGROUND)
{
GrfxScreen.fillRect(0,0,nWidth, nHeight);
}// if(...) -> Falls die Bufferstrategier nicht selbst den Backbuffer saeubert machen wir das
// ---- Draw here ----
GrfxScreen.setColor(Color.green);
GrfxScreen.drawString("Pageflipping: " + this.getBufferStrategy().getCapabilities().isPageFlipping(),0,40);
GrfxScreen.drawString("Fullscreen: " + this.bFullscreen,0,60);
GrfxScreen.drawString("VRAM: " + this.getGraphicsConfiguration().getDevice().getAvailableAcceleratedMemory(),0,80);
GrfxScreen.drawString("FlipContent: " + Backbuffer.getCapabilities().getFlipContents(),0,100);
GrfxScreen.drawString("Bounds: " + this.nWidth + " x " + this.nHeight,0,120);
GrfxScreen.setColor(Color.blue);
GrfxScreen.drawString("F Fullscreen <-> Window",0,140);
GrfxScreen.drawString("P PageFlipping oder -Blitting",0,160);
GrfxScreen.drawString("Esc Ende",0,180);
GrfxScreen.setColor(ClrBack);
// ---- End Drawing ----
// Anzahl Frames der letzten Sekunde anzeigen
GrfxScreen.setColor(Color.red);
GrfxScreen.drawString("FPS: "+nOldFPS, 0,20);
GrfxScreen.setColor(ClrBack);
nFPS++;
if(lTime+1000 <= System.currentTimeMillis())
{
lTime = System.currentTimeMillis();
nOldFPS = nFPS;
nFPS = 0;
}// if(...) -> Jede Sekunde Anzahl FPS der letzten Sek updaten
if(bRunning)Backbuffer.show();
}// while(bRunning)
}// public void run()
Then I wonder: it ran, but really slow (60FPS). So I tried a few things (using a frame and not a window and such things) and finally I changed the BufferStrat from PageFlipping to PageBlitting (first the flipping, then the blitting strat):
if(bFlipping && bFullscreen)
{
BufferCaps = new BufferCapabilities(new ImageCapabilities(true),
new ImageCapabilities(true),
BufferCapabilities.FlipContents.BACKGROUND);
}// if(…) -> Soll mit PageFlipping laufen?
else
{
bFlipping = false;
BufferCaps = new BufferCapabilities(new ImageCapabilities(true),
new ImageCapabilities(true),
null);
}// else -> PageBlitting … ist aus irgend einem Grund schneller als PageFlipping
`
And after that change the frames per minute increased to 220.
So is that normal? I thought PageFlipping is the fastest way, cause the graficcard just needs to change the pointer to a nother place in VRAM.
So finally, have i made a mistake (the full prog lists 240 lines, so I wouldn’t post it completely, but here is the link www.tzi.de/~oherdin/java/GrfxTest.rar), or ist PageFlipping in Java really slower then Blitting?
I use a Pentium M 1.7GHz 512MB RAM with Radeon 7500M on Windows XP SP1 with jre 1.4.2_02.
Don’t try to run the code under Linux, you will run into problems with your mice and keyboard.
P.S.: I’m a first poster, but doesn’t find something about that topic somewhere else in the forum, so hope it is placed correct here
P.P.S.: oh, and happy Xmas