Skip to content

Instantly share code, notes, and snippets.

View chinmaygarde's full-sized avatar

Chinmay Garde chinmaygarde

View GitHub Profile
@chinmaygarde
chinmaygarde / ScreenCapture.m
Created January 27, 2013 09:12
Mac OSX Screen Capture
CGImageRef imageRef = CGWindowListCreateImage(CGRectInfinite, kCGWindowListOptionAll, kCGNullWindowID, kCGWindowImageDefault);
CFMutableDataRef dataRef = CFDataCreateMutable(kCFAllocatorDefault, 0);
CGImageDestinationRef dest = CGImageDestinationCreateWithData(dataRef, kUTTypePNG, 1, NULL);
CGImageDestinationAddImage(dest, imageRef, NULL);
CGImageDestinationFinalize(dest);
CFRelease(dest);
CGImageRelease(imageRef);
@chinmaygarde
chinmaygarde / .gitignore
Last active December 16, 2015 15:29 — forked from adamgit/.gitignore
Default GitIgnore for XCode for Projects
.idea/
.sconsign.dblite
.svn/
.DS_Store
*.swp
*.lock
profile
DerivedData/
var simplifyPath = function( points, tolerance ) {
// helper classes
var Vector = function( x, y ) {
this.x = x;
this.y = y;
};
var Line = function( p1, p2 ) {
this.p1 = p1;
files = []
["plist", "xml"].each { |t| Dir["**/*.#{t}"].each {|i| files << i} }
files.each do |f|
`xmllint --noout #{f}`
puts "#{f} failed validation" if $?.exitstatus != 0
end
background: #f06;
background: linear-gradient(22deg, #blue, yellow);
min-height: 100%;
@chinmaygarde
chinmaygarde / gist:5660972
Last active December 17, 2015 19:29
Create an object but change the superclass
id objc_createInstanceOfClassWithPlatformSuperclass(Class clasz) {
Class currentSuperclass = class_getSuperclass(clasz);
Class originalSuperclass = objc_getClassRegisteredFirst(class_getName(currentSuperclass));
const char *currentClassName = [[NSString stringWithFormat:@"__%s", class_getName(clasz)] UTF8String];
// Allocate a new class par
Class createdClass = objc_allocateClassPair(originalSuperclass, currentClassName, 0);
if (createdClass == Nil) {
@chinmaygarde
chinmaygarde / gist:5835009
Created June 21, 2013 23:14
glReadPixels to Image on Desktop. Debugging Only
// Add ApplicationServices.h on Mac
#import <ImageIO/ImageIO.h>
#import <MobileCoreServices/MobileCoreServices.h>
CGSize sz = self.renderNode.size;
void *data = calloc(sz.width * sz.height * 4, sizeof(char));
glReadPixels(0, 0, sz.width, sz.height, GL_RGBA, GL_UNSIGNED_BYTE, data);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(data, sz.width, sz.height, 8, sz.width * 4, colorSpace, kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);
// Omega Spec
Ω interface Foo < Base :SomeProtocol
Ω (read, write) Bar *bar;
Ω (read) Baz *baz;
Ω (read, copy) Burrito *burrito;
Ω (atomic, write) Bang *bang;
1. The texture target needs to be GLES20.GL_TEXTURE_EXTERNAL_OES instead of GL_TEXTURE_2D, e.g. in the glBindTexture calls and glTexParameteri calls.
2. In the fragment shader define a requirement to use the extension:
#extension GL_OES_EGL_image_external : require
3. For the texture sampler used in the fragment shader, use samplerExternalOES instead of sampler2D.
Everything below here is all in the C code, no more Java.
4. In the C code, use glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, eglImage) to specify where the data is, instead of using glTexImage2D family of functions.
-(void) sandbox {
EFDisplay *display = [EFDisplay defaultDisplay];
const EGLint attributes[] = {
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_NONE, /* termination sentinel */
};
EFSurfaceConfig *config = [display configurationsForAttributes:attributes].firstObject;