Skip to content

Instantly share code, notes, and snippets.

@tadzik
Created January 8, 2014 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tadzik/8324000 to your computer and use it in GitHub Desktop.
Save tadzik/8324000 to your computer and use it in GitHub Desktop.
int load_texture(const char *file, int w, int h)
{
GLuint id;
glGenTextures(1, &id);
struct pixel px[w * h];
FILE *fh = fopen(file, "rb");
fseek(fh, 54L, SEEK_SET);
fread(&px, 3, w * h, fh);
fclose(fh);
glBindTexture(GL_TEXTURE_2D, id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h,
0, GL_RGB, GL_UNSIGNED_BYTE, px);
return id;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment