Skip to content

Commit

Permalink
gpu/triangle drawing test
Browse files Browse the repository at this point in the history
  • Loading branch information
JaCzekanski committed Oct 27, 2019
1 parent 86a6f3c commit 0f804df
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ IMAGES = gpu/bandwidth \
gpu/benchmark \
gpu/quad \
gpu/transparency \
gpu/triangle \
gpu/lines \
gpu/rectangles \
gpu/texture-overflow \
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gpu/bandwidth | Measure GPU/VRAM bandwidth
gpu/benchmark | Simple GPU test to benchmark rasteriser
gpu/quad | Semi-transparent polygon commands - for testing fill rules and transparency handling
gpu/transparency | Draws rectangles with 4 semi-transparent blending modes
gpu/triangle | Draws Gouroud shaded equilateral triangle
gpu/lines | Draws lines using different modes - for verifying Bresenham implementation, color blending, polyline handling
gpu/rectangles | Draws all combinations of Rectangle commands
gpu/texture-overflow | Draws textured rectangle with UV overflowing VRAM width
Expand Down
4 changes: 4 additions & 0 deletions gpu/triangle/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include $(PSN00BSDK)/sdk-common.mk

TARGET = triangle.elf
LIBS += -lpsxapi
94 changes: 94 additions & 0 deletions gpu/triangle/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include <stdio.h>
#include <stdlib.h>
#include <psxgpu.h>

DISPENV disp;
DRAWENV draw;

#define SCR_W 320
#define SCR_H 240

#define SQRT3_2 0.866025f

void setResolution(int w, int h)
{
SetDefDispEnv(&disp, 0, 0, w, h);
SetDefDrawEnv(&draw, 0, 0, 1024, 512);

PutDispEnv(&disp);
PutDrawEnv(&draw);
}

void initVideo()
{
ResetGraph(0);
setResolution(SCR_W, SCR_H);
SetDispMask(1);
}

void clearScreen()
{
FILL f;
setFill(&f);
setRGB0(&f, 0xff, 0xff, 0xff);
setXY0(&f, 0, 0);
setWH(&f, 1023, 256);

DrawPrim(&f);

setXY0(&f, 0, 256);
setWH(&f, 1023, 256);

DrawPrim(&f);
}

void drawTriangle(int cx, int cy, int a)
{
float h = a * SQRT3_2;

int x[3], y[3];
x[0] = cx - a / 2; y[0] = cy + h / 2;
x[1] = cx + a / 2; y[1] = cy + h / 2;
x[2] = cx; y[2] = cy - h / 2;

POLY_G3 p;
setPolyG3(&p);
setRGB0(&p, 255, 0, 0);
setRGB1(&p, 0, 255, 0);
setRGB2(&p, 0, 0, 255);
setXY3(&p,
x[0], y[0],
x[1], y[1],
x[2], y[2]
);
DrawPrim(&p);
}

void setDithering(int dithering)
{
DR_TPAGE e;
unsigned short texpage = getTPage(/* bitcount - do not care */0, /* semi-transparency mode */ 0, /*x*/0, /*y*/0);
setDrawTPage(&e, /* Drawing to display area */ 1, dithering, texpage);
DrawPrim(&e);
}

int main()
{
initVideo();
printf("\ngpu/triangle (shading test)\n");

for (;;)
{
clearScreen();

setDithering(0);
drawTriangle(SCR_W/2, SCR_H/2, 240);
drawTriangle(768, 256, 500);

setDithering(1);
drawTriangle(SCR_W/2, SCR_H + SCR_H/2, 240);

VSync(0);
}
return 0;
}
Binary file added gpu/triangle/vram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0f804df

Please sign in to comment.