gl_LightSource[0].position not updated?

Hi,

I’m currently learning GLSL. I’m trying to write a shader that does simple diffuse lighting together with a texture. The shader uses gl_LightSource[0].position to read the light direction that I set with glLightfv(GL_LIGHT0, GL_POSITION, …) in the cpp file. However, gl_LightSource[0].position seems to be updated only by the first call to glLightfv(). Here’s my code, is this my fault or nVidias? :wink:

Get the .exe here:
www.amnoid.de/glsl1st.zip
If you hold ‘A’, you can see what happens if the fixed function pipeline is used instead of the shader - I want the shader to look like that.

Source:

shader.vert:

varying vec3 N; //stores normal

void main()
{
  N = normalize(gl_Normal);

  //send interpolated color to
  //fragment shader
  gl_FrontColor = gl_Color;

  gl_TexCoord[0] = gl_MultiTexCoord0;
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

shader.frag:

uniform sampler2D myTexture;

varying vec3 N;

void main()
{
  vec3 light = gl_LightSource[0].position.xyz;
  vec4 lightColor = gl_Color*max(0.2, dot(light, N));

  gl_FragColor = lightColor*texture2D(myTexture, vec2(gl_TexCoord[0]));
}

main cpp file:

#include "simple_gl.h"
#include "modelle.h"

#include "shader.h"


GLuint g_tex;
GLhandleARB g_program;

//called one time at startup
bool init()
{
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_CULL_FACE);

  if(!hasShaderHardware())
    return false;

  walkBack(5);

  g_program = loadProgram("shader.vert", "shader.frag");
  printLog(g_program);

  g_tex = loadTexture2DMM("basement floor.bmp");

  glUseProgramObjectARB(g_program); //program has to be active to access its uniforms
  int texLocation = glGetUniformLocationARB(g_program, "myTexture");
  drawText("texLocation: %x", texLocation);
  if(texLocation != -1)
    glUniform1iARB(texLocation, 0); //bind texture unit 0 to shader
  glUseProgramObjectARB(0);

  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHTING);
  glEnable(GL_COLOR_MATERIAL);

  return true;
}

float frand()
{
  return (rand()/float(RAND_MAX))*2.f - 1.f;
}

//called for every frame
void draw()
{
  prepareCamera();

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  float lightPos[] = { frand(), frand(), frand(), 0 };
  glLightfv(GL_LIGHT0, GL_POSITION, lightPos);

  drawText("Hold A to disable shader");
  if(!isKeyPressed('A'))
    glUseProgramObjectARB(g_program);

  drawSphere();

  glUseProgramObjectARB(0);

  fertig();
}

//called at program shutdown
void exit()
{
}

I just tried your program on a FX 5200 with 66.81 drivers. (disco type lighting on a sphere) No real difference between fixed and shader version.

What driver/card are you using?

I’m using a GeForce 6800 with 61.77 drivers - they are what I get when I go to nVidia.com -> drivers -> GeForce -> WinXP. Where can I get 61.81?

Thanks for the quick reply,
Nico

http://www.forum-3dcenter.org/vbulletin/showthread.php?t=173484

Hi,

just found it myself:
ftp://download.nvidia.com/Windows/66.81/
(was mentioned in another post in this forum).

Sorry for the noise…

Still makes me wonder why the nVidia website suggests to download 61.77 instead of 66.81.

Originally posted by Nico:
[b]Hi,

just found it myself:
ftp://download.nvidia.com/Windows/66.81/
(was mentioned in another post in this forum).

Sorry for the noise…

Still makes me wonder why the nVidia website suggests to download 61.77 instead of 66.81.[/b]
I have seen some people complaining about problems with 66.xx drivers that just occurs on GF 6800 family.

70.xx are floating around in the web and seems to solve the problems found on those cards with 66.xx

http://download.guru3d.com/detonator/

I’m very happy with the 66.81 driver - all the problems I had with GLSL vanished. 3dlabs GLSL parser test still says that only 48% of the tests work, but all the crashs are gone and most of the failed tests are of the “expected: error, actual: success” kind…

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.