Qt - steps to using QOpenGLWidget to display images


April 2019


7 time


I'm trying to use a QOpenGLWidget to show some images instead of using QLabel. But I'm a bit confused about how to do this.

To make the widget get the job done, I know I need to reimplement the initializeGL() method and paintGL() method.

To get the texture of an image, what I used is SOIL_load_image(). Why is unsigned char* over GLuint textures[3]? I think each pixel of an image has 3 values(RGB).

After getting the texture, I have no idea what I should do and where should I do them in initializeGL() or paintGL(). Can anyone tell the steps?

void MyOpenGLWidget::loadTexture(const char* file_path)
    *image = cv::imread(file_path, cv::IMREAD_COLOR);
    width = image->rows;
    height = image->cols;
    int channels = image->channels();
    img_data = SOIL_load_image(file_path, &width, &height, &channels, SOIL_LOAD_RGB);

0 answers