c++ - What is the proper order of initialization of OpenGL inside a QT GraphicsScene? -
the following qt sample straightforward : i'm trying find out why texture shows if application gets timed messagebox. i'm using qt4.8.1 , tried both under linux , vs2008.
#include "ui_qtgltest.h" #include <qtgui/qapplication> #include <qtgui/qmainwindow> #include <qgraphicspixmapitem> #include <qgraphicsscene> #include <qglwidget> #include <qmessagebox> #include <qdebug> #include <qtimer> class glitem : public qgraphicspixmapitem // item issue opengl commands { gluint texture[1] ; glsizei w, h; public: glitem(qgraphicsitem *parent = null) : qgraphicspixmapitem(parent){ // when following line commented out, texture doesn't show up. qmessagebox::warning(null,qstring("???"),qstring("hold on second") ); qimage img( "im0.png" ) ; qimage gl_formatted_image; gl_formatted_image = qglwidget::converttoglformat(img); w = gl_formatted_image.width(); h = gl_formatted_image.height(); glgentextures(1, texture); glbindtexture(gl_texture_2d, texture[0]); glteximage2d( gl_texture_2d, 0, gl_rgba, gl_formatted_image.width(), gl_formatted_image.height(), 0, gl_rgba, gl_unsigned_byte, gl_formatted_image.bits() ); gltexparameteri(gl_texture_2d, gl_texture_wrap_s, gl_repeat); gltexparameteri(gl_texture_2d, gl_texture_wrap_t, gl_repeat); gltexparameteri( gl_texture_2d, gl_texture_min_filter, gl_linear ); gltexparameteri( gl_texture_2d, gl_texture_mag_filter, gl_linear ); gltexenvf(gl_texture_env, gl_texture_env_mode, gl_modulate); glbindtexture(gl_texture_2d, 0); } ~glitem(void){} void paint(qpainter *paint, const qstyleoptiongraphicsitem *option, qwidget *widget) { paint->setrenderhint(qpainter::antialiasing); paint->beginnativepainting(); glclearcolor( 0.5f, 0.5f, 0.5f, 0.0f); glclear( gl_color_buffer_bit ); glmatrixmode( gl_modelview ); glloadidentity(); glenable ( gl_blend ) ; glblendfunc(gl_src_alpha, gl_one_minus_src_alpha); glenable(gl_texture_2d); glbindtexture(gl_texture_2d, texture[0]); glbegin(gl_quads); gltexcoord2i( 1, 0 ); glcolor3f(1,0,0); glvertex2f( w, 0.0f); gltexcoord2i( 1, 1 ); glcolor3f(0,1,0); glvertex2f( w, h); gltexcoord2i( 0, 1 ); glcolor3f(0,0,1); glvertex2f( 0.0f, h); gltexcoord2i( 0, 0 ); glcolor3f(1,0,1); glvertex2f( 0.0f, 0.0f); glend(); paint->endnativepainting(); } }; class qtgl: public qmainwindow { public: qtgl(qwidget *parent =0, qt::wflags flags=0) : qmainwindow(parent, flags) { ui.setupui(this); } void setup() { qglwidget * glw = new qglwidget(qglformat(qgl::samplebuffers)); qgraphicsscene * s = new qgraphicsscene(); qgraphicsview * g = ui.graphicsview; g->setviewport(glw); g->setscene(s); glitem * gi = new glitem(); s->additem( gi ); qtimer * timer = new qtimer(this); connect(timer, signal(timeout()), s, slot(update())); timer->start(10); } ~qtgl() {} private: ui::mainwindow ui; }; int main(int argc, char *argv[]) { qapplication a(argc, argv); qtgl w; w.show(); w.setup(); return a.exec(); }
any idea on how debug , figure out going on inside ?
Comments
Post a Comment