Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
1,186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.65 KB | None | 0 0
  1. int WIDTH;
  2. WIDTH = 1280;
  3. int HEIGHT;
  4. HEIGHT = 960;
  5. int BPP;
  6. BPP = 32;
  7.  
  8. function void setMem(string base, int offset, int value, int width) native 'unsafe_setMem';
  9. function int getMem(string base, int offset, int width) native 'unsafe_getMem';
  10. function int videoInitFramebuffer(int width, int height, int bpp, int fullscreen) native 'unsafe_videoInitFramebuffer';
  11. function void videoDenitFramebuffer() native 'unsafe_videoDeinitFramebuffer';
  12. function int videoCheckEvent() native 'unsafe_videoCheckEvent';
  13. function string videoGrabFramebuffer() native 'unsafe_videoGrabFramebuffer';
  14. function void videoReleaseFramebuffer() native 'unsafe_videoReleaseFramebuffer';
  15.  
  16. function void setPixel(string mem, int x, int y, int r, int g, int b) {
  17.     int color;
  18.     color = (r % 256) * 65536 + (g % 256) *256 + (b % 256);
  19.     setMem(mem, (x + y*WIDTH) * BPP / 8 , color, 4);
  20. }
  21.  
  22. function int timestamp() native 'native_timestamp';
  23.  
  24. int h;
  25. h = 0;
  26. function void drawFrame() {
  27.    string fb;
  28.    fb = videoGrabFramebuffer();
  29.    if (!fb) {
  30.       print('fb', fb, '\n');
  31.       return;
  32.    }
  33.    int y; int x;
  34.     for (y in 0..(HEIGHT-1)) {
  35.         for (x in 0..(WIDTH-1)) {
  36.            setPixel(fb, x, y, (x*x)/256+3*y+h, (y*y)/256+x+h, h);
  37.        }
  38.    }
  39.    videoReleaseFramebuffer();
  40.    h += 1;
  41. }
  42.  
  43.  
  44. if (videoInitFramebuffer(WIDTH, HEIGHT, BPP, 0) == 0) {
  45.    print('Cannot init video\n');
  46.    return;
  47. }
  48.  
  49. int start;
  50. start = timestamp();
  51. int frames;
  52. frames = 0;
  53. while (videoCheckEvent() == 0) {
  54.     drawFrame();
  55.     int fps;
  56.     fps = frames * 1000000 / (timestamp() - start);
  57.     print('FPS ', fps, '\r');
  58.     frames += 1;
  59. }
  60.  
  61.  
  62. videoDenitFramebuffer();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement