Jump to content
  • Advertisement
Sign in to follow this  

OpenGL glUniform1f not working

This topic is 3010 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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:

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

    float 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
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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!