-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86a6f3c
commit 0f804df
Showing
5 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include $(PSN00BSDK)/sdk-common.mk | ||
|
||
TARGET = triangle.elf | ||
LIBS += -lpsxapi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.