Skip to content

Instantly share code, notes, and snippets.

@DylanLukes
Created September 24, 2010 23:35
Show Gist options
  • Save DylanLukes/596239 to your computer and use it in GitHub Desktop.
Save DylanLukes/596239 to your computer and use it in GitHub Desktop.
- (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);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0,
GL_RGBA8,
width, height, 0,
GL_RGBA8, GL_UNSIGNED_BYTE,
pixels);
free(pixels);
// Texture #2
pixels = load_image(@"hello2.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);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0,
GL_RGBA8,
width, height, 0,
GL_RGBA8, GL_UNSIGNED_BYTE,
pixels);
free(pixels);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment