Created
October 5, 2011 19:45
-
-
Save dennda/1265473 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FILE *fp = fopen([[[NSBundle mainBundle] pathForResource:@"binary" | |
ofType:@"buf"] | |
cStringUsingEncoding:NSUTF8StringEncoding], | |
"rb"); | |
unsigned short buffer[512*512] = {0}; /* initialized to zeroes */ | |
int i; | |
unsigned short rs; | |
if (fp == NULL) { | |
perror("Failed to open file \"myfile\""); | |
} | |
for (i = 0; (rs = getc(fp)) != EOF && i < 512*512; buffer[i++] = rs) | |
; | |
fclose(fp); | |
glGenTextures(1, &_name); | |
GetError(); | |
glBindTexture(GL_TEXTURE_2D, _tf_texname); | |
GetError(); | |
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); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
GetError(); | |
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 512, 512, 0, GL_ALPHA, GL_UNSIGNED_SHORT, buffer); | |
GetError(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment