OpenGL glBegin(GL_TRIANGLES) work only first time
-
wrote on 5 Aug 2014, 15:31 last edited by
Hi all,
first of all I'm completely new in OpenGL and Initiate in Qt )
I try relate Qml and OpenGL, so I take example openglunderqml
as in example I create own class
@class QProject1Main : public QQuickItemvoid QProject1Main::handleWindowChanged(QQuickWindow *win) {
if (win) {
connect(win, SIGNAL(beforeRendering()), this, SLOT(paint()), Qt::DirectConnection);
win->setClearBeforeRendering(false);
}
}void QProject1Main::paint() {
qDebug() << "QProject1Main::paint()";
qreal ratio = window()->devicePixelRatio();
int w = int(ratio * window()->width());
int h = int(ratio * window()->height());
glViewport(0, 0, w, h);// each iteration bg color change from green to read
glClearColor(((float)++idx)/100, 0.3, 0.3, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glLoadIdentity();
// triangle pain only at first iteration
glColor3f(0.5f, 0.5f, 0.5f);
glBegin(GL_TRIANGLES);
glVertex3f( 0.1f, 0.8f, 0.1f);
glVertex3f(-0.8f,-0.8f, 0.1f);
glVertex3f( 0.8f,-0.8f, 0.1f);
glEnd();
}
@I'm resize window to call paint method and see that background color changed but triangle paint only first time (
-
wrote on 5 Aug 2014, 15:51 last edited by
I'm add timer to my QML but receive same problem triangle visible only first time
@
Window {
id: wndMain
visible: true
width: 360
height: 360QProject1Main { id: core anchors.fill: parent } Text { text: qsTr("Black rectangle - it's OpenGL baby ;)") anchors.centerIn: parent color: "red" } Timer { id: tGameTimer interval: 29 running: true repeat: true onTriggered: { console.log("timer paint call") wndMain.update() } }
}
@ -
wrote on 7 Aug 2014, 09:13 last edited by
in article http://qt-project.org/doc/qt-5/qtquick-scenegraph-openglunderqml-example.html class SquircleRenderer exists but in examples openglunderqml.pro it's not esists
-
wrote on 7 Aug 2014, 15:26 last edited by
hey all
any body know how to call SwapBuffers? -
wrote on 21 Aug 2014, 07:44 last edited by
I've had the same problem. After the first frame, everything I draw is condensed to the lower left corner of the window. I've not come to a definite answer, but my guess here is that QtQuick doesn't cooperate well with the obsolete fixed function pipeline of OpenGL. It seems to tamper with some state variables.
Try using custom shaders.
-
wrote on 21 Aug 2014, 10:20 last edited by
Try using custom shaders.
are you mean create something like Geometry Shaders and move triangle with sync as in example?
I'll try, thank you -
wrote on 21 Aug 2014, 11:26 last edited by
The geometry shader is optional, you'll probably only need vertex and pixel shader.
Although there are other ways, the "OpenGL under QML" example is probably a good place to start from:
http://qt-project.org/doc/qt-5/qtquick-scenegraph-openglunderqml-example.html
-
wrote on 21 Aug 2014, 11:29 last edited by
yes, I take code from this example, thank you