I want to load an image (jpg and png) with OpenCV as OpenGL Texture.
Here is how I load the image to OpenGL:
glEnable(GL_TEXTURE_2D);
textureData =
Okay here is my working solution - based on the ideas of "Christan Rau" - Thanks for that!
cv::Mat image = cv::imread("textures/trashbin.png");
//cv::Mat flipped;
//cv::flip(image, flipped, 0);
//image = flipped;
if(image.empty()){
std::cout << "image empty" << std::endl;
}else{
cv::flip(image, image, 0);
glGenTextures(1, &textureTrash);
glBindTexture(GL_TEXTURE_2D, textureTrash);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// Set texture clamping method
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(GL_TEXTURE_2D, // Type of texture
0, // Pyramid level (for mip-mapping) - 0 is the top level
GL_RGB, // Internal colour format to convert to
image.cols, // Image width i.e. 640 for Kinect in standard mode
image.rows, // Image height i.e. 480 for Kinect in standard mode
0, // Border width in pixels (can either be 1 or 0)
GL_BGR, // Input image format (i.e. GL_RGB, GL_RGBA, GL_BGR etc.)
GL_UNSIGNED_BYTE, // Image data type
image.ptr()); // The actual image data itself
glGenerateMipmap(GL_TEXTURE_2D);
}