Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't access OpenGL Attribute or Uniform values
Forum Updated to NodeBB v4.3 + New Features

Can't access OpenGL Attribute or Uniform values

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Randomaniac
    wrote on 8 Mar 2014, 16:59 last edited by
    #1

    Hi there,

    First of all I'm using Qt 4.8 and have been quite happy with the OpenGL bindings for it. Now that I've started using Shaders I bumped into some trouble though. My first test was overriding all colours with a default, which worked fine. My second test exists of passing in this color value from outside. The problem is though, Qt can't find the variable for me. Here's what I've got so far:

    Initializing my shader program

    @ std::string sourceCode = "attribute mediump vec4 color;\n"
    "void main(void){"
    "gl_FragColor = color;"
    "}";

    QGLShader* shader = new QGLShader(QGLShader::Fragment);
    shader->compileSourceCode(sourceCode.c_str());

    QGLShaderProgram* program = new QGLShaderProgram(m_glContext);
    program->addShader(shader);
    program->link();
    program->bind();
    @

    Changing values for different objects i want to draw

    @
    QColor color2(0, 255, 0, 255);
    int colorLocation = m_program->attributeLocation("color");
    if (colorLocation == -1) {
    std::cerr << "Attribute location not found" << std::endl;
    }
    m_program->setAttributeValue(colorLocation, color2);
    @

    This outputs "Attribute location not found" and nets me black objects on the screen.

    Don't worry about names not matching, it's probably stored in some variable. Before you point out a name mismatch or anything, keep in mind I've got this working for 'color' fixed, instead of as an attribute variable.

    Could someone please point me in the right direction? I'm using the simple tutorial from "the official docs":http://qt-project.org/doc/qt-4.8/qglshaderprogram.html but alas, nothing.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      agocs
      wrote on 10 Mar 2014, 08:45 last edited by
      #2

      That's an invalid fragment shader to begin with. Attributes are only used in vertex shaders. What you want is either a varying or a uniform.

      1 Reply Last reply
      0

      1/2

      8 Mar 2014, 16:59

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved