purebasic
Code: Select all
#screenwidth = 640
#screenheight = 480
InitSprite()
OpenWindow(0, 0, 0, #screenwidth, #screenheight, "PB Drawing", #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget)
OpenWindowedScreen(WindowID(0), 0, 0, #screenwidth, #screenheight, 0, 0, 0, #PB_Screen_NoSynchronization)
bufferaddress.i = 0
StartDrawing(ScreenOutput())
bufferaddress = DrawingBuffer()
StopDrawing()
fpscounter.i = 0
timer.i = 0
fps.i = 0
frames.i = 0
totalTime.l = 0
curTime.l = ElapsedMilliseconds()
Repeat
lastTime = curTime
curTime = ElapsedMilliseconds()
totalTime + (curTime - lastTime)
If( totalTime > 1000 )
totalTime - 1000
fps = frames
frames = 0
EndIf
frames + 1
ClearScreen(0)
StartDrawing(ScreenOutput())
For i = 0 To 20
Box(Random(320), Random(240), Random(320), Random(240), Random($FFFFFF) )
Next i
DrawText(20,430,Str(fps))
StopDrawing()
FlipBuffers()
; If ElapsedMilliseconds() > timer+1000
; PrintN("fps: "+Str(fpscounter))
; fpscounter = 0
; timer = ElapsedMilliseconds()
; EndIf
;
; fpscounter + 1
Until WindowEvent() = #PB_Event_CloseWindow
Code: Select all
import java.awt.*;
import java.awt.image.*;
import java.util.Enumeration;
import java.util.Random;
import javax.swing.JFrame;
/*
* This is an example of a simple windowed render loop
*/
public class SimpleWindowedGame extends Canvas {
public static void main( String[] args ) {
// Create game window...
JFrame app = new JFrame();
app.setIgnoreRepaint( true );
app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
// Create canvas for painting...
Canvas canvas = new Canvas();
canvas.setIgnoreRepaint( true );
canvas.setSize( 640, 480 );
// Add canvas to game window...
app.add( canvas );
app.pack();
app.setVisible( true );
// Create BackBuffer...
canvas.createBufferStrategy( 2 );
BufferStrategy buffer = canvas.getBufferStrategy();
// Get graphics configuration...
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
// Create off-screen drawing surface
BufferedImage bi = gc.createCompatibleImage( 640, 480 );
// Objects needed for rendering...
Graphics graphics = null;
Graphics2D g2d = null;
Color background = Color.BLACK;
Random rand = new Random();
// Variables for counting frames per seconds
int fps = 0;
int frames = 0;
long totalTime = 0;
long curTime = System.currentTimeMillis();
long lastTime = curTime;
//int[] pixels;
while( true ) {
try {
// count Frames per second...
lastTime = curTime;
curTime = System.currentTimeMillis();
totalTime += curTime - lastTime;
if( totalTime > 1000 ) {
totalTime -= 1000;
fps = frames;
frames = 0;
}
++frames;
// clear back buffer...
g2d = bi.createGraphics();
g2d.setColor( background );
g2d.fillRect( 0, 0, 639, 479 );
// draw some rectangles...
for( int i = 0; i < 20; ++i ) {
int r = rand.nextInt(256);
int g = rand.nextInt(256);
int b = rand.nextInt(256);
g2d.setColor( new Color(r,g,b) );
int x = rand.nextInt( 640/2 );
int y = rand.nextInt( 480/2 );
int w = rand.nextInt( 640/2 );
int h = rand.nextInt( 480/2 );
g2d.fillRect( x, y, w, h );
}
// display frames per second...
g2d.setFont( new Font( "Courier New", Font.PLAIN, 12 ) );
g2d.setColor( Color.GREEN );
g2d.drawString( String.format( "FPS: %s", fps ), 20, 20 );
// Blit image and flip...
graphics = buffer.getDrawGraphics();
graphics.drawImage( bi, 0, 0, null );
if( !buffer.contentsLost() )
buffer.show();
// Let the OS have a little time...
Thread.yield();
} finally {
// release resources
if( graphics != null )
graphics.dispose();
if( g2d != null )
g2d.dispose();
}
}
}
}
pb directx : ~130 fps
pb opengl : ~275 fps
java : ~1000 fps
java executable : http://demo.ovh.net/en/44d4f05017461b9b ... 32569b38d/


