Page 1 of 1

Black Screen

Posted: March 28th, 2017, 2:14 am
by jacen
Hi. I've been wanting to make a ps1 game for a while and just found this site not too long ago. After reading a little bit of the documentation, I decided to give it a try. I'm trying to write a small program that displays a purple triangle over a bluish background using libgpu, but whenever I compile and try to run it I just get a black screen.

Being new to this, and new to C in general (being primarily a C# programmer, with a little C++), I'm sure it's some dumb obvious mistake. But I just can't figure it out.

Here's my code:

Code: Select all

#include<sys/types.h>
#include<libgte.h>
#include<libgpu.h>
#include<libetc.h>

#define x_res 320 /* Screen Width */
#define y_res 240 /* Screen Height */

DRAWENV draw[2];
DISPENV disp[2];
RECT clearRect[2];
int dispId = 0;

POLY_F3 tri;

/* Function Declarations */
void InitDispDrawEnvs();
void RenderAndSwap(); /* Handles rendering and swapping buffers */

int main()
{
    InitDispDrawEnvs();

    SetPolyF3(&tri);
    setRGB0(&tri, 200, 0, 255);
    setXY3(&tri, (x_res / 2), (y_res / 2) - 15, (x_res / 2) + 15, (y_res / 2) + 15, (x_res / 2) - 15, (y_res / 2) + 15);

	while(1) /* Main Loop */
	{
        RenderAndSwap();
	}

	return 0;
}

void InitDispDrawEnvs()
{
    SetDefDrawEnv(&draw[0], 0, y_res, x_res, y_res); /* Sets the drawing env */
    SetDefDrawEnv(&draw[1], 0, 0, x_res, y_res);
    SetDefDispEnv(&disp[0], 0, 0, x_res, y_res);     /* Sets the display env */
    SetDefDispEnv(&disp[1], 0, y_res, x_res, y_res);
    PutDrawEnv(&draw[0]);
    PutDispEnv(&disp[0]);

    setRECT(&clearRect[0], 0, y_res, x_res, y_res);
    setRECT(&clearRect[1], 0, 0, x_res, y_res);
}

void RenderAndSwap()
{
    /* Clear only the drawing enviornment */
    ClearImage(&clearRect[dispId], 75, 75, 150);

    /* Draw Primitives */
    DrawPrim(&tri);

    /* Swap the draw and disp envs */
        VSync(0);
        dispId = (dispId + 1) % 2;
        PutDrawEnv(&draw[dispId]);
        PutDispEnv(&disp[dispId]);
}
Any help would be greatly appreciated. Thank you.

Re: Black Screen

Posted: March 28th, 2017, 8:53 am
by Shadow
You haven't setup the GPU. No wonder you're getting nothing on screen :P
Take a look at some example code: http://www.psxdev.net/help/psyq_hello_world.html

Re: Black Screen

Posted: March 28th, 2017, 2:53 pm
by jacen
Oh, ha. Of course I overlooked something so important. I got it working now, thanks for the help. :lol:

I will add for the sake of anyone else who runs into this issue, that the helloworld example uses libgs, so I looked around for the relevant libgpu functions. What I found is that I was missing a call to "ResetGraph(0);" to initialize the drawing engine and "SetDispMask(1);" to allow the image to be displayed on the screen. Once I added those to my initialization code, it started working.