vyrix09
vyrix09

Reputation: 49

passing uniform float into vertex shader opengl

I am having a problem passing a float from c++ by using uniform in to my vertex shader. This float is just meant to keep adding to itself.

Within my header i have

float pauto;
void pautoupdate(int program);

Now within my cpp

void World::pautoupdate(int program)
{
    pauto += 0.1f;

    glUniform1f(glGetUniformLocation(program, "pauto"), pauto);
}

Within my vertex shader it is declared as and it is just incrementing the x values

uniform float pauto;

terrx = Position.x;
terrx += pauto;

From here on i am not getting any results from doing this, i am not sure if i am incorrectly pointing to it or something.

Upvotes: 4

Views: 10805

Answers (2)

Sup3rlum
Sup3rlum

Reputation: 51

GlUniform* should be applied between glUseProgram(program) and glUseProgram(0):

1.Use the shader
2.Set uniforms
3.Render stuff
4.Dispose the shader

It's so because OpenGL has to know witch program you are sending the uniform to.

Upvotes: 1

christophe3d
christophe3d

Reputation: 71

Try the following:

  1. I assume that the GLSL program you show is not the whole code, since there is no main or anything.
  2. Check that program is set when you enter the function
  3. Store the output of glGetUniformLocation and check it's OK
  4. Do a call to glGetError before/after to see if GL detects an issue.

If you want to quickly test and setup shaders in a variety of situations, there are several tools to help you with that. On-line, there's ShaderToy (http://www.shadertoy.com) for example. Off-line, let me recommend one I developed, Tao3D (http://tao3d.sf.net).

Upvotes: 2

Related Questions