Skip to content

Commit

Permalink
gpu/lines - horizontal/vertical lines added
Browse files Browse the repository at this point in the history
  • Loading branch information
JaCzekanski committed Sep 30, 2019
1 parent b0a94a8 commit 6f3e0f9
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,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/lines | Draws hexagon using opaque lines - for line rendering comparison
gpu/lines | Draws horizontal and vertical opaque lines - for line rendering comparison
gpu/texture-overflow | Draws textured rectangle with UV overflowing VRAM width
gte-fuzz | Executes GTE opcodes with random parameters, can be used to verify agains real console
spu/test | Check SPU behaviour (data is lost randomly on 32bit access, ok on 16bit)
Expand Down
68 changes: 53 additions & 15 deletions gpu/lines/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,72 @@ void clearScreen() {
fillRect(512, 256, 0x3f1, 256, 0xff, 0xff, 0xff);
}

void circle(int cx, int cy, int scale, int segs) {
const int PI = 4096/2;

LINE_F2 l;

setLineF2(&l);
setRGB0(&l, 0, 0, 0);

const int ANGLE = 2 * PI / segs;
const int H_ANGLE = ANGLE / 2;
for (int s = 0; s < segs; s++) {
l.x0 = cx + icos(ANGLE * s - H_ANGLE) / scale;
l.y0 = cy + isin(ANGLE * s - H_ANGLE) / scale;
l.x1 = cx + icos(ANGLE * s + H_ANGLE) / scale;
l.y1 = cy + isin(ANGLE * s + H_ANGLE) / scale;

DrawPrim(&l);
}
}

int main() {
initVideo();
InitGeom();
printf("\ngpu/lines\n");

for (;;) {
const int PI = 4096/2;
const int CX = SCR_W/2;
const int CY = SCR_H/2;
const int SEGS = 6;
const int ANGLE = 2 * PI / SEGS;
const int H_ANGLE = ANGLE / 2;
const int SCALE = 48;

clearScreen();

LINE_F2 l;

for (int s = 0; s < SEGS; s++) {
LINE_F2 l;
setLineF2(&l);
setRGB0(&l, 0, 0, 0);

setLineF2(&l);
setRGB0(&l, 0, 0, 0);
l.x0 = CX + icos(ANGLE * s - H_ANGLE) / SCALE;
l.y0 = CY + isin(ANGLE * s - H_ANGLE) / SCALE;
l.x1 = CX + icos(ANGLE * s + H_ANGLE) / SCALE;
l.y1 = CY + isin(ANGLE * s + H_ANGLE) / SCALE;
// Horizontal lines
for (int y = 0; y < 10; y++) {
l.x0 = 16;
l.y0 = 16 + y * 8;
l.x1 = 16 + 80;
l.y1 = 16 + y * 8 + y;

DrawPrim(&l);
}

// Vertical lines
for (int x = 0; x < 10; x++) {
l.x0 = 108 + x * 8;
l.y0 = 16;
l.x1 = 108 + x * 8 + x;
l.y1 = 16 + 80;

DrawPrim(&l);
}

// Horizontal lines
for (int y = 0; y < 40; y++) {
l.x0 = 200;
l.y0 = 16 + y * 4;
l.x1 = 200 + 40 - y;
l.y1 = 17 + y * 4;

DrawPrim(&l);
}


circle(SCR_W * 1/4, SCR_H * 4/6, 100, 6);

VSync(0);
}
Expand Down
Binary file modified gpu/lines/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 6f3e0f9

Please sign in to comment.