You can’t put OpenGL calls in draw()
. To see why, look at this simplified version of the draw routine in Window::run()
.
nvgBeginFrame(vg, fbWidth, fbHeight, pixelRatio);
APP->scene->draw();
glViewport(0, 0, fbWidth, fbHeight);
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
nvgEndFrame(vg);
NanoVG functions don’t do any drawing. They add commands to a command buffer which is converted into OpenGL calls when nvgEndFrame()
is called. If you draw anything directly in draw()
, it will be cleared with glClear()
, and then your NanoVG stuff will be drawn over the cleared screen in nvgEndFrame()
.
I suggest looking at the documentation of OpenGlWidget
. The only example of OpenGlWidget
I’m aware of is OpenGlWidget
itself, which draws a colorful triangle in its drawFramebuffer()
. You should not attempt to call NanoVG functions in this method unless you understand exactly how NanoVG is implemented.