Hi,

I made a small programme to illustrate the TCL/SW lighting differences.
It displays a square consisting of 10x10 quads which is lit by one
lightsource. The distance between the lightsource and the square is
changed periodically. With TCL this has the desired effect, with
software lighting it doesn't have any effect at all. This looks like an
optimization that assumes lightsources to be at infinite distance. I
attached the programme. With a macro you can switch between diffuse and
specular lighting.

So the lighting problem described with FlightGear could actually be a
bug in FlightGear that just isn't visible with software lighting.

Best regards,
   Felix

               __\|/__    ___     ___     ___
__Tschüß_______\_6 6_/___/__ \___/__ \___/___\___You can do anything,___
_____Felix_______\Ä/\ \_____\ \_____\ \______U___just not everything____
  [EMAIL PROTECTED]    >o<__/   \___/   \___/        at the same time!
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <math.h>

void init () {
    glClearColor (0.0, 0.0, 0.0, 0.0);
    glShadeModel (GL_FLAT);
}

#define USE_ARRAYS
#define SHOW_SPECULAR

#define MAX_QUADS 20
void manyQuads (GLfloat x0, GLfloat y0, GLfloat z0,
		GLfloat x1, GLfloat y1, GLfloat z1,
		GLfloat x2, GLfloat y2, GLfloat z2,
		GLfloat x3, GLfloat y3, GLfloat z3,
		GLint n, GLint m) {
    GLfloat vertices[MAX_QUADS+1][MAX_QUADS+1][3];
    GLint a, b;

    for (a = 0; a <= n; ++a) {
	GLfloat xa0, ya0, za0, xa1, ya1, za1;
	xa0 = x0 + (x1 - x0)*a / n;
	xa1 = x3 + (x2 - x3)*a / n;
	ya0 = y0 + (y1 - y0)*a / n;
	ya1 = y3 + (y2 - y3)*a / n;
	za0 = z0 + (z1 - z0)*a / n;
	za1 = z3 + (z2 - z3)*a / n;
	for (b = 0; b <= m; ++b) {
	    vertices[a][b][0] = xa0 + (xa1 - xa0)*b / m;
	    vertices[a][b][1] = ya0 + (ya1 - ya0)*b / m;
	    vertices[a][b][2] = za0 + (za1 - za0)*b / m;
	}
    }

#ifdef USE_ARRAYS
    glEnableClientState (GL_VERTEX_ARRAY);
    glVertexPointer (3, GL_FLOAT, 0, vertices);
#endif
    glBegin (GL_QUADS);
    for (a = 0; a < n; ++a)
	for (b = 0; b < m; ++b) {
#ifdef USE_ARRAYS
	    glArrayElement (a*(MAX_QUADS+1)+b);
	    glArrayElement ((a+1)*(MAX_QUADS+1)+b);
	    glArrayElement ((a+1)*(MAX_QUADS+1)+b+1);
	    glArrayElement (a*(MAX_QUADS+1)+b+1);
#else
	    glVertex3fv (vertices[a][b]);
	    glVertex3fv (vertices[a+1][b]);
	    glVertex3fv (vertices[a+1][b+1]);
	    glVertex3fv (vertices[a][b+1]);
#endif
	}
    glEnd ();
#ifdef USE_ARRAYS
    glDisableClientState (GL_VERTEX_ARRAY);
#endif
}

int timestep;
#define omega 0.01
void display () {
    GLfloat lightpos[3] = {0.0, 10.0, 0.0};
    GLfloat diffuse[4] = {0.0, 0.0, 0.0, 1.0};
    GLfloat specular[4] = {1.0, 1.0, 1.0, 1.0};
    timestep++;

    lightpos[1] = 1.0 + sinf (omega*timestep);
  /*lightpos[2] = cosf (omega*timestep);*/

    glLoadIdentity ();
    gluLookAt (0.0, 2.0, 0.1, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

    glEnable (GL_LIGHTING);
    glEnable (GL_LIGHT0);
    glShadeModel (GL_SMOOTH);
    glLightfv (GL_LIGHT0, GL_POSITION, lightpos);
#ifdef SHOW_SPECULAR
    glMaterialfv (GL_FRONT, GL_DIFFUSE, diffuse);
    glMaterialfv (GL_FRONT, GL_SPECULAR, specular);
    glMaterialf (GL_FRONT, GL_SHININESS, 2);
#endif

    glClear (GL_COLOR_BUFFER_BIT);
    glColor3f (1.0, 1.0, 1.0);
    glNormal3f (0.0, 1.0, 0.0);
    manyQuads (-1.0, 0.0, -1.0,
	       1.0, 0.0, -1.0,
	       1.0, 0.0, 1.0,
	       -1.0, 0.0, 1.0, 10, 10);
    glutSwapBuffers();
}

void reshape (int w, int h) {
    glViewport (0, 0, (GLsizei) w, (GLsizei) h);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
    glMatrixMode (GL_MODELVIEW);
}

int main (int argc, char *argv[]) {
    int winId;

    glutInit (&argc, argv);
    glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE);
    glutInitWindowSize (500, 500);
    glutInitWindowPosition (100, 100);
    winId = glutCreateWindow ("Light Test");
    init ();
    glutDisplayFunc (display);
    glutReshapeFunc (reshape);
    glutIdleFunc (display);

    glutMainLoop ();
    return 0;
}

Reply via email to