# HG changeset patch # User John Tsiombikas # Date 1403053982 -10800 # Node ID 73b5f2e5d18a0a8d3550efedc871c076ab90def1 # Parent 850be43b3135f382fd402508d1b8055c77fa06d6 first triangle on screen diff -r 850be43b3135 -r 73b5f2e5d18a src/config.h --- a/src/config.h Mon Jun 16 22:01:45 2014 +0300 +++ b/src/config.h Wed Jun 18 04:13:02 2014 +0300 @@ -5,6 +5,4 @@ #define WIDTH 160 #define HEIGHT 128 -#define SDLSCALE 2 - #endif /* CONFIG_H_ */ diff -r 850be43b3135 -r 73b5f2e5d18a src/game.c --- a/src/game.c Mon Jun 16 22:01:45 2014 +0300 +++ b/src/game.c Wed Jun 18 04:13:02 2014 +0300 @@ -1,3 +1,4 @@ +#include "config.h" #include "game.h" #include "gbasys.h" #include "polyfill.h" @@ -7,15 +8,23 @@ static const pvec3 poly[] = { {X16INT(80), X16INT(10), 0}, {X16INT(140), X16INT(100), 0}, - {X16INT(40), X16INT(800), 0} + {X16INT(40), X16INT(80), 0} }; void game_draw(void) { + int i; clear_buffer(back_buffer, 0); draw_poly(3, poly, 0xffff); + for(i=0; i> 16; + int y = poly[i].y >> 16; + + ((uint16_t*)back_buffer->pixels)[y * WIDTH + x] = RGB(0, 255, 0); + } + flip(); } diff -r 850be43b3135 -r 73b5f2e5d18a src/main_sdl.c --- a/src/main_sdl.c Mon Jun 16 22:01:45 2014 +0300 +++ b/src/main_sdl.c Wed Jun 18 04:13:02 2014 +0300 @@ -13,14 +13,23 @@ static SDL_Surface *surf; static struct pixel_buffer bbuf; static unsigned int keystate; +static int sdlscale = 2; int main(void) { - int i, j; + int i, j, k, l; + char *env; + + if((env = getenv("SDLSCALE"))) { + if(!(sdlscale = atoi(env))) { + fprintf(stderr, "invalid SDLSCALE envvar value (%s)\n", env); + sdlscale = 2; + } + } SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE); - if(!(surf = SDL_SetVideoMode(WIDTH * SDLSCALE, HEIGHT * SDLSCALE, 16, SDL_SWSURFACE))) { + if(!(surf = SDL_SetVideoMode(WIDTH * sdlscale, HEIGHT * sdlscale, 16, SDL_SWSURFACE))) { fprintf(stderr, "failed to initialize graphics\n"); return 1; } @@ -58,10 +67,16 @@ for(i=0; i +#include #include "polyfill.h" #include "fixed.h" #include "gbasys.h" @@ -32,29 +33,34 @@ lidx[1] = topidx ? topidx - 1 : num - 1; ridx[1] = (topidx + 1) % num; - if(ridx[1] < lidx[1]) { + if(verts[ridx[1]].x < verts[lidx[1]].x) { return; /* backface (CCW) */ } lx = rx = verts[lidx[0]].x; + /* TODO handle ldy == 0 or rdy == 0 */ ldy = verts[lidx[1]].y - verts[lidx[0]].y; ldxdy = x16div(verts[lidx[1]].x - lx, ldy); - rdy = verts[ridx[1]].y - verts[ridx[1]].y; + rdy = verts[ridx[1]].y - verts[ridx[0]].y; rdxdy = x16div(verts[ridx[1]].x - rx, rdy); start = topy >> 16; end = boty >> 16; + if(end >= HEIGHT) end = HEIGHT - 1; + y = topy; for(i=start; i> 16); - x1 = rx >= WIDTH ? WIDTH - 1 : (rx >> 16); + x1 = (rx >> 16) >= WIDTH ? WIDTH - 1 : (rx >> 16); - fill_scanline(i, x0, x1, color); + if(i >= 0 && x1 > x0) { + fill_scanline(i, x0, x1, color); + } if(y >= verts[lidx[1]].y) { lidx[0] = lidx[1]; @@ -77,6 +83,7 @@ lx += ldxdy; rx += rdxdy; + y += 65536; } } diff -r 850be43b3135 -r 73b5f2e5d18a src/sdlsys/gbasys.h --- a/src/sdlsys/gbasys.h Mon Jun 16 22:01:45 2014 +0300 +++ b/src/sdlsys/gbasys.h Wed Jun 18 04:13:02 2014 +0300 @@ -8,15 +8,15 @@ void *pixels; }; -extern struct pixel_buffer *back_buffer; +extern struct pixel_buffer *back_buffer, *front_buffer; #define RGB(r, g, b)\ - ((((b) >> 3) & 0x1f) << 10) |\ - ((((g) >> 3) & 0x1f) << 5) |\ + ((((b) >> 3) & 0x1f) << 11) |\ + ((((g) >> 2) & 0x3f) << 5) |\ (((r) >> 3) & 0x1f) -#define GET_R(c) ((((c) >> 10) & 0x1f) << 3) -#define GET_G(c) ((((c) >> 5) & 0x1f) << 3) +#define GET_R(c) ((((c) >> 11) & 0x1f) << 3) +#define GET_G(c) ((((c) >> 5) & 0x3f) << 2) #define GET_B(c) (((c) & 0x1f) << 3) /* defined in main_sdl.c */