OutRun/src/src/drawstuff.cc

65 lines
1.6 KiB
C++

#include "../include/drawstuff.h"
#include "../parameters.h"
#include <gint/display.h>
void gint_dhline(int x1, int x2, int y, uint16_t color)
{
if((uint)y >= 224) return;
if(x1 > x2) swap(x1, x2);
if(x1 >= 396 || x2 < 0) return;
if(x1 < 0) x1 = 0;
if(x2 >= 396) x2 = 395;
int offset = 396 * y;
gint_vram[offset + x1] = color;
gint_vram[offset + x2] = color;
x1 = x1 + (x1 & 1);
x2 = (x2 + 1) & ~1;
uint32_t *start = (void *)(gint_vram + offset + x1);
uint32_t *end = (void *)(gint_vram + offset + x2);
uint32_t op = (color << 16) | color;
while(end > start) *--end = op;
};
void drawGrass( int y1, int y2, uint8_t R, uint8_t G, uint8_t B, uint8_t A )
{
uint16_t color = C_RGB(R,G,B);
for (int y=y1; y<=y2; y++) gint_dhline( 0, SCREEN_WIDTH, y, color );
};
void drawPolygon( int x1min, int x1max, int y1, int x2min, int x2max, int y2, uint8_t R, uint8_t G, uint8_t B, uint8_t A )
{
uint16_t color = C_RGB(R,G,B);
float Ddeltay = 1.0f / (float) (y2-y1);
float deltay=0.0f;
for (int y=y1; y<=y2; y++)
{
if (y>0 && y<SCREEN_HEIGHT)
{
float xmin = (float) x1min + (float) (x2min-x1min)*deltay;
float xmax = (float) x1max + (float) (x2max-x1max)*deltay;
gint_dhline( (int) xmin, (int) xmax, y, color );
}
deltay+=Ddeltay;
}
};
void drawSky( void )
{
dclear( C_RGB(0,45,255) );
};
void drawSky( int ymin, int ymax )
{
uint16_t color = C_RGB(0,45,255);
for(int y=ymin; y<=ymax; y++ )
gint_dhline( 0, SCREEN_WIDTH, y, color );
};