Skip to content

Instantly share code, notes, and snippets.

@MaGetzUb
MaGetzUb / shaderc.odin
Last active February 19, 2025 11:33
shaderc (https://github.com/google/shaderc) bindings for odin
package shaderc
import "core:c"
when ODIN_OS == .Windows {
@(export) foreign import lib { "shaderc_shared.lib" }
} else {
@(export) foreign import lib { "system:libshaderc_shared.so" }
}
source_language :: enum {
@MaGetzUb
MaGetzUb / triraster.cpp
Last active November 22, 2023 05:09
Triangle rasterisation with pixel plotting callback
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"
#include <functional>
#include <string_view>
#ifdef __EMSCRIPTEN__
EM_JS(const char*, WebNavigate, (const char* str), {
window.location.href = UTF8ToString(str);
});
@MaGetzUb
MaGetzUb / colorTemp.glsl
Last active August 30, 2021 21:35
Returns color based on temperature of black-body.
//https://en.wikipedia.org/wiki/Black-body_radiation
//Converts color temperature (kelvins, K) into RGB
vec3 colorTemp(float temp) {
temp *= .01;
vec3 c;
c.r = mix(1., clamp(1.2929361861 * pow(temp - 60., -0.1332047592), 0., 1.), step(66., temp));
c.g = mix(clamp(0.39008157877 * log(temp) - 0.6318414437886275, 0., 1.), clamp(1.1298908609 * pow(temp - 60., -0.0755148492), 0., 1.), step(66., temp));
#include "olcPixelGameEngine.h"
#include <vector>
#include <list>
#include <string>
#include <unordered_map>
#include <new>
#include <algorithm>
#include <random>
#include <memory>
@MaGetzUb
MaGetzUb / particles.cpp
Last active April 8, 2019 17:34
A demonstration of simple particle physics in 3D and projecting them in 2D
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"
#include <list>
#include <random>
//By MaGetzUb
//Some helper functions
//Clamps the value between a range ow [Low, High]
@MaGetzUb
MaGetzUb / wavio.cpp
Last active February 3, 2019 09:42
Open / Save WAV files
#include <fstream>
#include <vector>
#include <iostream>
#include <string>
//TODO: More types & features, more error handling and stuff.
std::vector<float> OpenWAV(const std::string& path, int& sampleRate, int& numChannels) {
auto result = std::vector<float>();
@MaGetzUb
MaGetzUb / renderingroutine.cpp
Created August 27, 2018 21:56
Rendering routine
void TilemapEditor::paintEvent(QPaintEvent* e) {
QPainter p(this);
//p.scale(mZoom, mZoom);
p.fillRect(e->rect(), QBrush(Qt::black));
if(!mTilemap->tilesetCount()) return;
int camX = mCameraPosition.x();
int camY = mCameraPosition.y();
Const TileW = 32
Const TileH = 32
Const ScrW = 1280
Const ScrH = 720
FrameLimit 60
Dim Grid(ScrW/TileW, ScrH/TileH) As Integer