Skip to content

Instantly share code, notes, and snippets.

View Twinklebear's full-sized avatar

Will Usher Twinklebear

View GitHub Profile
@Twinklebear
Twinklebear / main.cpp
Created October 30, 2013 20:54
Gamepad whatchamathingy. Requires SDL2. Should work with DInput and XInput, DInput only seems to be picked up as a joystick while XInput works as game controller and joystick.
#include <iostream>
#include <SDL2/SDL.h>
//It seems only XInput controllers are detected as game controllers
void xinputTest();
void dinputTest();
int main(int argc, char **argv){
if (SDL_Init(SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) != 0){
std::cout << "Init failed" << std::endl;
@Twinklebear
Twinklebear / main.cpp
Last active February 18, 2024 02:28
Example of render to texture with SDL2
#include <iostream>
#ifdef __linux__
#include <SDL2/SDL.h>
#elif defined(_WIN32)
#include <SDL.h>
#endif
const int WIN_WIDTH = 640;
const int WIN_HEIGHT = 480;
@Twinklebear
Twinklebear / main.rs
Last active January 15, 2023 16:57
Messing about with Conjugate Gradient in Rust
extern crate sparse_matrix;
use sparse_matrix::{MatrixElement, SparseMatrix};
fn conjugate_gradient(matrix: &SparseMatrix, b: &Vec<f32>) -> Vec<f32> {
let mut r = b.clone();
let mut p = b.clone();
let mut x = Vec::from_elem(b.len(), 0f32);
let mut r_dot_r = [sparse_matrix::dot(&r, &r), 0f32];
let mut step = 0u;
@Twinklebear
Twinklebear / kernel.cl
Last active March 31, 2022 00:51
trying to fake an image2d opencl
__constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP
| CLK_FILTER_NEAREST;
__kernel void processImg(read_only image2d_t srcImg, write_only image2d_t outImg){
//uint offset = get_global_id(1) * 0x4000 + get_global_id(0) * 0x1000;
int2 coord = (int2)(get_global_id(0), get_global_id(1));
uint4 pixel = read_imageui(srcImg, sampler, coord);
write_imageui(outImg, coord, pixel);
}
@Twinklebear
Twinklebear / CMakeLists.txt
Last active May 30, 2020 14:35
SDL2 + TBB Malloc Proxy Repro
cmake_minimum_required(VERSION 3.5)
project(sdl2_test)
find_package(SDL2 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(TBB REQUIRED)
add_executable(sdl2_test
main.cpp)
#include "render_optix.h"
#include <algorithm>
#include <array>
#include <chrono>
#include <cstring>
#include <iostream>
#include <numeric>
#include <cuda.h>
#include <cuda_gl_interop.h>
#include <cuda_runtime_api.h>
uniform int i = 0;
foreach_unique(b in blockID) {
unmasked {
i = i + 1;
}
}
print("unique blocks: %\n", i);
@Twinklebear
Twinklebear / CMakeLists.txt
Last active July 12, 2018 21:04
Simple example of rendering a generated volume with OSPRay
cmake_minimum_required(VERSION 3.0)
project(OspExample)
# To build provide the path to your osprayConfig.cmake included in the OSPRay
# releases to CMake as "-Dospray_DIR=<..>"
# and the path to the embreeConfig.cmake from the Embree releases similarly
# as "-Dembree_DIR=<..>"
find_package(ospray REQUIRED)
include_directories(${OSPRAY_INCLUDE_DIRS})
@Twinklebear
Twinklebear / CMakeLists.txt
Last active June 7, 2018 00:57
OSPRay Transparency Test Case Repro
cmake_minimum_required(VERSION 3.5)
project(osp-transparency-bug)
set(CMAKE_CXX_STANDARD 14)
add_definitions(-DNOMINMAX)
find_package(ospray REQUIRED)
include_directories(${OSPRAY_INCLUDE_DIRS})
add_executable(transparency-test transparency-test.cpp)
@Twinklebear
Twinklebear / sample.cpp
Last active June 4, 2018 16:19
linux performance tracking utility
#include <iostream>
#include <thread>
#include <chrono>
#include <sys/times.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/resource.h>
#include <unistd.h>
#include <fstream>