On Tue, 16 Jul 2002, Keith Whitwell wrote:

> > Well, it's not high on my list.  I don't think flat-shading is used that
> > often, and the changes don't have any effect on smooth shading.  Actually, 
> > it _eliminates_ some saves/restores necessary for unfilled polygons with 
> > hardware flat-shading.
> >  
> > Actually, I think the problem is larger than mach64.  Rage128 has the same
> > problem and it appears to have GL compliant flat-shading based on the
> > primitive.  The problem is that for clipped polygons, the primitive type
> > changes, so flat-shading breaks down in that case (like with unfilled
> > polygons).  I think the templates would have to be changed to copy the
> > provoking-vertex color of the polygon being clipped into the vertices of
> > the triangles generated by clipping, rather than interpolating the color.
> 
> I'm surprised that this isn't working.  Can you verify?  I tested on the i810 
> at the time & definitely got clipping working there...

Here's a couple screenshots with the r128 driver (20020629 build):

http://www.retinalburn.net/linux/r128-unclipped-flat.png
http://www.retinalburn.net/linux/r128-clipped-flat.png

Allen's test program is attached.  Maybe someone could check this on 
Radeon with software tcl as well?

-- 
Leif Delgass 
http://www.retinalburn.net
/*
 * Clipped faces are not colored correctly with flat shading (except for
 * the yellow face which only has one color).
 * Use the left button to spin, middle button to zoom.
 */
#include <GL/glut.h>
static void init ( const char* filename )
{
  // Set the window's background color

  glClearColor( .25, .25, .25, 1. );
  glShadeModel( GL_FLAT );
  glEnable( GL_DEPTH_TEST );
}

static void display ( void )
{
  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

  glBegin( GL_QUAD_STRIP );
  glColor3f( 1., 0., 0. ); /* red */
  glVertex3f( -1., -1., -1. );
  glVertex3f( -1., -1., 1. );

  glColor3f( 0., 0., 1. ); /* blue */
  glVertex3f( -1., 1., -1. );
  glVertex3f( -1., 1., 1. );

  glColor3f( 0., 1., 0. ); /* green */
  glVertex3f( 1., 1., -1. );
  glVertex3f( 1., 1., 1. );

  glColor3f( 1., 0., 1. ); /* magenta */
  glVertex3f( 1., -1., -1. );
  glVertex3f( 1., -1., 1. );

  glColor3f( 1., 0., 0. ); /* red */
  glVertex3f( -1., -1., -1. );
  glVertex3f( -1., -1., 1. );
  glEnd();

  glBegin( GL_QUADS );
  glColor3f( 1., 0., 0. ); /* red */
  glVertex3f( -1., -1., -1. );
  glColor3f( 0., 0., 1. ); /* blue */
  glVertex3f( -1., 1., -1. );
  glColor3f( 0., 1., 0. ); /* green */
  glVertex3f( 1., 1., -1. );
  glColor3f( 0., 1., 1. ); /* cyan */
  glVertex3f( 1., -1. , -1. );

  glColor3f( 1., 1., 0. ); /* yellow */
  glVertex3f( -1., -1., 1. );
  glVertex3f( 1., -1. , 1. );
  glVertex3f( 1., 1., 1. );
  glVertex3f( -1., 1., 1. );
  glEnd();

  glutSwapBuffers();
}

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

  glMatrixMode( GL_PROJECTION );
  glLoadIdentity();
  glOrtho( -1.5, 1.5, -1.5, 1.5, -2, 2 );

  glMatrixMode( GL_MODELVIEW );
  glLoadIdentity();

  glRotatef( 40., 1., 0., 0. );
  glRotatef( 50., 0., 1., 0. );
  glRotatef( 10., 1., 0., 0. );
}

static enum MouseAction { NONE, SPIN, ZOOM } action = NONE;
static int m_x = 0;
static int m_y = 0;

static void mouse ( int button, int state, int x, int y )
{
  if ( button == 0 ) {
    if ( state == 0 )
      action = SPIN;
    else
      action = NONE;
  }
  else if ( button == 1 ) {
    if ( state == 0 )
      action = ZOOM;
    else
      action = NONE;
  }
  m_x = x;
  m_y = y;
}

static GLdouble modelview[16];

static void motion ( int x, int y )
{
  int dx = x - m_x;
  int dy = y - m_y;

  switch ( action ) {
  case SPIN:
    glRotated( dy, modelview[0], modelview[4], modelview[8] );
    glRotated( dx, modelview[1], modelview[5], modelview[9] );

    glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
    break;

  case ZOOM:
    glMatrixMode( GL_PROJECTION );
    if ( dy > 0 )
      glScalef( .99, .99, .99 );
    else
      glScalef( 1.01, 1.01, 1.01 );
    glMatrixMode( GL_MODELVIEW );
  }
  m_x = x;
  m_y = y;

  glutPostRedisplay();
}

static void key ( unsigned char key, int x, int y )
{
  switch ( key ) {
  case 27:
    exit( 0 );
  }
}

int main ( int argc, char* argv[] )
{
  // Standard GLUT setup commands

  glutInit( &argc, argv );
  glutInitWindowSize( 500, 500 );
  glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
  glutCreateWindow( argv[0] );

  printf( "%s %s\n", glGetString( GL_VERSION ), glGetString( GL_RENDERER ) );

  init( argv[1] );

  glutReshapeFunc( reshape );
  glutDisplayFunc( display );
  glutMouseFunc( mouse );
  glutMotionFunc( motion );
  glutKeyboardFunc( key );
  glutMainLoop();

  return 0;
}

Reply via email to