Results 1 to 2 of 2

Thread: QGLWidget won't display anything except the clear color

  1. #1
    Join Date
    Sep 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QGLWidget won't display anything except the clear color

    Hello,

    I have started to develop a 3D viewer on a computer, and I would like to test it on another one. Both of them are under ubuntu lucid lynx. Unfortunately, on the second computer, the QGLWidget is blank. I have made up a minimal application that doesn't work neither on that second computer :

    Qt Code:
    1. #ifndef GLVIEWER_H
    2. #define GLVIEWER_H
    3. #include <QtOpenGL/qgl.h>
    4.  
    5. class GLViewer : public QGLWidget {
    6.  
    7. public:
    8. GLViewer(QWidget * parent = 0);
    9. ~GLViewer();
    10.  
    11. protected:
    12. int viewport[4];
    13.  
    14. void initializeGL();
    15. void resizeGL (int width, int height);
    16. void paintGL();
    17.  
    18.  
    19. };
    20.  
    21. #endif // GLVIEWER_H
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. #include "GLViewer.h"
    2.  
    3. GLViewer::GLViewer(QWidget * parent)
    4. : QGLWidget(parent)
    5. {
    6.  
    7. }
    8.  
    9. GLViewer::~GLViewer() {
    10.  
    11. }
    12.  
    13. void GLViewer::initializeGL() {
    14.  
    15. }
    16.  
    17. void GLViewer::resizeGL(int width, int height) {
    18. viewport[0] = 0;
    19. viewport[1] = 0;
    20. viewport[2] = width;
    21. viewport[3] = height;
    22. glViewport(0, 0, width, height);
    23. }
    24.  
    25. void GLViewer::paintGL() {
    26. glClearColor(1,1,1,1);
    27. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    28. glMatrixMode(GL_PROJECTION);
    29. glLoadIdentity();
    30. glOrtho(-1.0, 1.0, -1.0, 1.0, 0, 1);
    31. glMatrixMode(GL_MODELVIEW);
    32. glLoadIdentity();
    33. glColor3f(0.0f, 0.0f, 1.0f);
    34. glBegin(GL_TRIANGLES);
    35. glVertex3f(0,0,.5);
    36. glVertex3f(0,1,.5);
    37. glVertex3f(1,1,.5);
    38. glEnd();
    39. }
    To copy to clipboard, switch view to plain text mode 

    What it does is to draw a blank area in clearColor, but nothing else. It seems however that the Qt precompiled demo are working well with opengl. Where can the problem come from ?

  2. #2
    Join Date
    Nov 2008
    Posts
    39
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGLWidget won't display anything except the clear color

    you have to organise your code ...you have to go along in this way. this is just an example you can place your own opengl drawing code in paintGL() function
    [QTCODE]
    void GLWidget::initializeGL()
    {
    qglClearColor(Qt::gray);
    glShadeModel(GL_SMOOTH);
    }
    void GLWidget::resizeGL(int width, int height)
    {
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    GLfloat x = GLfloat(width) / height;
    glFrustum(-x, +x, -1.0, +1.0, 4.0, 20.0);
    glMatrixMode(GL_MODELVIEW); }

    void GLWidget:aintGL()
    { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.0, 0.0, -15.0);
    glRotatef(rotationX, 1.0, 0.0, 0.0);
    glRotatef(rotationY, 0.0, 1.0, 0.0);
    glRotatef(rotationZ, 0.0, 0.0, 1.0);
    pobj = gluNewQuadric();
    gluQuadricDrawStyle(pobj, GLU_LINE);
    gluQuadricNormals(pobj, GLU_SMOOTH);
    qglColor(Qt::red);
    gluCylinder(pobj, 1, 1, 3, 30, 30); }
    [/QTCODE]

Similar Threads

  1. Text Color display in Table
    By sosanjay in forum Qt Programming
    Replies: 1
    Last Post: 29th October 2009, 06:35
  2. Display Label Color by selecting Color Picker
    By sosanjay in forum Qt Programming
    Replies: 1
    Last Post: 25th September 2009, 06:11
  3. Replies: 0
    Last Post: 3rd December 2008, 11:58
  4. Display a Label on top of a QGlWidget
    By Lele in forum Qt Programming
    Replies: 3
    Last Post: 4th February 2008, 16:11
  5. Replies: 2
    Last Post: 10th March 2006, 20:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.