예제 #1
0
void
mouse(int button, int state, int x, int y)
{
  if (button == GLUT_LEFT_BUTTON) {
    if (state == GLUT_DOWN) {
      glutSetCursor(GLUT_CURSOR_LEFT_RIGHT);
      moving = 1;
      begin = x;
    } else if (state == GLUT_UP) {
      glutSetCursor(GLUT_CURSOR_INHERIT);
      moving = 0;
    }
  }
  if (overlaySupport && button == GLUT_MIDDLE_BUTTON) {
    if (state == GLUT_DOWN) {
      help = 0;
      clearHelp = 1;
      rubberbanding = 1;
      anchorx = x;
      anchory = y;
      stretchx = x;
      stretchy = y;
      glutShowOverlay();
    } else if (state == GLUT_UP) {
      rubberbanding = 0;
      glutHideOverlay();
      glutUseLayer(GLUT_NORMAL);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();

#undef max
#undef min
#define max(a,b)  ((a) > (b) ? (a) : (b))
#define min(a,b)  ((a) < (b) ? (a) : (b))

      wx = min(anchorx, stretchx);
      wy = min(H - anchory, H - stretchy);
      wx2 = max(anchorx, stretchx);
      wy2 = max(H - anchory, H - stretchy);
      ww = wx2 - wx;
      wh = wy2 - wy;
      if (ww == 0 || wh == 0) {
        glutUseLayer(GLUT_NORMAL);
        defaultProjection();
      } else {

        vx2 = wx2 / W * vw + vx;
        vx = wx / W * vw + vx;
        vy2 = wy2 / H * vh + vy;
        vy = wy / H * vh + vy;
        vw = vx2 - vx;
        vh = vy2 - vy;

        glFrustum(vx, vx + vw, vy, vy + vh, 1.0, 40);
      }
      glutPostRedisplay();
      glMatrixMode(GL_MODELVIEW);
    }
  }
}
예제 #2
0
void
mouse(int button, int state, int x, int y)
{
  GLdouble objx, objy, objz;

  gluUnProject(x, height - y, 0.95,
    modelMatrix, projMatrix, viewport,
    &objx, &objy, &objz);
  overlaySphere.x = objx;
  overlaySphere.y = objy;
  overlaySphere.z = objz;
  overlaySphere.material = button;
  glutUseLayer(GLUT_OVERLAY);
  glutSetColor(opaque,
    2 * matColor[button][0],  /* Red. */
    2 * matColor[button][1],  /* Green. */
    2 * matColor[button][2]);  /* Blue. */
  if (state == GLUT_UP) {
    glutHideOverlay();
    if (spheres < MAX_SPHERES) {
      sphereInfo[spheres] = overlaySphere;
      sphereInfo[spheres].detail = 25;  /* Fine tesselation. */
      spheres++;
    } else {
      printf("oversphere: Out of spheres.\n");
    }
    glutPostRedisplay();
  } else {
    overlaySphere.detail = 10;  /* Coarse tesselation. */
    glutShowOverlay();
    glutPostOverlayRedisplay();
  }
}
예제 #3
0
void
controlLights(int value)
{
  glutUseLayer(GLUT_NORMAL);
  switch (value) {
  case 1:
    lightZeroSwitch = !lightZeroSwitch;
    if (lightZeroSwitch) {
      glEnable(GL_LIGHT0);
    } else {
      glDisable(GL_LIGHT0);
    }
    break;
  case 2:
    lightOneSwitch = !lightOneSwitch;
    if (lightOneSwitch) {
      glEnable(GL_LIGHT1);
    } else {
      glDisable(GL_LIGHT1);
    }
    break;
  case 3:
    defaultProjection();
    break;
  case 4:
    fancy = 1;
    break;
  case 5:
    fancy = 0;
    wasFancy = 1;
    break;
  case 6:
    if (!rubberbanding)
      help = 1;
    glutShowOverlay();
    glutPostOverlayRedisplay();
    break;
  }
  glutPostRedisplay();
}
예제 #4
0
void
key(unsigned char c, int w, int h)
{
  int transP;

  printf("c=%d  w=%d h=%d\n", c, w, h);
  switch (c) {
  case 'e':
    glutEstablishOverlay();
    independent = 0;
    transP = glutLayerGet(GLUT_TRANSPARENT_INDEX);
    glClearIndex(transP);
    glutSetColor((transP + 1) % 2, 1.0, 1.0, 0.0);
    glIndexi((transP + 1) % 2);
    on = 1;
    break;
  case 'r':
    glutRemoveOverlay();
    on = 0;
    break;
  case 'm':
    if (glutLayerGet(GLUT_HAS_OVERLAY)) {
      int pixel;
      GLfloat red, green, blue;

      transP = glutLayerGet(GLUT_TRANSPARENT_INDEX);
      pixel = (transP + 1) % 2;
      red = glutGetColor(pixel, GLUT_RED) + 0.2;
      if (red > 1.0)
        red = red - 1.0;
      green = glutGetColor(pixel, GLUT_GREEN) - 0.1;
      if (green > 1.0)
        green = green - 1.0;
      blue = glutGetColor(pixel, GLUT_BLUE) + 0.1;
      if (blue > 1.0)
        blue = blue - 1.0;
      glutSetColor(pixel, red, green, blue);
    }
    break;
  case 'h':
    glutSetWindow(hidden_w);
    glutHideWindow();
    glutSetWindow(s2);
    glutHideWindow();
    break;
  case 's':
    glutSetWindow(hidden_w);
    glutShowWindow();
    glutSetWindow(s2);
    glutShowWindow();
    break;
  case 'H':
    glutHideOverlay();
    break;
  case 'S':
    glutShowOverlay();
    break;
  case 'D':
    glutDestroyWindow(main_w);
    exit(0);
    break;
  case ' ':
    printf("overlay possible: %d\n", glutLayerGet(GLUT_OVERLAY_POSSIBLE));
    printf("layer in  use: %d\n", glutLayerGet(GLUT_LAYER_IN_USE));
    printf("has overlay: %d\n", glutLayerGet(GLUT_HAS_OVERLAY));
    printf("transparent index: %d\n", glutLayerGet(GLUT_TRANSPARENT_INDEX));
    break;
  }
}
예제 #5
0
int
main(int argc, char **argv)
{
  glutInit(&argc, argv);
  glutInitWindowSize(300, 300);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_INDEX);

  if (!glutLayerGet(GLUT_OVERLAY_POSSIBLE)) {
    printf("UNRESOLVED: need overlays for this test (your window system lacks overlays)\n");
    exit(0);
  }
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  main_win = glutCreateWindow("test17");

  if (glutLayerGet(GLUT_LAYER_IN_USE) == GLUT_OVERLAY) {
    printf("FAIL: overlay should not be in use\n");
    exit(1);
  }
  if (glutLayerGet(GLUT_HAS_OVERLAY)) {
    printf("FAIL: overlay should not exist\n");
    exit(1);
  }
  if (glutLayerGet(GLUT_TRANSPARENT_INDEX) != -1) {
    printf("FAIL: transparent pixel of normal plane should be -1\n");
    exit(1);
  }
  if (glutLayerGet(GLUT_NORMAL_DAMAGED) != 0) {
    printf("FAIL: no normal damage yet\n");
    exit(1);
  }
  if (glutLayerGet(GLUT_OVERLAY_DAMAGED) != -1) {
    printf("FAIL: no overlay damage status yet\n");
    exit(1);
  }
  glClearColor(0.0, 1.0, 0.0, 0.0);

  glutInitDisplayMode(GLUT_SINGLE | GLUT_INDEX);

  /* Small torture test. */
  glutEstablishOverlay();
  glutRemoveOverlay();
  glutEstablishOverlay();
  glutEstablishOverlay();
  glutShowOverlay();
  glutHideOverlay();
  glutShowOverlay();
  glutRemoveOverlay();
  glutRemoveOverlay();
  glutEstablishOverlay();

  if (glutGet(GLUT_WINDOW_RGBA)) {
    printf("FAIL: overlay should not be RGBA\n");
    exit(1);
  }
  glutUseLayer(GLUT_NORMAL);
  if (!glutGet(GLUT_WINDOW_RGBA)) {
    printf("FAIL: normal should be RGBA\n");
    exit(1);
  }
  glutUseLayer(GLUT_OVERLAY);
  if (glutGet(GLUT_WINDOW_RGBA)) {
    printf("FAIL: overlay should not be RGBA\n");
    exit(1);
  }
  if (glutLayerGet(GLUT_LAYER_IN_USE) == GLUT_NORMAL) {
    printf("FAIL: overlay should be in use\n");
    exit(1);
  }
  if (glutLayerGet(GLUT_HAS_OVERLAY) == 0) {
    printf("FAIL: overlay should exist\n");
    exit(1);
  }
  if (glutLayerGet(GLUT_TRANSPARENT_INDEX) == -1) {
    printf("FAIL: transparent pixel should exist\n");
    exit(1);
  }
  if (glutLayerGet(GLUT_NORMAL_DAMAGED) != 0) {
    printf("FAIL: no normal damage yet\n");
    exit(1);
  }
  if (glutLayerGet(GLUT_OVERLAY_DAMAGED) != 0) {
    printf("FAIL: no overlay damage yet\n");
    exit(1);
  }
  transP = glutLayerGet(GLUT_TRANSPARENT_INDEX);
  glClearIndex(glutLayerGet(GLUT_TRANSPARENT_INDEX));
  glutSetColor((transP + 1) % 2, 1.0, 0.0, 1.0);
  glIndexi((transP + 1) % 2);

  glutUseLayer(GLUT_NORMAL);
  if (glutLayerGet(GLUT_LAYER_IN_USE) == GLUT_OVERLAY) {
    printf("FAIL: overlay should not be in use\n");
    exit(1);
  }
  glutDisplayFunc(display);

  glutMainLoop();
  return 0;             /* ANSI C requires main to return int. */
}
예제 #6
0
/*
 * Class:     gruenewa_opengl_GLUT__
 * Method:    glutShowOverlay
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_gruenewa_opengl_GLUT_00024_glutShowOverlay
  (JNIEnv * jenv, jobject jobj) {
   glutShowOverlay(); 
}