c++ - OpenGL scene under Qt qml application -


this should best way how add custom opengl qml app.

http://qt-project.org/doc/qt-5/qtquick-scenegraph-openglunderqml-example.html

the problem is, dont want paint on whole window, in rectangle occupied opengl custom qt quick item. thought can call glviewport appropriate parameters, opengl paint rectangle of item.

actually, doesn't work me.

qml:

import qtquick 2.2 import qtquick.controls 1.1 import ge.components 1.0  applicationwindow {     visible: true     width: 640     height: 480     title: qstr("hello world")     color: "red"      menubar: menubar {         menu {             title: qstr("filxe")             menuitem {                 text: qstr("exit")                 ontriggered: qt.quit();             }         }     }      glviewer {         width: 200         height: 200         x: 100         y: 100     } } 

qt quick item: in paint method, first fill whole window color of applicationwindow , want fill rectangle occupied item black color. fill whole window black, why???

#include "glviewer.h" #include <qquickwindow> #include <iostream> #include <qcolor>  using namespace std;  glviewer::glviewer(qquickitem *parent) :     qquickitem(parent) {     connect(this, signal(windowchanged(qquickwindow*)), this, slot(handlewindowchanged(qquickwindow*))); }  void glviewer::handlewindowchanged(qquickwindow *win) {     if (win) {         connect(win, signal(beforerendering()), this, slot(paint()), qt::directconnection);         win->setclearbeforerendering(false);     } }  void glviewer::paint() {      qcolor color = window()->color();     glclearcolor(color.red(), color.green(), color.blue(), color.alpha());     glclear(gl_color_buffer_bit | gl_depth_buffer_bit);      cout << "x: " << x() << ", y: " << y() << ", w: " << width() << ", h: " << height() << endl;      glviewport(x(), y(), width(), height());     glclearcolor(0.0f, 0.0f, 0.0f, 1.0f);     glclear(gl_color_buffer_bit);  } 

there 2 issues code. first one, applicationwindow has no color attribute when set

color: "red" 

in component don't set color (that color black). can set background color applicationwindow adding rectangle component before glviewer follow

rectangle {     width: parent.width     height: parent.height     anchors.centerin: parent     color: "red" } 

second one, drawing in main windows gl context then, if viewport correctly setted, following lines of code

glclearcolor(0.0f, 0.0f, 0.0f, 1.0f); glclear(gl_color_buffer_bit); 

will clear entire window. if want clear part of window have use glscissor

glviewport(x, y, w, h);  glenable(gl_scissor_test); glscissor(x,y,w,h);  glclearcolor(0, 0, 0, 1); glclear(gl_color_buffer_bit);  gldisable(gl_scissor_test); 

you can find complete example (based on link) on github.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -