Skip to content

Instantly share code, notes, and snippets.

View obj_export.cpp
std::ofstream aFile ( "Mesh.obj" );
for (int i = 0; i < aMesh->numVertices(); ++i) {
aFile << "v " << aMesh->vertices()[i].x() << " "
<< aMesh->vertices()[i].y() << " "
<< aMesh->vertices()[i].z() << std::endl;
}
for (int i = 0; i < aMesh->numVertices(); ++i) {
aFile << "vn " << aMesh->normals()[i].x() << " "
@hb3p8
hb3p8 / ImGuiHandler.cpp
Created Jan 29, 2016
ImGui OSG wrapper
View ImGuiHandler.cpp
#include <ImGuiHandler.hpp>
#include <imgui/imgui.h>
#include <iostream>
using namespace sf;
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
// If text or lines are blurry when integrating ImGui in your engine:
@hb3p8
hb3p8 / pattern.hpp
Created Apr 28, 2016
C++14 pattern matching
View pattern.hpp
/*
std::string s = "12";
cout << match(s
,[](int& i) { return "int"; }
,[](bool& b) { return "bool"; }
,[](std::string& s) -> auto& { s += " GAV"; return s; }
,[](auto j) { cout << "default one"; return j; }
);
*/
@hb3p8
hb3p8 / markdeep.js
Created Jun 22, 2016
Markdeep with localized keywords
View markdeep.js
/**
markdeep.js
Version 0.12
Copyright 2015-2016, Morgan McGuire, http://casual-effects.com
All rights reserved.
-------------------------------------------------------------
See http://casual-effects.com/markdeep for documentation on how to
View progress.cpp
float aProgress = 0.0;
while (aProgress < 1.0) {
int aBarWidth = 70;
std::cout << "[";
int aPos = (int) (aBarWidth * aProgress);
for (int i = 0; i < aBarWidth; ++i) {
if (i < aPos) std::cout << "=";
else if (i == aPos) std::cout << ">";
else std::cout << " ";
View oit.py
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright (c) 2015, Nicolas P. Rougier. All Rights Reserved.
# Distributed under the (new) BSD License.
# -----------------------------------------------------------------------------
# This is a python implementation of the "Weighted Blended Order-Independent
# Transparency" technique by Morgan McGuire and Louis Bavoil
#
# This implementation use the glumpy python framework available from:
View docker_devicemapper.md

Warning: the following will delete all your containers and all your images. Make sure that you backup any precious data!

Remember what we said above: Docker will create the data and metadata files if they don’t exist. So the solution is pretty simple: just create the files for Docker, before starting it!

  • Stop the Docker daemon, because we are going to reset the storage plugin, and if we remove files while it is running, Bad Things Will Happen©.
  • Wipe out /var/lib/docker. Warning: as mentioned above, this will delete all your containers all all your images.
  • Create the storage directory: mkdir -p /var/lib/docker/devicemapper/devicemapper.
  • Create your pool: dd if=/dev/zero of=/var/lib/docker/devicemapper/devicemapper/data bs=1G count=0 seek=250 will create a sparse file of 250G. If you specify bs=1G count=250 (without the seek option) then it will create a normal file (instead of a sparse file).
View shader_binary.cpp
const size_t MAX_SIZE = 1<<24;
char* binary = new char[MAX_SIZE];
GLenum format;
GLint length;
theGlContext->core44->glGetProgramBinary (myRaytraceProgram->ProgramId(), MAX_SIZE, &length, &format, binary);
std::ofstream file ("D:/asm.bin", ios::out | ios::binary );
file.write (binary, length);
file.close();
View triangle_intersect_x4.glsl
else if (aData.x < 0) // leaf node (containg triangles)
{
ivec4 aTrg0 = texelFetch (uGeometryTriangTexture, (aData.y + 0) + TRG_OFFSET (aSubTree));
ivec4 aTrg1 = texelFetch (uGeometryTriangTexture, (aData.y + 1) + TRG_OFFSET (aSubTree));
ivec4 aTrg2 = texelFetch (uGeometryTriangTexture, (aData.y + 2) + TRG_OFFSET (aSubTree));
ivec4 aTrg3 = texelFetch (uGeometryTriangTexture, (aData.y + 3) + TRG_OFFSET (aSubTree));
vec3 aTrg0Vrt0 = texelFetch (uGeometryVertexTexture, aTrg0.x += VRT_OFFSET (aSubTree)).xyz;
vec3 aTrg0Vrt1 = texelFetch (uGeometryVertexTexture, aTrg0.y += VRT_OFFSET (aSubTree)).xyz;
vec3 aTrg0Vrt2 = texelFetch (uGeometryVertexTexture, aTrg0.z += VRT_OFFSET (aSubTree)).xyz;
View perlin3d.cpp
struct Noise3D
{
static const int size = 8;
sf::mesh::RealVector3 gradients[size][size][size];
float Drop(float dist)
{
float val = fabs (dist);