Unsolved display .obj file in QOpenGLWindow
-
Hi everyone,
Hope this is the right subforum for my question.
After creating an empty window with QOpenGLWindow, I want to import and display a .obj file in that window.
In the documentation I could not find anything. Does anybody have suggestions what the general approach to this task is?Thanks
-
Hi,
IIRC, Qt3D has all you need for that.
-
@cprinter What are you actually trying to do? If you want to do it yourself, there are a couple of sub-problems.
1 - Load an OBJ file into memory, parse it, and have some raw geometry to render. You can find documentation for the format, or various libraries that can read the format.
2 - Use OpenGL to render some geometry in memory. The fact that the geometry originally came from an OBJ file doesn't make any difference when you are rendering it. "How to render 3D graphics with OpenGL" is a giant topic, and there are tons of approaches to writing your renderer, potentially involving all sorts of interesting decisions about how to do shading and lighting, or how to improve performance by only drawing visible parts of the scene.
3 - Open a window to have some place for your OpenGL renderer to draw on screen. This is the only part that would be Qt specific, and it sounds like you've got that much figured out.
If you don't want to do all that stuff yourself, like Sgaist said you can use Qt3D rather than a bare QOpenGLWindow. If you do want to do it yourself in a bare QOpenGLWindow, there isn't a ton of Qt-specific stuff to discuss. Override the methods mentioned in the QOpenGLWindow documentation and do your painting there with standard OpenGL functionality. There's a handful of helper classes like QOpenGLTexture, but they aren't doing anything you can't do other ways, and you haven't mentioned any specific problems with your OpenGL.
-
@SGaist
had a quick look at qt3d as well, but I had the impression that I have more freedom using QOpenGLWindow as a "foundation".@wrosecrans
thanks for the elaborate response, I plan to build an application that allows me to import a .obj file, visualize the mesh, then slice the mesh into multiple parts and visualize these slices.
I have to add that I also have no prior experience with OpenGL, so it seems I have a lot of learning to do. I just wanted to know if there is one obvious, correct way to do this. -
@cprinter There's definitely no one correct way to do it. You are 100% right that writing your own OpenGL code gives you more freedom to do whatever you want than using a higher level library like Qt3D. But that freedom means it's up to you to decide what exactly you want to do.
At the end of the day, OpenGL is just a way to draw a triangle. It's up to you to decide what triangles, where they should be and what they should look like.
-
@wrosecrans okay, thanks again for clarifying that.