Skip to content

Instantly share code, notes, and snippets.

View DylanLukes's full-sized avatar

Dylan Lukes DylanLukes

  • University of California San Diego
  • San Diego, CA
View GitHub Profile
GLvoid* load_image(NSString* imagename){
CGImageRef img = [[NSImage imageNamed:imagename] CGImage];
if(!img) NSLog(@"Image loading failed for \"%@\"", imagename);
NSInteger width = CGImageGetWidth(img);
NSInteger height = CGImageGetHeight(img);
unsigned char *data = (unsigned char*) malloc(width*height*4);
// Create a context to draw the new bitmap into
CGContextRef context = CGBitmapContextCreate(data, width, height, 8, width * 4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast);
GLvoid* load_image(NSString* imagename){
CFURLRef url = (CFURLRef)[[NSBundle mainBundle] URLForImageResource:imagename];
CGImageSourceRef source = CGImageSourceCreateWithURL(url, NULL);
CGImageRef img = CGImageSourceCreateImageAtIndex(source, 0, NULL);
if(!img) NSLog(@"Image loading failed for \"%@\"", imagename);
NSInteger width = CGImageGetWidth(img);
- (GLvoid)setupOpenGL{
/* Create buffers */ {
glGenBuffers(2, buffers);
// Vertex buffer
glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vbdata), vbdata, GL_STATIC_DRAW);
// Element buffer
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(ebdata), ebdata, GL_STATIC_DRAW);
}
/* Load textures */ {
glGenTextures(2, textures);
GLsizei width, height;
GLvoid* pixels;
// Texture #1
pixels = load_image(@"hello1.png", &width, &height);
glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
//
// CNWorldView+Drawing.m
// Concorde
//
// Created by Dylan Lukes on 9/22/10.
// Copyright 2010 Dylan Lukes. All rights reserved.
//
#import <OpenGL/gl.h>
#import <OpenGL/glu.h>
- (void)loadShaderNamed:(NSString*)shaderName buffer:(const GLchar**)buffer length:(GLuint*)length{
NSURL *url;
NSString *shader;
NSError *error;
NSDictionary *errorInfo;
url = [self URLForResource:shaderName withExtension:nil subdirectory:@"Shaders"];
shader = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];
if (!shader) {
//
// NSBundle+GLUtil.m
// Concorde
//
// Created by Dylan Lukes on 9/25/10.
// Copyright 2010 Dylan Lukes. All rights reserved.
//
#import "NSBundle+CGLUtil.h"
package alphatunnel;
import java.io.IOException;
import java.io.FilterInputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.CharBuffer;
import java.util.logging.Level;
import java.util.logging.Logger;
require 'socket'
class ClientQuitError < RuntimeError; end
port = ARGV.shift || 0 # default is to use the next available port
host = ARGV.shift # default is to bind everything
server = host ? TCPServer.open(host, port) : TCPServer.open(port)
port = server.addr[1]
require 'socket'
local_port = 45788
# Quick check
if ARGV.length() < 2 then
puts "Syntax: 'ruby InventProxy.rb [dest_host] [dest_port]'"
exit()
end