GithubHelp home page GithubHelp logo

mare's Introduction

mare (Mini Agnostic REnder)

A simple software based render.

#include "mare.h"
#include <SDL2/SDL.h>
#include <stdio.h>

int main(void) {
	SDL_Init(SDL_INIT_VIDEO);
	SDL_Window *window;
	SDL_Renderer *render;

	mare_t *m = mare_create(0);

	SDL_CreateWindowAndRenderer(640, 380, SDL_WINDOW_SHOWN, &window, &render);
	SDL_SetWindowTitle(window, "mare");

	SDL_Event event;
	SDL_Texture *tex = SDL_CreateTexture(render, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STREAMING, SCREEN_WIDTH, SCREEN_HEIGHT);
	float x;
	float time = 0.f;
	while (event.type != SDL_QUIT) {
		SDL_PollEvent(&event);
		mare_begin(m);
		mare_clear(m, 0xff000000);
		mare_line(m, 0, 0, 32, 32);
		mare_rect(m, 32, 32, 16, 16);
		mare_rectfill(m, 32, 48, 16, 16);
		time += 0.01f;
		x = sinf(time) * 16;

		vertex_t v[6] = {
			{ x+64, 16, 0xff0000ff, 0, 0 },
			{ x+48, 32, 0xff00ff00, 0, 0 },
			{ x+80, 32, 0xffff0000, 0, 0 },
			{ x+64, 48, 0xff0000ff, 0, 0 },
			{ x+48, 32, 0xff00ff00, 0, 0 },
			{ x+80, 32, 0xffff0000, 0, 0 }
		};
		mare_polygon(m, MARE_TRIANGLES, 2, v);

		const char* px = mare_end(m);
		SDL_SetRenderDrawColor(render, 0, 255, 0, 255);
		SDL_RenderClear(render);
		SDL_SetRenderDrawColor(render, 255, 255, 255, 255);
		void *data;
		int pitch;
		SDL_LockTexture(tex, NULL, &data, &pitch);
		memcpy(data, px, sizeof(color_t) * SCREEN_SIZE);
		SDL_UnlockTexture(tex);
		SDL_RenderCopy(render, tex, NULL, NULL);
		SDL_RenderPresent(render);
	}
	
	mare_destroy(m);
	SDL_DestroyWindow(window);
	SDL_DestroyRenderer(render);
	SDL_Quit();

	return 0;
}
Screen.recording.2022-08-25.17.13.15.webm

mare's People

Contributors

canoi12 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.