19 #include <QOpenGLShaderProgram> 20 #include <QOpenGLFunctions> 21 #include <QOpenGLContext> 44 qDebug() <<
"GLShaderSimple::initializeGL: error in vertex shader: " <<
m_program->log();
48 qDebug() <<
"GLShaderSimple::initializeGL: error in fragment shader: " <<
m_program->log();
51 m_program->bindAttributeLocation(
"vertex", 0);
54 qDebug() <<
"GLShaderSimple::initializeGL: error linking shader: " <<
m_program->log();
65 draw(GL_POINTS, transformMatrix, color, vertices, nbVertices);
70 draw(GL_LINE_STRIP, transformMatrix, color, vertices, nbVertices);
75 draw(GL_LINES, transformMatrix, color, vertices, nbVertices);
80 draw(GL_LINE_LOOP, transformMatrix, color, vertices, nbVertices);
85 draw(GL_TRIANGLE_FAN, transformMatrix, color, vertices, nbVertices);
88 void GLShaderSimple::draw(
unsigned int mode,
const QMatrix4x4& transformMatrix,
const QVector4D& color, GLfloat *vertices,
int nbVertices)
90 QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
94 f->glEnable(GL_BLEND);
95 f->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
97 f->glEnableVertexAttribArray(0);
98 f->glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices);
99 f->glDrawArrays(mode, 0, nbVertices);
100 f->glDisableVertexAttribArray(0);
114 "uniform highp mat4 uMatrix;\n" 115 "attribute highp vec4 vertex;\n" 117 " gl_Position = uMatrix * vertex;\n" 122 "uniform mediump vec4 uColour;\n" 124 " gl_FragColor = uColour;\n"
void drawSegments(const QMatrix4x4 &transformMatrix, const QVector4D &color, GLfloat *vertices, int nbVertices)
static const QString m_fragmentShaderSourceColored
void draw(unsigned int mode, const QMatrix4x4 &transformMatrix, const QVector4D &color, GLfloat *vertices, int nbVertices)
void drawSurface(const QMatrix4x4 &transformMatrix, const QVector4D &color, GLfloat *vertices, int nbVertices)
void drawContour(const QMatrix4x4 &transformMatrix, const QVector4D &color, GLfloat *vertices, int nbVertices)
static const QString m_vertexShaderSourceSimple
void drawPolyline(const QMatrix4x4 &transformMatrix, const QVector4D &color, GLfloat *vertices, int nbVertices)
void drawPoints(const QMatrix4x4 &transformMatrix, const QVector4D &color, GLfloat *vertices, int nbVertices)
QOpenGLShaderProgram * m_program