Skip to content

Instantly share code, notes, and snippets.

@xophiix
xophiix / digital_glitch_f.glsl
Last active March 25, 2016 09:02
screen signal distort .shader
uniform int byp;
uniform sampler2D tDiffuse;
uniform sampler2D tDisp;
uniform float amount;
uniform float angle;
uniform float seed;
uniform float seed_x;
uniform float seed_y;
uniform float distortion_x;
uniform float distortion_y;
@xophiix
xophiix / renderbuffer_create_on_MIUI3_failed.cpp
Last active August 29, 2015 14:19
my own android gles bug fix and tricks
// MIUI3 not support GL_OES_packed_depth_stencil workaround
glGenRenderbuffers(1, &m_pDepthStencil);
glBindRenderbuffer(GL_RENDERBUFFER, m_pDepthStencil);
static bool supportedPackedDepthStencil = strstr((const char*)glGetString(GL_EXTENSIONS), "GL_OES_packed_depth_stencil") != NULL;
GLenum internalFormat = supportedPackedDepthStencil ? GL_DEPTH24_STENCIL8 : GL_DEPTH_COMPONENT16;
glRenderbufferStorage(GL_RENDERBUFFER, internalFormat, nWidth, nHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_pDepthStencil);
@xophiix
xophiix / align4.cpp
Last active August 29, 2015 14:19
solve pointer alignment bug on ios device
// see http://www.galloway.me.uk/2010/10/arm-hacking-exc_arm_da_align-exception/
// force size to align 4 byte
if ((dataSize & 0x3) != 0) {
dataSize += 4 - (dataSize & 0x3);
}
@xophiix
xophiix / print.cpp
Last active August 29, 2015 14:19
c++11 template
void printf(const char *s)
{
while (*s)
{
if (*s == '%' && *(++s) != '%')
throw std::runtime_error("invalid format string: missing arguments");
std::cout << *s++;
}
}
float Q_rsqrt( float number )
{
long i;
float x2, y;
const float threehalfs = 1.5F;
x2 = number * 0.5F;
y = number;
i = * ( long * ) &y; // evil floating point bit level hacking
i = 0x5f3759df - ( i >> 1 ); // what the fuck?
@xophiix
xophiix / parseCombinedPropertyStr
Created April 2, 2015 12:51
parseCombinedPropertyStr.js
/** 简易属性解释
@param object 访问对象
@param propertyStr 访问属性字符串,仅限于包含若干.或[]的组合,如"p1.p2[3][4].p5"
@param [newValue] 如果不为undefined,则执行 object.propertyStr = newValue
@return value of object.propertyStr if newValue !== undefined
*/
function parseCombinedPropertyStr(object, propertyStr, newValue) {
if (!propertyStr) {
return undefined;
}
$ curl -O ftp://ftp.gnu.org/gnu/ncurses/ncurses-5.9.tar.gz
$ tar -xzvf ncurses-5.9.tar.gz
$ cd ./ncurses-5.9
$ ./configure --prefix=/usr/local \
--without-cxx --without-cxx-binding --without-ada --without-progs --without-curses-h \
--with-shared --without-debug \
--enable-widec --enable-const --enable-ext-colors --enable-sigwinch --enable-wgetch-events \
&& make
$ sudo make install
@xophiix
xophiix / mac_tips
Created October 28, 2014 15:58
some mac tricks
#show invisible files in finder
defaults write com.apple.finder AppleShowAllFiles -bool true
@xophiix
xophiix / get_common_missing_gl_ext.js
Created April 29, 2014 13:47
input several gl extension list file, extract common extensions and differences
/**
* Created with JetBrains WebStorm.
* User: xophiix
* Date: 14-4-24
* Time: 22:58
* To change this template use File | Settings | File Templates.
*/
var passGroup = ["hongmi", "ios-simulator", "ipad2", "lenovo"];
var failGroup = ["htc", "sony", "xiaomi"];
@xophiix
xophiix / printGlExtensions
Created April 29, 2014 13:43
print gl extensions
string extensions = (const char*)glGetString(GL_EXTENSIONS);
set<string> extensionSet;
size_t strStart = 0;
for (size_t i = 0; i < extensions.size(); ++i) {
if (extensions[i] == ' ') {
string ext = extensions.substr(strStart, i - strStart);
extensionSet.insert(ext);
strStart = i+1;
}