Example #1
0
int
main(int argc, char **argv)
{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  glutCreateWindow("zoomdino");
  glutDisplayFunc(redraw);
  glutMouseFunc(mouse);
  glutMotionFunc(motion);
  glutCreateMenu(controlLights);
  glutAddMenuEntry("Toggle right light", 1);
  glutAddMenuEntry("Toggle left light", 2);
  glutAttachMenu(GLUT_RIGHT_BUTTON);
  makeDinosaur();
  glEnable(GL_CULL_FACE);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_LIGHTING);
  defaultProjection();
  gluLookAt(0.0, 0.0, 30.0,  /* eye is at (0,0,30) */
    0.0, 0.0, 0.0,      /* center is at (0,0,0) */
    0.0, 1.0, 0.);      /* up is in postivie Y direction */
  glPushMatrix();       /* dummy push so we can pop on model
                           recalc */
  glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
  glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
  glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1);
  glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05);
  glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
  glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHT1);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_INDEX);
  overlaySupport = glutLayerGet(GLUT_OVERLAY_POSSIBLE);
  if (overlaySupport) {
    glutEstablishOverlay();
    glutHideOverlay();
    transparent = glutLayerGet(GLUT_TRANSPARENT_INDEX);
    glClearIndex(transparent);
    red = (transparent + 1) % glutGet(GLUT_WINDOW_COLORMAP_SIZE);
    white = (transparent + 2) % glutGet(GLUT_WINDOW_COLORMAP_SIZE);
    glutSetColor(red, 1.0, 0.0, 0.0);  /* Red. */
    glutSetColor(white, 1.0, 1.0, 1.0);  /* White. */
    glutOverlayDisplayFunc(redrawOverlay);
    glutReshapeFunc(reshape);
    glutSetWindowTitle("zoomdino with rubber-banding");
    glutAddMenuEntry("------------------", 0);
    glutAddMenuEntry("Reset projection", 3);
    glutAddMenuEntry("------------------", 0);
    glutAddMenuEntry("Fancy rubber-banding", 4);
    glutAddMenuEntry("Simple rubber-banding", 5);
    glutAddMenuEntry("------------------", 0);
    glutAddMenuEntry("Show help", 6);
  } else {
    printf("Sorry, no whizzy zoomdino overlay usage!\n");
  }
  glutMainLoop();
  return 0;             /* ANSI C requires main to return int. */
}
Example #2
0
void
drawDinosaur(void) {
    static int first = 1;
    if (first) {
	makeDinosaur();
	first = 0;
    }
    glCallList(DINOSAUR);
}
Example #3
0
int
main(int argc, char **argv)
{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL);
  trackball(curquat, 0.0, 0.0, 0.0, 0.0);
  glutInitWindowSize(600, 300);
  glutCreateWindow("dinodraw");
  glutDisplayFunc(redraw);
  glutReshapeFunc(myReshape);
  glutVisibilityFunc(vis);
  glutMouseFunc(mouse);
  glutMotionFunc(motion);
  glutCreateMenu(controlLights);
  glutAddMenuEntry("Toggle right light", 1);
  glutAddMenuEntry("Toggle left light", 2);
  if (glutGet(GLUT_WINDOW_NUM_SAMPLES) > 0) {
    glutAddMenuEntry("Toggle multisampling", 3);
    glutSetWindowTitle("dinospin (multisample capable)");
  }
  glutAddMenuEntry("Full screen", 4);
  glutAddMenuEntry("Quit", 5);
  glutAttachMenu(GLUT_RIGHT_BUTTON);
  makeDinosaur();
  glEnable(GL_CULL_FACE);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_LIGHTING);
  glMatrixMode(GL_PROJECTION);
  gluPerspective( /* field of view in degree */ 40.0,
  /* aspect ratio */ 1.0,
    /* Z near */ 1.0, /* Z far */ 40.0);
  glMatrixMode(GL_MODELVIEW);
  gluLookAt(0.0, 0.0, 30.0,  /* eye is at (0,0,30) */
    0.0, 0.0, 0.0,      /* center is at (0,0,0) */
    0.0, 1.0, 0.);      /* up is in positive Y direction */
  glPushMatrix();       /* dummy push so we can pop on model
                           recalc */
  glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
  glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
  glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1);
  glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05);
  glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
  glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHT1);
  glLineWidth(2.0);
  glutMainLoop();
  return 0;             /* ANSI C requires main to return int. */
}
Example #4
0
int
main(int argc, char **argv)
{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
  glutCreateWindow("dinoball (Spaceball demo)");
  glutDisplayFunc(redraw);
  glutMouseFunc(mouse);
  glutMotionFunc(motion);
  glutTabletMotionFunc(tablet);
  glutSpaceballMotionFunc(translate);
  glutSpaceballRotateFunc(rotate);
  glutSpaceballButtonFunc(button);
  glutDialsFunc(dials);
  glutCreateMenu(controlLights);
  glutAddMenuEntry("Toggle right light", 1);
  glutAddMenuEntry("Toggle left light", 2);
  glutAttachMenu(GLUT_RIGHT_BUTTON);
  makeDinosaur();
  glEnable(GL_CULL_FACE);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_LIGHTING);
  glMatrixMode(GL_PROJECTION);
  gluPerspective( /* field of view in degree */ 40.0,
  /* aspect ratio */ 1.0,
    /* Z near */ 1.0, /* Z far */ 100.0);
  glMatrixMode(GL_MODELVIEW);
  gluLookAt(0.0, 0.0, 30.0,  /* eye is at (0,0,30) */
    0.0, 0.0, 0.0,      /* center is at (0,0,0) */
    0.0, 1.0, 0.);      /* up is in positive Y direction */
  glPushMatrix();       /* dummy push so we can pop on model
                           recalc */
  glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
  glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
  glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1);
  glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05);
  glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
  glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHT1);
  glutMainLoop();
  return 0;             /* ANSI C requires main to return int. */
}
Example #5
0
int
main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL);
    glutCreateWindow("Leapin' Lizards");
    glutDisplayFunc(redraw);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutVisibilityFunc(visible);
    glutCreateMenu(controlLights);
    glutAddMenuEntry("Toggle right light", 1);
    glutAddMenuEntry("Toggle left light", 2);
    glutAddMenuEntry("Toggle stenciling out reflection artifacts", 3);
    glutAttachMenu(GLUT_RIGHT_BUTTON);
    makeDinosaur();
    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glMatrixMode(GL_PROJECTION);
    gluPerspective( /* field of view in degree */ 40.0,
            /* aspect ratio */ 1.0,
            /* Z near */ 1.0, /* Z far */ 80.0);
    glMatrixMode(GL_MODELVIEW);
    gluLookAt(0.0, 0.0, 40.0,  /* eye is at (0,0,30) */
              0.0, 0.0, 0.0,      /* center is at (0,0,0) */
              0.0, 1.0, 0.);      /* up is in postivie Y direction */
    glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
    glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1);
    glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05);
    glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHT1);

    glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
    glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);

    glutMainLoop();
    return 0;             /* ANSI C requires main to return int. */
}
Example #6
0
int
main(int argc, char **argv)
{
  int i;

  glutInit(&argc, argv);

  for (i=1; i<argc; i++) {
    if (!strcmp("-linear", argv[i])) {
      linearFiltering = 1;
    } else if (!strcmp("-mipmap", argv[i])) {
      useMipmaps = 1;
    } else if (!strcmp("-ext", argv[i])) {
      forceExtension = 1;
    }
  }

  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL);

#if 0
  /* In GLUT 4.0, you'll be able to do this an be sure to
     get 2 bits of stencil if the machine has it for you. */
  glutInitDisplayString("samples stencil>=2 rgb double depth");
#endif

  glutCreateWindow("Shadowy Leapin' Lizards");
  glewInit();

  if (glutGet(GLUT_WINDOW_STENCIL_SIZE) <= 1) {
    printf("dinoshade: Sorry, I need at least 2 bits of stencil.\n");
    exit(1);
  }

  /* Register GLUT callbacks. */
  glutDisplayFunc(redraw);
  glutMouseFunc(mouse);
  glutMotionFunc(motion);
  glutVisibilityFunc(visible);
  glutKeyboardFunc(key);
  glutSpecialFunc(special);

  glutCreateMenu(controlLights);

  glutAddMenuEntry("Toggle motion", M_MOTION);
  glutAddMenuEntry("-----------------------", M_NONE);
  glutAddMenuEntry("Toggle light", M_LIGHT);
  glutAddMenuEntry("Toggle texture", M_TEXTURE);
  glutAddMenuEntry("Toggle shadows", M_SHADOWS);
  glutAddMenuEntry("Toggle reflection", M_REFLECTION);
  glutAddMenuEntry("Toggle dinosaur", M_DINOSAUR);
  glutAddMenuEntry("-----------------------", M_NONE);
  glutAddMenuEntry("Toggle reflection stenciling", M_STENCIL_REFLECTION);
  glutAddMenuEntry("Toggle shadow stenciling", M_STENCIL_SHADOW);
  glutAddMenuEntry("Toggle shadow offset", M_OFFSET_SHADOW);
  glutAddMenuEntry("----------------------", M_NONE);
  glutAddMenuEntry("Positional light", M_POSITIONAL);
  glutAddMenuEntry("Directional light", M_DIRECTIONAL);
  glutAddMenuEntry("-----------------------", M_NONE);
  glutAddMenuEntry("Toggle performance", M_PERFORMANCE);
  glutAttachMenu(GLUT_RIGHT_BUTTON);
  makeDinosaur();

#ifdef GL_VERSION_1_1
  if (GLEW_VERSION_1_1 && !forceExtension) {
    polygonOffsetVersion = ONE_DOT_ONE;
    glPolygonOffset(-2.0, -9.0);
  } else
#endif
  {
#ifdef GL_EXT_polygon_offset
  /* check for the polygon offset extension */
  if (GLEW_EXT_polygon_offset) {
    polygonOffsetVersion = EXTENSION;
    glPolygonOffsetEXT(-2.0, -0.002);
  } else 
#endif
    {
      polygonOffsetVersion = MISSING;
      printf("\ndinoshine: Missing polygon offset.\n");
      printf("           Expect shadow depth aliasing artifacts.\n\n");
      fflush(stdout);
    }
  }

  glEnable(GL_CULL_FACE);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_TEXTURE_2D);
  glLineWidth(3.0);

  glMatrixMode(GL_PROJECTION);
  gluPerspective( /* field of view in degree */ 40.0,
  /* aspect ratio */ 1.0,
    /* Z near */ 20.0, /* Z far */ 100.0);
  glMatrixMode(GL_MODELVIEW);
  gluLookAt(0.0, 8.0, 60.0,  /* eye is at (0,8,60) */
    0.0, 8.0, 0.0,      /* center is at (0,8,0) */
    0.0, 1.0, 0.);      /* up is in postivie Y direction */

  glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);
  glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1);
  glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHTING);

  makeFloorTexture();

  /* Setup floor plane for projected shadow calculations. */
  findPlane(floorPlane, floorVertices[1], floorVertices[2], floorVertices[3]);

  glutMainLoop();
  return 0;             /* ANSI C requires main to return int. */
}
Example #7
0
int
main(int argc, char **argv)
{
  int width, height;
  int i;
  GLubyte *imageData;

  glutInit(&argc, argv);
  for (i=1; i<argc; i++) {
    if (!strcmp("-lesstex", argv[i])) {
      /* Only use 16 caustic textures.  Saves texture memory and works
	 better on slow machines. */
      causticIncrement = 2;
    } else if (!strcmp("-evenlesstex", argv[i])) {
      /* Only use 8 caustic textures.  Saves even more texture memory for
	 slow machines.  Temporal rippling suffers. */
      causticIncrement = 4;
    } else if (!strcmp("-nomipmap", argv[i])) {
      /* Don't use linear mipmap linear texture filtering; instead
	 use linear filtering. */
      useMipmaps = 0;
    } else if (!strcmp("-fullscreen", argv[i])) {
      fullscreen = 1;
    } else {
      fprintf(stderr, "usage: caustics [-lesstex]\n");
      fprintf(stderr, "       -lesstex uses half the caustic textures.\n");
      fprintf(stderr, "       -evenlesstex uses one fourth of the caustic textures.\n");
      exit(1);
    }
  }

  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
  if (fullscreen) {
    glutGameModeString("800x600:16@60");
    glutEnterGameMode();
  } else {
    glutCreateWindow("underwater");
  }

  /* Check that renderer has the GL_EXT_texture_object
     extension or supports OpenGL 1.1 */
#ifdef TEXTURE_OBJECT
  {
    char *version = (char *) glGetString(GL_VERSION);
    if (glutExtensionSupported("GL_EXT_texture_object")
      || strncmp(version, "1.1", 3) == 0) {
      HaveTexObj = GL_TRUE;
    }
  }
#endif

  glEnable(GL_TEXTURE_2D);
#ifdef TEXTURE_OBJECT  /* Replace texture environment not in OpenGL 1.0. */
  if (HaveTexObj)
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
#endif

  /* Load the caustic ripple textures. */
  printf("loading caustics:");
  for (i=0; i<NUM_PATTERNS; i += causticIncrement) {
    char filename[80];

    sprintf(filename, "caust%02d.bw", i);
    printf(" %d", i);
    fflush(stdout);
    imageData = read_alpha_texture(filename, &width, &height);
    if (imageData == NULL) {
      fprintf(stderr, "\n%s: could not load image file\n", filename);
      exit(1);
    }
    if (HaveTexObj)
      glBindTexture(GL_TEXTURE_2D, i+1);
    else
      glNewList(i+101, GL_COMPILE);
    if (useMipmaps) {
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
      gluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE, width, height,
        GL_LUMINANCE, GL_UNSIGNED_BYTE, imageData);
    } else {
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
      glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, height, width, 0,
        GL_LUMINANCE, GL_UNSIGNED_BYTE, imageData);
    }
    free(imageData);
    if (!HaveTexObj)
      glEndList();
  }
  printf(".\n");

  /* Load an RGB file for the floor texture. */
  printf("loading RGB textures: floor");
  fflush(stdout);
  imageData = read_rgb_texture(FLOOR_FILE, &width, &height);
  if (imageData == NULL) {
    fprintf(stderr, "%s: could not load image file\n", FLOOR_FILE);
    exit(1);
  }
  printf(".\n");

  if (HaveTexObj)
    glBindTexture(GL_TEXTURE_2D, 100);
  else
    glNewList(100, GL_COMPILE);
  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  if (useMipmaps) {
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB,
      GL_UNSIGNED_BYTE, imageData);
  } else {
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0,
      GL_RGB, GL_UNSIGNED_BYTE, imageData);
  }
  free(imageData);
  if (!HaveTexObj)
    glEndList();

  glMatrixMode(GL_MODELVIEW);
  gluLookAt(0.0, 8.0, 60.0,  /* eye is at (0,8,60) */
    0.0, 8.0, 0.0,      /* center is at (0,8,0) */
    0.0, 1.0, 0.);      /* up is in postivie Y direction */

  /* Setup initial OpenGL rendering state. */
  glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuseColor);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHTING);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_CULL_FACE);

  /* Register assorted GLUT callback routines. */
  glutDisplayFunc(display);
  glutReshapeFunc(reshape);
  glutVisibilityFunc(visible);
  glutMouseFunc(mouse);
  glutMotionFunc(motion);
  glutKeyboardFunc(keyboard);

  /* Create a pop-up menu. */
  if (!fullscreen) {
    glutCreateMenu(menuSelect);
    glutAddMenuEntry("Positional light", M_POSITIONAL);
    glutAddMenuEntry("Directional light", M_DIRECTIONAL);
    glutAddMenuEntry("Greenish light", M_GREENISH_LIGHT);
    glutAddMenuEntry("White light", M_WHITE_LIGHT);
    glutAddMenuEntry("With caustics", M_WITH_CAUSTICS);
    glutAddMenuEntry("No caustics", M_NO_CAUSTICS);
    glutAddMenuEntry("Switch model", M_SWITCH_MODEL);
    glutAddMenuEntry("Increase ripple size", M_INCREASE_RIPPLE_SIZE);
    glutAddMenuEntry("Decrease ripple size", M_DECREASE_RIPPLE_SIZE);
    glutAttachMenu(GLUT_RIGHT_BUTTON);
  }

  /* For rendering the MODEL_DINO object. */
  dinoDisplayList = makeDinosaur();

  /* Enter GLUT's main loop; callback dispatching begins. */
  glutMainLoop();
  return 0;             /* ANSI C requires main to return int. */
}