Sign in to follow this  
The_Underscore

OpenGL glUniform1f not working

Recommended Posts

I'm using glUniform1f to pass a float uniform to my vertex shader. However, instead of the float value specified in glUniform1f, another value is used. This value is the always the same when using the same value in glUniform1f, but it is not the value I specified. The relevant code is the following:
    glUseProgram(Race_gl_program0);

    Race_render_uniform_time = glGetUniformLocation(Race_gl_program0,"time");
    glUniform1f(Race_render_uniform_time,1.0f); //ERROR

    float tempfloat;
    glGetUniformfv(Race_gl_program0,Race_render_uniform_time,&tempfloat);
    printf("%f\n",tempfloat); // output depends on glUniform1f, see below

    int tempint;
    tempint = glGetError();
    printf("%i\n",tempint); // prints 0
    printf("%i\n",Race_gl_program0); // prints 1
    printf("%i\n",Race_render_uniform_time); // prints 0
The vertex shader:
#version 110
//removing #version doesnt change anything

uniform float time;

void main()
{	
	vec4 v = gl_Vertex;
	v.y *= time;
	gl_Position = gl_ModelViewProjectionMatrix * v;
	gl_FrontColor = gl_Color;
}
The uniform value which is used in the shader and returned by glGetUniformfv depends on the value sent by glUniform1f:
value sent // value used
1.0f       0.000000
0.8f       -0.000000
0.7f       36893488147419103232.000000
0.65f      -2.000000
0.6f       2.000000
0.5f       0.000000
0.2271f    -36893488147419103232.000000
0.227f     0.000000
0.0f       0.000000
I am using OpenGL 3.2.0 on Ubuntu 9.10 with the NVIDIA 195.36.15 driver (it didn't work with the driver 185.something I had before either). I already tried inserting
PFNGLUNIFORM1FPROC glUniform1f = (PFNGLUNIFORM1FPROC)glXGetProcAddress((GLubyte*)"glUniform1f");
into my context creation which didn't help, as well as
#define DGL_GLEXT_PROTOTYPES
What am I doing wrong here?

Share this post


Link to post
Share on other sites
Hmm that's a tough one. Everything you've shown looks right (I even cut it into a quick test program and I read back the float correctly).

So its either something you're doing that you haven't shown, or a wonky driver.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this