jvcleave / ofxImGui

Use ImGui in openFrameworks
296 stars 124 forks source link

suport for textures without alpha #24

Open andreirt opened 8 years ago

andreirt commented 8 years ago

Hello,

I made some changes regarding loading textures for use in bottoms, so images don't need to have an alpha channel.

Best, Andrei

BasEngine.h

// mode can be GL_RGB GLuint loadTextureImage2D(unsigned char * pixels, int width, int height, int mode = GL_RGBA);

BaseEngine.cpp

GLuint BaseEngine::loadTextureImage2D(unsigned char * pixels, int width, int height, int mode) { GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);

GLuint new_texture;
glGenTextures(1, &new_texture);
glBindTexture(GL_TEXTURE_2D, new_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(
             GL_TEXTURE_2D,
             0,
             mode,
             width, height,
             0,
             mode,
             GL_UNSIGNED_BYTE,
             pixels
             );

glBindTexture(GL_TEXTURE_2D, last_texture);

return new_texture;

};

ofxImGui.cpp

GLuint ofxImGui::loadPixels(ofPixels& pixels) { return engine->loadTextureImage2D(pixels.getData(), pixels.getWidth(), pixels.getHeight(), pixels.getBytesPerPixel() == 4 ? GL_RGBA : GL_RGB); }