Advertisement
Guest User

testGraphics.c

a guest
Aug 29th, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.22 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <3ds.h>
  4.  
  5. #define GFX_TOP_WIDTH     400
  6. #define GFX_TOP_HEIGHT    240
  7. #define GFX_BOTTOM_WIDTH  320
  8. #define GFX_BOTTOM_HEIGHT 240
  9.  
  10. u32 kDown;        // keys down
  11. u32 kHeld;        // keys pressed
  12. u32 kUp;          // keys up
  13. u8* fbTopLeft;    // top left screen's framebuffer
  14. u8* fbTopRight;   // top right screen's framebuffer
  15. u8* fbBottom;     // bottom screen's framebuffer
  16. u8* sprites;
  17.  
  18. void resetBuffers()
  19. {
  20.   fbTopLeft = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
  21.   fbTopRight = gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL);
  22.   fbBottom = gfxGetFramebuffer(GFX_BOTTOM, 0, NULL, NULL);
  23.   memset(fbTopLeft, 0, 240 * 400 * 3);
  24.   memset(fbTopRight, 0, 240 * 400 * 3);
  25.   memset(fbBottom, 0, 240 * 320 * 3);
  26. }
  27.  
  28. void init()
  29. {
  30.   srvInit();        // services
  31.   aptInit();        // applets
  32.   hidInit(NULL);    // input
  33.   gfxInitDefault(); // graphics
  34.   gfxSet3D(false);  // stereoscopy (true == on / false == off)
  35.   resetBuffers();
  36. }
  37.  
  38. void quit()
  39. {
  40.   gfxExit();
  41.   hidExit();
  42.   aptExit();
  43.   srvExit();
  44. }
  45.  
  46. void setPixelRGB(u8* buffer, int w, int h, int x, int y, int r, int g, int b)
  47. {
  48.   if((x < w) && (y < h))
  49.   {
  50.     buffer[((h * x) + (h - y)) * 3] = b;
  51.     buffer[(((h * x) + (h - y)) * 3) + 1] = g;
  52.     buffer[(((h * x) + (h - y)) * 3) + 2] = r;
  53.   }
  54. }
  55.  
  56. void setPixelBGR(u8* buffer, int w, int h, int x, int y, int b, int g, int r)
  57. {
  58.   if((x < w) && (y < h))
  59.   {
  60.     buffer[((h * x) + (h - y)) * 3] = b;
  61.     buffer[(((h * x) + (h - y)) * 3) + 1] = g;
  62.     buffer[(((h * x) + (h - y)) * 3) + 2] = r;
  63.   }
  64. }
  65.  
  66. int main()
  67. {
  68.   init();
  69.   // Main loop
  70.   while (aptMainLoop())
  71.   {
  72.     // Wait for next frame
  73.     gspWaitForVBlank();
  74.  
  75.     // Read which buttons are currently pressed or not
  76.     hidScanInput();
  77.     kDown = hidKeysDown();
  78.     kHeld = hidKeysHeld();
  79.     kUp = hidKeysUp();
  80.  
  81.     // If START button is pressed, break loop and quit
  82.     if (kDown & KEY_START)
  83.     {
  84.       break;
  85.     }
  86.  
  87.     //resetBuffers();
  88.  
  89.     setPixelRGB(fbTopLeft, GFX_TOP_WIDTH, GFX_TOP_HEIGHT, 0, 0, 255, 0, 0);
  90.  
  91.     // Flush and swap framebuffers
  92.     gfxFlushBuffers();
  93.     gfxSwapBuffers();
  94.   }
  95.  
  96.   quit();
  97.  
  98.   // Return to hbmenu
  99.   return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement