Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <sys/types.h>
  2. #include <stdlib.h>
  3. #include <libgte.h>
  4. #include <libgpu.h>
  5. #include <libgs.h>
  6.  
  7. DRAWENV     draw;           /*Drawing environment*/
  8. DISPENV     disp;               /*Display environment*/
  9.  
  10. #define OT_LENGTH 1 // the ordertable length
  11. #define PACKETMAX 10000 // the maximum number of objects on the screen (please note that i added more than on the hello word example so it can display all the triangles correctly)
  12.  
  13. GsOT myOT[2]; // ordering table header
  14. GsOT_TAG myOT_TAG[2][1<<OT_LENGTH]; // ordering table unit
  15. PACKET GPUPacketArea[2][PACKETMAX]; // GPU packet data
  16.  
  17. unsigned char CurrentBuffer = 0; // holds the current buffer number
  18. unsigned char vertical_spaces = 0; //for the for loop in the Main loop
  19. unsigned short line_y_movement = 0;
  20.  
  21. //Prototypes
  22. void init_graphics(); // inits the GPU
  23. void animated_line(); // draws a line that moves across the screen vertically
  24. void display(unsigned char r, unsigned char g, unsigned char b); // updates the GPU (IE: VRAM/SGRAM/framebuffer), and clear the screen to the given rgb colors
  25.  
  26. //Code flow
  27. int main(){ ResetGraph(0);
  28.     FntLoad(960, 256); // load the font from the BIOS into the framebuffer
  29.     SetDumpFnt(FntOpen(0, 0, 640, 512, 0, 1024)); // screen X,Y | max text length X,Y | autmatic background clear 0,1 | max characters
  30.     init_graphics();
  31.     SetDispMask(1);     /*Enable display (0:inhibit, 1:enable)*/
  32. //Main loop
  33.     while(1){
  34.         FntPrint("                       HI, I AM AT THE TOP OF THE SCREEN                        \n\n");
  35.         FntPrint("              HELLO WORLD\n\n          HTTP://PSXDEV.NET/");
  36.         for(vertical_spaces = 0; vertical_spaces < 58; vertical_spaces++){ //this for loop makes enough vertical spaces so the bottom screen text displays in place
  37.         FntPrint("\n");
  38.         }
  39.         FntPrint("                    HELLOO, I AM AT THE BOTTOM OF THE SCREEN                    ");
  40.         animated_line();
  41.         display(128,93,105); //the parameters are the background's color, each one is rgb respectively
  42.     }
  43.     return(0);
  44. }
  45.  
  46. void init_graphics(){  
  47.     GsInitGraph(640, 511, GsINTER|GsOFSGPU, 0, 0); // set the graphics mode resolutions (GsNONINTER for NTSC, and GsINTER for PAL)
  48.     GsDefDispBuff(0, 0, 0, 0); // tell the GPU to draw from the top left coordinates of the framebuffer
  49.  
  50.     SetVideoMode(1); //Sets video mode to Pal
  51.  
  52.     SetDefDrawEnv(&draw, 0,  0, 640, 511);
  53.     SetDefDispEnv(&disp, 0,  0, 640, 511);
  54.    
  55.     /*Enable drawing on display*/
  56.     draw.dfe = 1;
  57.    
  58.     /*Turn on interlaced mode*/
  59.     disp.isinter = 1;
  60.  
  61.     /*Moves the display offset so they look centered on pal*/
  62.     disp.screen.y = 16;
  63.     disp.screen.x = -8;
  64.     disp.screen.h = 256;
  65.  
  66.     /*Set up ordering table*/
  67.     // init the ordertables
  68.     myOT[0].length = OT_LENGTH;
  69.     myOT[1].length = OT_LENGTH;
  70.     myOT[0].org = myOT_TAG[0];
  71.     myOT[1].org = myOT_TAG[1];
  72.    
  73.     // clear the ordertables
  74.     GsClearOt(0,0,&myOT[0]);
  75.     GsClearOt(0,0,&myOT[1]);
  76. }
  77.  
  78. LINE_F2 F2Line;
  79. void animated_line(){
  80.     SetLineF2(&F2Line);                                                 // initialise the primitive
  81.     setRGB0(&F2Line, 0, 255, 0);                                        // set the fill colour (RGB)
  82.     setSemiTrans(&F2Line, 1);                                           // semi-transparency; 0=off; 1=on
  83.     setXY2(&F2Line, 0, 0 + line_y_movement, 640, 0 + line_y_movement);  // draw 3 lines (3 sets of x/y co-ords)
  84.     DrawPrim(&F2Line);                                                  // copy shape to frame buffer
  85.     GsSortPoly(&F2Line, &myOT[CurrentBuffer], 0);                       // put the polygon into the order table
  86.     if (line_y_movement < 512) line_y_movement++;                       // if line_y_movement is below 512, increment it by 1 each time
  87.     else line_y_movement = 0;                                           // else if it gets to 512, line_y_movement goes back to 0
  88. }
  89.  
  90. void display(unsigned char r, unsigned char g, unsigned char b){
  91.     // refresh the font
  92.     FntFlush(-1);
  93.  
  94.     PutDrawEnv(&draw);
  95.     PutDispEnv(&disp);
  96.  
  97.     // get the current buffer
  98.     CurrentBuffer = GsGetActiveBuff();
  99.    
  100.     // setup the packet workbase
  101.     GsSetWorkBase((PACKET*)GPUPacketArea[CurrentBuffer]);
  102.    
  103.     // clear the ordering table
  104.     GsClearOt(0,0, &myOT[CurrentBuffer]);
  105.    
  106.     // wait for all drawing to finish
  107.     DrawSync(0);
  108.    
  109.     // wait for v_blank interrupt
  110.     VSync(0);
  111.    
  112.     // flip the double buffers
  113.     GsSwapDispBuff();
  114.    
  115.     // clear the ordering table with a background color (R,G,B)
  116.     GsSortClear(r, g, b, &myOT[CurrentBuffer]);
  117.    
  118.     // draw the ordering table
  119.     GsDrawOt(&myOT[CurrentBuffer]);
  120. }