问题
Recently I began to use qt3d (with it's QGlView and QGLSceneNode). I provide per-vertex normals for generated model and now want to use GL_FLAT shading model for my modeling app. But simple call to glShadeModel(GL_FLAT) doesnt do anything - shading is doing look like in smooth mode
I tried to find where qt3d/qopengl calls that function but besides QGLBuilder couldn't find anything.
It seems to me that I have to do something with QOpenGLContext to make native opengl functions work (I have same problems with some other opengl functions)
or maybe QGLPainter/QGLSceneNode internally sets shading model and I have not to use it at all?
回答1:
I guess you already found the solution or gave up, but for completeness this should help if I understood you correctly:
QGLPainter
sets the shading program via a "high level" effect which will then be used when drawing (rendering) QGLSceneNode
s. There are some standard effects you can set using this function:
void QGLPainter::setStandardEffect(QGL::StandardEffect effect);
The standard effects are defined in the documentation. If you can't find what you want, you can pass a user effect using this function:
void QGLPainter::setUserEffect(QGLAbstractEffect * effect)
QGLShaderProgramEffect inherits QGLAbstractEffect
and is the class you are looking for in this case.
Please also note that Qt3D is something like a "high level" OpenGL wrapper. Calling OpenGL commands directly isn't "the correct way" in most cases (apart from initialization code and some other things). You should tell Qt3D what and how to render, not the OpenGL API.
来源:https://stackoverflow.com/questions/11091993/qt3d-glshademodel