2018-11-17 13:34:15 +01:00
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#define S3L_PIXEL_FUNCTION drawPixel
|
|
|
|
|
|
|
|
#include "s3l.h"
|
|
|
|
|
|
|
|
#define SCREEN_WIDTH 640
|
|
|
|
#define SCREEN_HEIGHT 480
|
|
|
|
|
|
|
|
uint32_t pixels[SCREEN_WIDTH * SCREEN_HEIGHT];
|
|
|
|
|
|
|
|
uint32_t frame = 0;
|
|
|
|
|
|
|
|
void clearScreen()
|
|
|
|
{
|
|
|
|
memset(pixels,0,SCREEN_WIDTH * SCREEN_HEIGHT * sizeof(uint32_t));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void setPixel(int x, int y, uint8_t red, uint8_t green, uint8_t blue)
|
|
|
|
{
|
|
|
|
uint32_t r = red & 0x000000FF;
|
2018-11-17 16:40:44 +01:00
|
|
|
r = r << 24;
|
2018-11-17 13:34:15 +01:00
|
|
|
|
|
|
|
uint32_t g = green & 0x000000FF;
|
2018-11-17 16:40:44 +01:00
|
|
|
g = g << 16;
|
2018-11-17 13:34:15 +01:00
|
|
|
|
|
|
|
uint32_t b = blue & 0x000000FF;
|
2018-11-17 16:40:44 +01:00
|
|
|
b = b << 8;
|
2018-11-17 13:34:15 +01:00
|
|
|
|
|
|
|
pixels[y * SCREEN_WIDTH + x] = r | g | b;
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawPixel(S3L_PixelInfo *p)
|
|
|
|
{
|
2018-11-17 16:40:44 +01:00
|
|
|
setPixel(p->x,p->y,255,255,255);
|
2018-11-17 13:34:15 +01:00
|
|
|
}
|
|
|
|
|
2018-11-17 16:40:44 +01:00
|
|
|
const int16_t test_coords[] =
|
|
|
|
{
|
|
|
|
100,100, 99,101, 101,101, // 0, small triangle
|
|
|
|
90,50, 100,10, 300,80, // 1, arbitrary
|
|
|
|
100,30, 20,50, 40,80 // 2, arbitrary
|
|
|
|
};
|
|
|
|
|
2018-11-17 13:34:15 +01:00
|
|
|
void draw()
|
|
|
|
{
|
|
|
|
clearScreen();
|
|
|
|
|
2018-11-17 16:40:44 +01:00
|
|
|
int c = 0;
|
|
|
|
|
|
|
|
int
|
|
|
|
x0 = test_coords[6 * c],
|
|
|
|
y0 = test_coords[6 * c + 1],
|
|
|
|
x1 = test_coords[6 * c + 2],
|
|
|
|
y1 = test_coords[6 * c + 3],
|
|
|
|
x2 = test_coords[6 * c + 4],
|
|
|
|
y2 = test_coords[6 * c + 5];
|
|
|
|
|
|
|
|
S3L_drawTriangle(x0,y0,x1,y1,x2,y2);
|
2018-11-17 13:34:15 +01:00
|
|
|
|
2018-11-17 16:40:44 +01:00
|
|
|
/*
|
|
|
|
setPixel(x0,y0,255,0,0);
|
|
|
|
setPixel(x1,y1,255,0,0);
|
|
|
|
setPixel(x2,y2,255,0,0);
|
|
|
|
*/
|
2018-11-17 13:34:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
SDL_Window *window = SDL_CreateWindow("test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
|
|
|
|
SDL_Renderer *renderer = SDL_CreateRenderer(window,-1,0);
|
|
|
|
SDL_Texture *texture = SDL_CreateTexture(renderer,SDL_PIXELFORMAT_RGBX8888, SDL_TEXTUREACCESS_STATIC, SCREEN_WIDTH, SCREEN_HEIGHT);
|
|
|
|
SDL_Surface *screenSurface = SDL_GetWindowSurface(window);
|
|
|
|
SDL_Event event;
|
|
|
|
|
|
|
|
int running = 1;
|
|
|
|
|
|
|
|
while (running)
|
|
|
|
{
|
|
|
|
draw();
|
|
|
|
SDL_UpdateTexture(texture,NULL,pixels,SCREEN_WIDTH * sizeof(uint32_t));
|
|
|
|
|
|
|
|
while (SDL_PollEvent(&event))
|
|
|
|
{
|
|
|
|
switch (event.type)
|
|
|
|
{
|
|
|
|
case SDL_QUIT:
|
|
|
|
running = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_RenderClear(renderer);
|
|
|
|
SDL_RenderCopy(renderer,texture,NULL,NULL);
|
|
|
|
SDL_RenderPresent(renderer);
|
|
|
|
|
|
|
|
frame++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|