Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mqcmd196
Copy link
Contributor

@mqcmd196 mqcmd196 commented Jun 27, 2024

Fixes #20001

GSoC2024 Project

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@asmorkalov
Copy link
Contributor

./bin/example_opengl_opengl
Usage: ./bin/example_opengl_opengl image
[ WARN:[email protected]] global samples.cpp:61 findFile cv::samples::findFile('lena.jpg') => '/home/alexander/Projects/OpenCV/opencv-build/../opencv-master/samples/data/lena.jpg'
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.10.0-dev) /home/alexander/Projects/OpenCV/opencv-master/modules/core/src/opengl.cpp:359: error: (-215:Assertion failed) bufId_ != 0 in function 'Impl'

@asmorkalov
Copy link
Contributor

I created a sample from your test and it shows just empty window:

#ifdef _WIN32
    #define WIN32_LEAN_AND_MEAN 1
    #define NOMINMAX 1
    #include <windows.h>
#endif

#if defined(__APPLE__)
    #include <OpenGL/gl.h>
    #include <OpenGL/glu.h>
#else
    #include <GL/gl.h>
    #include <GL/glu.h>
#endif

#include "opencv2/core.hpp"
#include "opencv2/core/opengl.hpp"
#include "opencv2/core/cuda.hpp"
#include "opencv2/highgui.hpp"

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
    const std::string window_name("gl_test_window");
    const Size image_size(800, 600);

    namedWindow(window_name, WINDOW_OPENGL);
    Mat m = Mat(image_size, CV_8UC3, Scalar(255, 0, 0));
    resizeWindow(window_name, image_size);
    setOpenGlContext(window_name);

    setOpenGlDrawCallback(window_name, [](void*){
        glClear(GL_COLOR_BUFFER_BIT);
        glColor3f(1.0f, 0.0f, 0.0f);
        glBegin(GL_QUADS);
        glVertex2f(-0.5f, -0.5f);
        glVertex2f( 0.5f, -0.5f);
        glVertex2f( 0.5f,  0.5f);
        glVertex2f(-0.5f,  0.5f);
        glEnd();
    });

    imshow(window_name, m);

    while (waitKey(30) != 27)
    {
    }

    setOpenGlDrawCallback(window_name, 0);
    destroyAllWindows();
}

@asmorkalov asmorkalov self-assigned this Jul 3, 2024
@mqcmd196 mqcmd196 force-pushed the gtk3-gl-support branch 3 times, most recently from ea0e347 to a35dfd3 Compare July 5, 2024 07:18
@mqcmd196
Copy link
Contributor Author

mqcmd196 commented Jul 5, 2024

@asmorkalov
I updated the codes and confirmed that the GL test in modules/highgui/test/test_gui.cpp works well. (This test will be removed when merged.) As I mentioned online, GTK3's OpenGL API only supports OpenGL > 3.2 , and I updated its test code to 3.2.

I'll continue working on supporting current OpenCV's OpenGL example code.

@mqcmd196
Copy link
Contributor Author

mqcmd196 commented Jul 5, 2024

And I squashed some commits into a single commit.

@asmorkalov
Copy link
Contributor

Looks like we are closer to result, but opengl/opengl.cpp still does not work correctly. I do not see error messages any more and just black window.

@asmorkalov
Copy link
Contributor

In case I add sample with your test code I see the following error:

/usr/bin/ld: CMakeFiles/example_opengl_opengl.dir/opengl.cpp.o: unresolved external symbol «epoxy_glDrawArrays»
//usr/lib/x86_64-linux-gnu/libepoxy.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
samples/opengl/CMakeFiles/example_opengl_opengl.dir/build.make:103: recipe for target 'bin/example_opengl_opengl' failed
make[3]: *** [bin/example_opengl_opengl] Error 1

The error means that libepoxy is missing somewhere in cmake. I'll take a look today.

@mqcmd196
Copy link
Contributor Author

mqcmd196 commented Jul 5, 2024

Looks like we are closer to result, but opengl/opengl.cpp still does not work correctly. I do not see error messages any more and just black window.

Thank you. The code is written in a legacy OpenGL version, so it won't be drawn in a newer GtkGlArea, I think.

So I added the example code for OpenGL 3.2 c035d93

@mqcmd196 mqcmd196 marked this pull request as ready for review July 14, 2024 03:57
@mqcmd196
Copy link
Contributor Author

Sorry, I forgot to remove them.

@asmorkalov
Copy link
Contributor

Tested manually with:

  • Ubuntu 18.04 + GTK 2
  • Ubuntu 18.04 + GTK 3
  • Ubuntu 18.04 + QT 5.9
  • Ubuntu 24.04 + GTK 3
  • Ubuntu 24.04 + QT 5.15

@asmorkalov asmorkalov merged commit 4842043 into opencv:4.x Jul 15, 2024
@mqcmd196 mqcmd196 deleted the gtk3-gl-support branch July 15, 2024 14:08
@asmorkalov asmorkalov mentioned this pull request Jul 16, 2024
fengyuentau pushed a commit to fengyuentau/opencv that referenced this pull request Aug 15, 2024
Support OpenGL GTK3 New API opencv#25822

Fixes opencv#20001

GSoC2024 Project

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A strange logic when checking opengl support in OpenCVFindLibsGUI.cmake

3 participants