I report the bug about Color handling of glRasterPos.

As you know, glRasterPos memories RasterColor through shade.c:gl_shade_rastpos
function. When lighting is enabled, rgba value is calcurated and stored as
float [0, 1].

Sometimes, calcurated color values become over 1.0.
glBitmap function does not check if RasterColor is in range [0, 1],
so image is drawn with strange color.

This problem seems in MesaCVS.tar.gz and cvs -r mesa_3_2.
I created test program and patch. patch is for src/shade.c

Regards,

                                Takashi Matsuda
                                [EMAIL PROTECTED]

TEST PROGRAM:
--------------8<----------------------8<---------------------8<------------
#include <stdio.h>
#include <GL/gl.h>
#include <GL/glut.h>

static GLenum __gl_error;
#define GL_CHECK(expr) \
{                                                       \
  expr;                                                 \
  if ((__gl_error = glGetError ()) != GL_NO_ERROR) {    \
    fprintf (stderr, "%s:%d (%s): OpenGL error: %s",    \
             __FILE__,                                  \
             __LINE__,                                  \
             __PRETTY_FUNCTION__,                       \
             gluErrorString (__gl_error));              \
  }                                                     \
}

#define FADE_IN_INTERVAL 100
static int time = 0;
static int fade_in_time = 2000;
static GLfloat diffuse [4] = {1, 1, 1, 1};
static GLubyte rasters [24] = {
  0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
  0xff, 0x00, 0xff, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
  0xff, 0xc0, 0xff, 0xc0
};

static void display (void)
{
  GL_CHECK (glEnable (GL_COLOR_MATERIAL));
  GL_CHECK (glEnable (GL_LIGHTING));
  GL_CHECK (glEnable (GL_LIGHT0));

  GL_CHECK(glClearColor (0, 0, 0, 1));
  GL_CHECK(glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));

  GL_CHECK(glMatrixMode (GL_PROJECTION));
  GL_CHECK(glLoadIdentity ());
  GL_CHECK(glOrtho (-1, 1, -1, 1, -1, 1));

  GL_CHECK(glMatrixMode (GL_MODELVIEW));
  GL_CHECK(glLoadIdentity ());

  GL_CHECK(glPixelStorei (GL_UNPACK_ALIGNMENT, 1));
  GL_CHECK(glColor3f (1, 1, 1));
  GL_CHECK(glRasterPos2i (0, 0));
  GL_CHECK(glBitmap (10, 12, 0, 0, 11, 0, rasters));

  GL_CHECK(glFlush ());
  GL_CHECK(glutSwapBuffers ());
}

static void reshape (int width, int height)
{
  GL_CHECK(glViewport (0, 0, width, height));

  glutPostRedisplay ();
}

static void keyboard (unsigned char key, int x, int y)
{
  if (key == 27) {
    exit (0);
  }
}

static void timer (int value)
{
  GLfloat f[4];
  float scale;

  scale = (double)(time) / fade_in_time;

  f[0] = scale * diffuse[0];
  f[1] = scale * diffuse[1];
  f[2] = scale * diffuse[2];
  f[3] = diffuse[3];

  glLightfv (GL_LIGHT0, GL_DIFFUSE, f);

  time += FADE_IN_INTERVAL;

  if (time <= fade_in_time) {
    glutTimerFunc (FADE_IN_INTERVAL, timer, value);
  }

  glutPostRedisplay ();
}

int main (int argc, char **argv)
{
  glutInit (&argc, argv);

  glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
  glutCreateWindow ("testgl");
  glutDisplayFunc (display);
  glutReshapeFunc (reshape);
  glutKeyboardFunc (keyboard);

  timer (0);

  glutMainLoop ();

  return 0;
}

PATCH:
--------------8<----------------------8<---------------------8<------------
*** shade.c.old Tue Nov  9 00:29:57 1999
--- shade.c     Sun Nov 28 02:42:22 1999
***************
*** 354,360 ****
--- 354,367 ----
     } 
  
     if (ctx->Visual->RGBAflag) {
+ #if 1
+       Rcolor[0] = CLAMP( color[0], 0.0F, 1.0F );
+       Rcolor[1] = CLAMP( color[1], 0.0F, 1.0F );
+       Rcolor[2] = CLAMP( color[2], 0.0F, 1.0F );
+       Rcolor[3] = CLAMP( color[3], 0.0F, 1.0F );
+ #else
        COPY_4FV(Rcolor, color);
+ #endif
     } else {
        GLfloat ind;
        struct gl_material *mat = &ctx->Light.Material[0];


_______________________________________________
Mesa-bug maillist  -  [EMAIL PROTECTED]
http://lists.mesa3d.org/mailman/listinfo/mesa-bug


_______________________________________________
Mesa-dev maillist  -  [EMAIL PROTECTED]
http://lists.mesa3d.org/mailman/listinfo/mesa-dev

Reply via email to