Skip to content

Instantly share code, notes, and snippets.

@feuery
Created March 16, 2017 17:45
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 feuery/8bb229c3ff5d023fa87195e163badf73 to your computer and use it in GitHub Desktop.
Save feuery/8bb229c3ff5d023fa87195e163badf73 to your computer and use it in GitHub Desktop.
void immutable_obj::setup_texture(QOpenGLFunctions_4_3_Core *f, const char* filename)
{
if(strcmp(filename, "") == 0) {
qDebug() << "Not loading texture's from an empty string";
return;
}
if(!shader_loaded) { qDebug()<<"Shader isn't loaded?"; return; }
f->glGenTextures(1, &texture);
f->glBindTexture(GL_TEXTURE_2D, texture);
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
unsigned char* img = SOIL_load_image(filename, &text_w, &text_h, 0, SOIL_LOAD_RGB);
f->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, text_w, text_h, 0, GL_RGB, GL_UNSIGNED_BYTE, img);
f->glGenerateMipmap(GL_TEXTURE_2D);
SOIL_free_image_data(img);
f->glBindTexture(GL_TEXTURE_2D, 0);
qDebug() << "Set up a texture from " << filename;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment