Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <stdlib.h>
- #include <libgte.h>
- #include <libgpu.h>
- #include <libgs.h>
- DRAWENV draw; /*Drawing environment*/
- DISPENV disp; /*Display environment*/
- #define OT_LENGTH 1 // the ordertable length
- #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)
- GsOT myOT[2]; // ordering table header
- GsOT_TAG myOT_TAG[2][1<<OT_LENGTH]; // ordering table unit
- PACKET GPUPacketArea[2][PACKETMAX]; // GPU packet data
- unsigned char CurrentBuffer = 0; // holds the current buffer number
- unsigned char vertical_spaces = 0; //for the for loop in the Main loop
- unsigned short line_y_movement = 0;
- //Prototypes
- void init_graphics(); // inits the GPU
- void animated_line(); // draws a line that moves across the screen vertically
- 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
- //Code flow
- int main(){ ResetGraph(0);
- FntLoad(960, 256); // load the font from the BIOS into the framebuffer
- SetDumpFnt(FntOpen(0, 0, 640, 512, 0, 1024)); // screen X,Y | max text length X,Y | autmatic background clear 0,1 | max characters
- init_graphics();
- SetDispMask(1); /*Enable display (0:inhibit, 1:enable)*/
- //Main loop
- while(1){
- FntPrint(" HI, I AM AT THE TOP OF THE SCREEN \n\n");
- FntPrint(" HELLO WORLD\n\n HTTP://PSXDEV.NET/");
- for(vertical_spaces = 0; vertical_spaces < 58; vertical_spaces++){ //this for loop makes enough vertical spaces so the bottom screen text displays in place
- FntPrint("\n");
- }
- FntPrint(" HELLOO, I AM AT THE BOTTOM OF THE SCREEN ");
- animated_line();
- display(128,93,105); //the parameters are the background's color, each one is rgb respectively
- }
- return(0);
- }
- void init_graphics(){
- GsInitGraph(640, 511, GsINTER|GsOFSGPU, 0, 0); // set the graphics mode resolutions (GsNONINTER for NTSC, and GsINTER for PAL)
- GsDefDispBuff(0, 0, 0, 0); // tell the GPU to draw from the top left coordinates of the framebuffer
- SetVideoMode(1); //Sets video mode to Pal
- SetDefDrawEnv(&draw, 0, 0, 640, 511);
- SetDefDispEnv(&disp, 0, 0, 640, 511);
- /*Enable drawing on display*/
- draw.dfe = 1;
- /*Turn on interlaced mode*/
- disp.isinter = 1;
- /*Moves the display offset so they look centered on pal*/
- disp.screen.y = 16;
- disp.screen.x = -8;
- disp.screen.h = 256;
- /*Set up ordering table*/
- // init the ordertables
- myOT[0].length = OT_LENGTH;
- myOT[1].length = OT_LENGTH;
- myOT[0].org = myOT_TAG[0];
- myOT[1].org = myOT_TAG[1];
- // clear the ordertables
- GsClearOt(0,0,&myOT[0]);
- GsClearOt(0,0,&myOT[1]);
- }
- LINE_F2 F2Line;
- void animated_line(){
- SetLineF2(&F2Line); // initialise the primitive
- setRGB0(&F2Line, 0, 255, 0); // set the fill colour (RGB)
- setSemiTrans(&F2Line, 1); // semi-transparency; 0=off; 1=on
- setXY2(&F2Line, 0, 0 + line_y_movement, 640, 0 + line_y_movement); // draw 3 lines (3 sets of x/y co-ords)
- DrawPrim(&F2Line); // copy shape to frame buffer
- GsSortPoly(&F2Line, &myOT[CurrentBuffer], 0); // put the polygon into the order table
- if (line_y_movement < 512) line_y_movement++; // if line_y_movement is below 512, increment it by 1 each time
- else line_y_movement = 0; // else if it gets to 512, line_y_movement goes back to 0
- }
- void display(unsigned char r, unsigned char g, unsigned char b){
- // refresh the font
- FntFlush(-1);
- PutDrawEnv(&draw);
- PutDispEnv(&disp);
- // get the current buffer
- CurrentBuffer = GsGetActiveBuff();
- // setup the packet workbase
- GsSetWorkBase((PACKET*)GPUPacketArea[CurrentBuffer]);
- // clear the ordering table
- GsClearOt(0,0, &myOT[CurrentBuffer]);
- // wait for all drawing to finish
- DrawSync(0);
- // wait for v_blank interrupt
- VSync(0);
- // flip the double buffers
- GsSwapDispBuff();
- // clear the ordering table with a background color (R,G,B)
- GsSortClear(r, g, b, &myOT[CurrentBuffer]);
- // draw the ordering table
- GsDrawOt(&myOT[CurrentBuffer]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement