~rabbits/nasu

cc729c884cd9545f1247e73872ad61b5a0373264 — Devine Lu Linvega 2 years ago 33b9371
Implemented render
1 files changed, 23 insertions(+), 9 deletions(-)

M chr6.c
M chr6.c => chr6.c +23 -9
@@ 1,6 1,8 @@
#include <SDL2/SDL.h>
#include <stdio.h>

#define HOR 24
#define VER 16
#define PAD 32
#define ZOOM 4
#define color1 0x000000


@@ 22,8 24,8 @@ typedef struct Brush {

unsigned char buffer[4096];
int colors[] = {color1, color2, color3, color4, color0};
int WIDTH = 128 * ZOOM + PAD * 2;
int HEIGHT = 128 * ZOOM + PAD * 2;
int WIDTH = 8 * HOR * ZOOM + PAD * 2;
int HEIGHT = 8 * VER * ZOOM + PAD * 2;
int FPS = 30;
int GUIDES = 1;
SDL_Window* gWindow = NULL;


@@ 54,10 56,10 @@ void
draw(uint32_t* dst, int id, int color)
{
	int ti = id / 64;
	int px = (ti / 256) * 128;
	int tx = (ti % 16) * 8;
	int ty = ((ti / 16) * 8) % 128;
	int odd = (ti + (ti / 16 + 2)) % 2 == 0;
	int px = (ti / 256) * (8 * HOR);
	int tx = (ti % HOR) * 8;
	int ty = ((ti / HOR) * 8) % 128;
	int odd = (ti + (ti / HOR + 2)) % 2 == 0;
	Point p;
	p.x = px + tx + (id % 8);
	p.y = ty + ((id % 64) / 8);


@@ 86,8 88,8 @@ redraw(void)
void
write(int tx, int ty, int px, int py, int color)
{
	int id = tx + ty * 16;
	int row = py + id * 16;
	int id = tx + ty * HOR;
	int row = py + id * VER;
	if(id > 255)
		return;
	if(color == 0) {


@@ 110,7 112,7 @@ edit(Brush* b)
{
	Point p1;
	setpt(&p1, b->pos.x - PAD, b->pos.y - PAD);
	if(p1.x < 0 || p1.y < 0 || p1.x > 128 * ZOOM || p1.y > 128 * ZOOM)
	if(p1.x < 0 || p1.y < 0 || p1.x > (8 * HOR) * ZOOM || p1.y > (8 * VER) * ZOOM)
		return;
	write(
	    p1.x / (8 * ZOOM),


@@ 178,6 180,15 @@ load(char* path)
}

void
render()
{
	SDL_Surface* surface = SDL_GetWindowSurface(gWindow);
	SDL_RenderReadPixels(gRenderer, NULL, SDL_PIXELFORMAT_ARGB8888, surface->pixels, surface->pitch);
	SDL_SaveBMP(surface, "render.bmp");
	SDL_FreeSurface(surface);
}

void
quit(void)
{
	free(pixels);


@@ 225,6 236,9 @@ dokey(SDL_Event* event, Brush* b)
	case SDLK_e:
		save();
		break;
	case SDLK_r:
		render();
		break;
	case SDLK_h:
		GUIDES = !GUIDES;
		redraw();