Results 1 to 2 of 2

Thread: QGLWidget, setting OpenGL version, and shaders

  1. #1
    Join Date
    Mar 2014
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QGLWidget, setting OpenGL version, and shaders

    I'm attempting to draw a triangle to a (derived) QGLWidget, using Qt 5.2 on an Arch Linux system. I've found that if I try to set the version to anything greater than 2.1, I don't get a drawing. Here's my source:

    Qt Code:
    1. #include <QtOpenGL>
    2. #include <QGLContext>
    3. #include <QGLFormat>
    4. #include <QGLShader>
    5. #include <QGLShaderProgram>
    6.  
    7. #include <QDebug>
    8.  
    9. #include "GLWidget.h"
    10.  
    11.  
    12. GLWidget::GLWidget(QWidget *parent, const QGLWidget *shareWidget, Qt::WindowFlags f)
    13. : QGLWidget(parent, shareWidget, f)
    14. {
    15. QGLFormat newFormat(format());
    16.  
    17. /* Change to 3.0 and no triangle is drawn */
    18. newFormat.setVersion(2,1);
    19. setFormat(newFormat);
    20.  
    21. makeCurrent();
    22. }
    23.  
    24. void GLWidget::initializeGL()
    25. {
    26. _backgroundColour = Qt::black;
    27. _triangleColour = Qt::white;
    28. _triangle.push_back(QVector3D(-0.75, 0.75, 0));
    29. _triangle.push_back(QVector3D(-0.75, -0.75, 0));
    30. _triangle.push_back(QVector3D(0.75, -0.75, 0));
    31. }
    32.  
    33. void GLWidget::paintGL()
    34. {
    35. qglClearColor(_backgroundColour);
    36. glClear(GL_COLOR_BUFFER_BIT);
    37.  
    38. glEnableClientState(GL_VERTEX_ARRAY);
    39. glVertexPointer(3, GL_FLOAT, 0, _triangle.constData());
    40. glDrawArrays(GL_TRIANGLES, 0, 3);
    41. }
    42.  
    43. void GLWidget::resizeGL(int width, int height)
    44. {
    45. int side = qMin(width, height);
    46.  
    47. int hoffset = (int)((width - side) / 2.0 + 0.5);
    48. int voffset = (int)((height - side) / 2.0 + 0.5);
    49.  
    50. glViewport(hoffset, voffset, side, side);
    51. }
    To copy to clipboard, switch view to plain text mode 

    I've tried using the alternate constructor that takes a QGLFormat object, and I get the same effect. Interestingly, if I dump the output of format() to qDebug() (inside GLWidget::initializeGL()), it says it's using version 3.0.

    Second issue... if I give up on explicitly setting the OpenGL version, but try to compile shaders with "#version 300", I get the following error:

    QGLShader::compile(Vertex): 0:1(10): error: GLSL 3.00 is not supported. Supported versions are: 1.10, 1.20, 1.30, 1.00 ES, and 3.00 ES
    I'm calling the function that creates and compiles my shaders from GLWidget::initilizeGL(), immediately after dumping the format string to qDebug(), so I know I've got OpenGL 3.0. What's going on?

    To summarize:

    1. How can I explicitly set the OpenGL version?
    2. Why does QGLShader seem to think my OpenGL version is older than what QGLWidget thinks it is?

  2. #2
    Join Date
    Mar 2014
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGLWidget, setting OpenGL version, and shaders

    I managed to check the GLSL version, and it's in fact 1.30. I've started a separate thread asking whether it's possible to set the GLSL version explicitly. I've had no trouble compiling GLSL 3.30 shaders in a FreeGLUT-based tutorial I've been following.

    Also, I've compiled my code with Qt 4.8, and I get a triangle even when I request OpenGL version 3.3. I've checked the format in initializeGL(), and the version is actually 3.3. So it seems something funny is going on with Qt 5.2 (or something funny is going on in my code, and Qt 5.2 is less tolerant).

Similar Threads

  1. Setting up OpenGL shaders with QGLWidget
    By Wasabi in forum Newbie
    Replies: 7
    Last Post: 9th September 2011, 18:12
  2. Replies: 2
    Last Post: 30th December 2010, 17:03
  3. OpenGL shaders and x11 forwarding
    By Wali in forum Qt Programming
    Replies: 0
    Last Post: 2nd November 2010, 21:38
  4. 4.5.2 =>4.6.3 OpenGL shaders+qrphicsview issue
    By medved6 in forum Qt Programming
    Replies: 1
    Last Post: 22nd August 2010, 19:33
  5. Replies: 0
    Last Post: 20th August 2010, 12:50

Tags for this Thread

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.