Thursday, 15 March 2012

c++ - QGLWidget refuses to draw anything -



c++ - QGLWidget refuses to draw anything -

i've looked @ ton of articles , questions opengl not drawing, mutual mistakes, etc. 1 stumping me.

i've tried several different settings glortho, different vertex positions, colors, etc., no avail.

i can confirm opengl state valid because clear color is violet in code (meaning window is purple). gdebugger confirming frames beingness updated (so fraps).

here code. lines marked "didn't help" not there originally, , things tried , failed.

qtwindow::qtwindow( ) { // enable mouse tracking this->setmousetracking(true); } void qtwindow::initializegl() { // debug debug("init'ing gl"); this->makecurrent(); ///< didn't help this->resizegl(0, 0); ///< didn't help gldisable(gl_cull_face); ///< didn't help glclearcolor(1, 0, 1, 0); } void qtwindow::paintgl() { // debug debug("painting gl"); this->makecurrent(); ///< didn't help glloadidentity(); glclear(gl_color_buffer_bit); glcolor3f(0,1,1); glbegin(gl_triangles); glvertex2f(500,100); glvertex2f(100,500); glvertex2f(0,0); glend(); this->swapbuffers(); ///< didn't help } void qtwindow::resizegl(int width, int height) { // debug debug("resizing gl"); this->makecurrent(); ///< didn't help glmatrixmode(gl_projection); glloadidentity(); glortho(0, 1000, 0, 1000, -1, 1); glmatrixmode(gl_modelview); glloadidentity(); }

the triangle not beingness displayed @ all, culling turned off. however, 3 debug logs called how should be.

what missing?

try calling glviewport() function @ origin of qtwindow::resizegl() function:

glviewport(0, 0, width, height);

and don't ever phone call resizegl() width , height set 0 ;) besides that, not necessary phone call resizegl() straight beingness called qt whenever window beingness resized.

you can remove calls swapbuffers() function - beingness called internally qt.

the makecurrent() function should called before other gl calls, have called in initializegl(), don't have phone call in paintgl() function (unless paintgl() beingness called thread, bet isn't in code).

c++ qt opengl qt4 qglwidget

No comments:

Post a Comment