Ejemplo n.º 1
0
 private static void initControls() {
   // Automatically create mouse, keyboard and controller
   if (!getPrivilegedBoolean("org.lwjgl.opengl.Display.noinput")) {
     if (!Mouse.isCreated() && !getPrivilegedBoolean("org.lwjgl.opengl.Display.nomouse")) {
       try {
         Mouse.create();
       } catch (LWJGLException e) {
         if (LWJGLUtil.DEBUG) {
           e.printStackTrace(System.err);
         } else {
           LWJGLUtil.log("Failed to create Mouse: " + e);
         }
       }
     }
     if (!Keyboard.isCreated() && !getPrivilegedBoolean("org.lwjgl.opengl.Display.nokeyboard")) {
       try {
         Keyboard.create();
       } catch (LWJGLException e) {
         if (LWJGLUtil.DEBUG) {
           e.printStackTrace(System.err);
         } else {
           LWJGLUtil.log("Failed to create Keyboard: " + e);
         }
       }
     }
   }
 }
Ejemplo n.º 2
0
  private void restoreDisplayMode() {
    try {
      doSetGammaRamp(current_gamma);
    } catch (LWJGLException e) {
      LWJGLUtil.log("Failed to restore gamma: " + e.getMessage());
    }

    if (!mode_set) {
      mode_set = true;
      try {
        nSwitchDisplayMode(current_mode);
      } catch (LWJGLException e) {
        LWJGLUtil.log("Failed to restore display mode: " + e.getMessage());
      }
    }
  }
Ejemplo n.º 3
0
 private void updateCursor() {
   try {
     if (mouse != null && shouldGrab()) nSetNativeCursor(getHwnd(), mouse.getBlankCursor());
     else nSetNativeCursor(getHwnd(), current_cursor);
   } catch (LWJGLException e) {
     LWJGLUtil.log("Failed to update cursor: " + e);
   }
 }
Ejemplo n.º 4
0
 public boolean openURL(String url) {
   try {
     FileManager.openURL(url);
     return true;
   } catch (Exception e) {
     LWJGLUtil.log("Exception occurred while trying to invoke browser: " + e);
     return false;
   }
 }
Ejemplo n.º 5
0
 public int getPbufferCapabilities() {
   try {
     // Return the capabilities of a minimum pixel format
     return nGetPbufferCapabilities(new PixelFormat(0, 0, 0, 0, 0, 0, 0, 0, false));
   } catch (LWJGLException e) {
     LWJGLUtil.log("Exception occurred while determining pbuffer capabilities: " + e);
     return 0;
   }
 }
Ejemplo n.º 6
0
 private static void makeCurrentAndSetSwapInterval() throws LWJGLException {
   makeCurrent();
   try {
     drawable.checkGLError();
   } catch (OpenGLException e) {
     LWJGLUtil.log("OpenGL error during context creation: " + e.getMessage());
   }
   setSwapInterval(swap_interval);
 }
Ejemplo n.º 7
0
 static void resetCursorClipping() {
   if (cursor_clipped) {
     try {
       clipCursor(null);
     } catch (LWJGLException e) {
       LWJGLUtil.log("Failed to reset cursor clipping: " + e);
     }
     cursor_clipped = false;
   }
 }
Ejemplo n.º 8
0
 static {
   Sys.initialize();
   display_impl = createDisplayImplementation();
   try {
     current_mode = initial_mode = display_impl.init();
     LWJGLUtil.log("Initial mode: " + initial_mode);
   } catch (LWJGLException e) {
     throw new RuntimeException(e);
   }
   ;
 }
Ejemplo n.º 9
0
 private static void releaseDrawable() {
   try {
     Context context = drawable.getContext();
     if (context != null && context.isCurrent()) {
       context.releaseCurrent();
       context.releaseDrawable();
     }
   } catch (LWJGLException e) {
     LWJGLUtil.log("Exception occurred while trying to release context: " + e);
   }
 }
 /**
  * @see #PLATFORM_WINDOWS_NAME
  * @see #PLATFORM_LINUX_NAME
  * @see #PLATFORM_MACOSX_NAME
  * @return current platform name
  */
 public static String getPlatformName() {
   switch (LWJGLUtil.getPlatform()) {
     case LWJGLUtil.PLATFORM_LINUX:
       return PLATFORM_LINUX_NAME;
     case LWJGLUtil.PLATFORM_MACOSX:
       return PLATFORM_MACOSX_NAME;
     case LWJGLUtil.PLATFORM_WINDOWS:
       return PLATFORM_WINDOWS_NAME;
     default:
       return "unknown";
   }
 }
Ejemplo n.º 11
0
 private static DisplayImplementation createDisplayImplementation() {
   switch (LWJGLUtil.getPlatform()) {
     case LWJGLUtil.PLATFORM_LINUX:
       return new LinuxDisplay();
     case LWJGLUtil.PLATFORM_WINDOWS:
       return new WindowsDisplay();
     case LWJGLUtil.PLATFORM_MACOSX:
       return new MacOSXDisplay();
     default:
       throw new IllegalStateException("Unsupported platform");
   }
 }
Ejemplo n.º 12
0
 public static GLContext createFromCurrent() {
   switch (LWJGLUtil.getPlatform()) {
     case WINDOWS:
       return WindowsGLContext.createFromCurrent();
     case LINUX:
       return LinuxGLContext.createFromCurrent();
     case MACOSX:
       return MacOSXGLContext.createFromCurrent();
     default:
       throw new IllegalStateException();
   }
 }
Ejemplo n.º 13
0
 public void resetDisplayMode() {
   try {
     doSetGammaRamp(saved_gamma);
   } catch (LWJGLException e) {
     LWJGLUtil.log("Failed to reset gamma ramp: " + e.getMessage());
   }
   current_gamma = saved_gamma;
   if (mode_set) {
     mode_set = false;
     nResetDisplayMode();
   }
   resetCursorClipping();
 }
Ejemplo n.º 14
0
 private void updateClipping() {
   if ((Display.isFullscreen() || (mouse != null && mouse.isGrabbed()))
       && !isMinimized
       && isFocused
       && (getForegroundWindow() == getHwnd() || hasParent)) {
     try {
       setupCursorClipping(getHwnd());
     } catch (LWJGLException e) {
       LWJGLUtil.log("setupCursorClipping failed: " + e.getMessage());
     }
   } else {
     resetCursorClipping();
   }
 }
 /**
  * Method to determine if the current system is running a version of Mac OS X better than the
  * given version. This is only useful for Mac OS X specific code and will not work for any other
  * platform.
  */
 public static boolean isMacOSXEqualsOrBetterThan(int major_required, int minor_required) {
   String os_version = getPrivilegedProperty("os.version");
   StringTokenizer version_tokenizer = new StringTokenizer(os_version, ".");
   int major;
   int minor;
   try {
     String major_str = version_tokenizer.nextToken();
     String minor_str = version_tokenizer.nextToken();
     major = Integer.parseInt(major_str);
     minor = Integer.parseInt(minor_str);
   } catch (Exception e) {
     LWJGLUtil.log("Exception occurred while trying to determine OS version: " + e);
     // Best guess, no
     return false;
   }
   return major > major_required || (major == major_required && minor >= minor_required);
 }
Ejemplo n.º 16
0
  public static void main(String[] args) throws Exception {
    System.setProperty(
        "org.lwjgl.librarypath",
        new File(new File("lib\\native"), LWJGLUtil.getPlatformName()).getAbsolutePath());
    System.setProperty(
        "net.java.games.input.librarypath", System.getProperty("org.lwjgl.librarypath"));

    try {
      AppGameContainer appgc =
          new AppGameContainer(
              new Game(GAME_TITLE)); // Makes a new game container with the specified title.
      appgc.setDisplayMode(640, 400, false); // Sets the screen size to 640x400.
      appgc.setTargetFrameRate(60); // Sets the frame rate to 60.
      appgc.start(); // Starts the game.
    } catch (SlickException e) {
      e.printStackTrace(); // Prints an error if it doesn't work.
    }
  }
Ejemplo n.º 17
0
  public static void main(String[] args) {
    // TODO Auto-generated method stub

    // This  is used to find out which OS is being used
    System.setProperty(
        "org.lwjgl.librarypath",
        new File(new File(System.getProperty("user.dir"), "native"), LWJGLUtil.getPlatformName())
            .getAbsolutePath());
    try {
      AppGameContainer app = new AppGameContainer(new Game("Game"));
      app.setDisplayMode(1050, 750, false);
      app.setTargetFrameRate(60);
      app.setShowFPS(false);
      app.start();
    } catch (SlickException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 18
0
  /**
   * Returns the entire list of possible fullscreen display modes as an array, in no particular
   * order. Although best attempts to filter out invalid modes are done, any given mode is not
   * guaranteed to be available nor is it guaranteed to be within the current monitor specs (this is
   * especially a problem with the frequency parameter). Furthermore, it is not guaranteed that
   * create() will detect an illegal display mode.
   *
   * <p>The only certain way to check is to call create() and make sure it works. Only
   * non-palette-indexed modes are returned (ie. bpp will be 16, 24, or 32). Only DisplayModes from
   * this call can be used when the Display is in fullscreen mode.
   *
   * @return an array of all display modes the system reckons it can handle.
   */
  public static DisplayMode[] getAvailableDisplayModes() throws LWJGLException {
    synchronized (GlobalLock.lock) {
      DisplayMode[] unfilteredModes = display_impl.getAvailableDisplayModes();

      if (unfilteredModes == null) {
        return new DisplayMode[0];
      }

      // We'll use a HashSet to filter out the duplicated modes
      HashSet<DisplayMode> modes = new HashSet<DisplayMode>(unfilteredModes.length);

      modes.addAll(Arrays.asList(unfilteredModes));
      DisplayMode[] filteredModes = new DisplayMode[modes.size()];
      modes.toArray(filteredModes);

      LWJGLUtil.log(
          "Removed " + (unfilteredModes.length - filteredModes.length) + " duplicate displaymodes");

      return filteredModes;
    }
  }
Ejemplo n.º 19
0
  public void update() {
    nUpdate();

    if (!isFocused && parent != null && parent_focused.compareAndSet(true, false)) {
      setFocus(getHwnd());
    }

    if (redoMakeContextCurrent) {
      redoMakeContextCurrent = false;
      /**
       * WORKAROUND: Making the context current (redundantly) when the window is maximized helps
       * some gfx cards recover from fullscreen
       */
      try {
        Context context = ((DrawableLWJGL) Display.getDrawable()).getContext();
        if (context != null && context.isCurrent()) context.makeCurrent();
      } catch (LWJGLException e) {
        LWJGLUtil.log("Exception occurred while trying to make context current: " + e);
      }
    }
  }
Ejemplo n.º 20
0
  public Airport(
      /*int duration,*/ double newLandingProbability,
      double newTakeoffProbability,
      int simulationDelay) {
    super("Airport Simulator");

    // -- AIRPORT SIMULATOR STUFF --

    // this.duration = duration;
    this.currentUpdate = 0;
    this.newLandingProbability = newLandingProbability;
    this.newTakeoffProbability = newTakeoffProbability;
    this.simulationDelay = simulationDelay;
    this.lastUpdate = System.currentTimeMillis();

    rand = new Random();

    airQueue = new LinkedList<Airplane>();
    groundQueue = new LinkedList<Airplane>();

    runway = new Runway(2);

    // --SLICK STUFF--

    System.setProperty(
        "org.lwjgl.librarypath",
        System.getProperty("user.dir") + "/lib/native/" + LWJGLUtil.getPlatformName());
    System.setProperty(
        "net.java.games.input.librarypath", System.getProperty("org.lwjgl.librarypath"));

    try {
      app = new AppGameContainer(this);
      app.setDisplayMode(750, 370, false);
      app.setVSync(true);
      app.setTargetFrameRate(60);
      app.start();
    } catch (SlickException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 21
0
 /**
  * Set the display configuration to the specified gamma, brightness and contrast. The
  * configuration changes will be reset when destroy() is called.
  *
  * @param gamma The gamma value
  * @param brightness The brightness value between -1.0 and 1.0, inclusive
  * @param contrast The contrast, larger than 0.0.
  */
 public static void setDisplayConfiguration(float gamma, float brightness, float contrast)
     throws LWJGLException {
   synchronized (GlobalLock.lock) {
     if (!isCreated()) {
       throw new LWJGLException("Display not yet created.");
     }
     if (brightness < -1.0f || brightness > 1.0f)
       throw new IllegalArgumentException("Invalid brightness value");
     if (contrast < 0.0f) throw new IllegalArgumentException("Invalid contrast value");
     int rampSize = display_impl.getGammaRampLength();
     if (rampSize == 0) {
       throw new LWJGLException("Display configuration not supported");
     }
     FloatBuffer gammaRamp = BufferUtils.createFloatBuffer(rampSize);
     for (int i = 0; i < rampSize; i++) {
       float intensity = (float) i / (rampSize - 1);
       // apply gamma
       float rampEntry = (float) java.lang.Math.pow(intensity, gamma);
       // apply brightness
       rampEntry += brightness;
       // apply contrast
       rampEntry = (rampEntry - 0.5f) * contrast + 0.5f;
       // Clamp entry to [0, 1]
       if (rampEntry > 1.0f) rampEntry = 1.0f;
       else if (rampEntry < 0.0f) rampEntry = 0.0f;
       gammaRamp.put(i, rampEntry);
     }
     display_impl.setGammaRamp(gammaRamp);
     LWJGLUtil.log(
         "Gamma set, gamma = "
             + gamma
             + ", brightness = "
             + brightness
             + ", contrast = "
             + contrast);
   }
 }
Ejemplo n.º 22
0
 public String getAdapter() {
   try {
     String maxObjNo =
         WindowsRegistry.queryRegistrationKey(
             WindowsRegistry.HKEY_LOCAL_MACHINE, "HARDWARE\\DeviceMap\\Video", "MaxObjectNumber");
     int maxObjectNumber = maxObjNo.charAt(0);
     String vga_driver_value = "";
     for (int i = 0; i < maxObjectNumber; i++) {
       String adapter_string =
           WindowsRegistry.queryRegistrationKey(
               WindowsRegistry.HKEY_LOCAL_MACHINE,
               "HARDWARE\\DeviceMap\\Video",
               "\\Device\\Video" + i);
       String root_key = "\\registry\\machine\\";
       if (adapter_string.toLowerCase().startsWith(root_key)) {
         String driver_value =
             WindowsRegistry.queryRegistrationKey(
                 WindowsRegistry.HKEY_LOCAL_MACHINE,
                 adapter_string.substring(root_key.length()),
                 "InstalledDisplayDrivers");
         if (driver_value.toUpperCase().startsWith("VGA")) {
           vga_driver_value = driver_value;
         } else if (!driver_value.toUpperCase().startsWith("RDP")
             && !driver_value.toUpperCase().startsWith("NMNDD")) {
           return driver_value;
         }
       }
     }
     if (!vga_driver_value.equals("")) {
       return vga_driver_value;
     }
   } catch (LWJGLException e) {
     LWJGLUtil.log("Exception occurred while querying registry: " + e);
   }
   return null;
 }
Ejemplo n.º 23
0
  private long doHandleMessage(long hwnd, int msg, long wParam, long lParam, long millis) {
    /*switch ( msg ) {
    	case 0x0:
    	case 0x0020:
    	case 0x0084:
    	case WM_MOUSEMOVE:
    		break;
    	default:
    		WindowsEventDebug.printMessage(msg, wParam, lParam);
    }*/

    if (parent != null && !isFocused) {
      switch (msg) {
        case WM_LBUTTONDOWN:
        case WM_RBUTTONDOWN:
        case WM_MBUTTONDOWN:
        case WM_XBUTTONDOWN:
          sendMessage(parent_hwnd, msg, wParam, lParam);
      }
    }

    switch (msg) {
        // disable screen saver and monitor power down messages which wreak havoc
      case WM_ACTIVATE:
        /*switch ((int)wParam) {
        	case WA_ACTIVE:
        	case WA_CLICKACTIVE:
        		appActivate(true);
        		break;
        	case WA_INACTIVE:
        		appActivate(false);
        		break;
        }*/
        return 0L;
      case WM_SIZE:
        switch ((int) wParam) {
          case SIZE_RESTORED:
          case SIZE_MAXIMIZED:
            maximized = ((int) wParam) == SIZE_MAXIMIZED;
            resized = true;
            updateWidthAndHeight();
            setMinimized(false);
            break;
          case SIZE_MINIMIZED:
            setMinimized(true);
            break;
        }
        break;
      case WM_SIZING:
        resized = true;
        updateWidthAndHeight();
        break;
      case WM_SETCURSOR:
        if ((lParam & 0xFFFF) == HTCLIENT) {
          // if the cursor is inside the client area, reset it
          // to the current LWJGL-cursor
          updateCursor();
          return -1; // TRUE
        } else {
          // let Windows handle cursors outside the client area for resizing, etc.
          return defWindowProc(hwnd, msg, wParam, lParam);
        }
      case WM_KILLFOCUS:
        appActivate(false);
        return 0L;
      case WM_SETFOCUS:
        appActivate(true);
        return 0L;
      case WM_MOUSEACTIVATE:
        if (parent != null) {
          if (!isFocused) grabFocus();
          return 3L; // MA_NOACTIVATE
        }
        break;
      case WM_MOUSEMOVE:
        int xPos = (int) (short) (lParam & 0xFFFF);
        int yPos = transformY(getHwnd(), (int) (short) ((lParam >> 16) & 0xFFFF));
        handleMouseMoved(xPos, yPos, millis);
        checkCursorState();
        mouseInside = true;
        if (!trackingMouse) {
          trackingMouse = nTrackMouseEvent(hwnd);
        }
        return 0L;
      case WM_MOUSEWHEEL:
        int dwheel = (int) (short) ((wParam >> 16) & 0xFFFF);
        handleMouseScrolled(dwheel, millis);
        return 0L;
      case WM_LBUTTONDOWN:
        handleMouseButton(0, 1, millis);
        return 0L;
      case WM_LBUTTONUP:
        handleMouseButton(0, 0, millis);
        return 0L;
      case WM_RBUTTONDOWN:
        handleMouseButton(1, 1, millis);
        return 0L;
      case WM_RBUTTONUP:
        handleMouseButton(1, 0, millis);
        return 0L;
      case WM_MBUTTONDOWN:
        handleMouseButton(2, 1, millis);
        return 0L;
      case WM_MBUTTONUP:
        handleMouseButton(2, 0, millis);
        return 0L;
      case WM_XBUTTONUP:
        if ((wParam >> 16) == XBUTTON1) {
          handleMouseButton(3, 0, millis);
        } else {
          handleMouseButton(4, 0, millis);
        }
        return 1;
      case WM_XBUTTONDOWN:
        if ((wParam & 0xFF) == MK_XBUTTON1) {
          handleMouseButton(3, 1, millis);
        } else {
          handleMouseButton(4, 1, millis);
        }
        return 1;
      case WM_SYSCHAR:
      case WM_CHAR:
        handleChar(wParam, lParam, millis);
        return 0L;
      case WM_SYSKEYUP:
        /* Fall through */
      case WM_KEYUP:
        // SysRq apparently only generates WM_KEYUP, so we'll fake a WM_KEYDOWN
        if (wParam == WindowsKeycodes.VK_SNAPSHOT
            && keyboard != null
            && !keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_SYSRQ)) {
          // Set key state to pressed
          long fake_lparam = lParam & ~(1 << 31);
          // Set key previous state to released
          fake_lparam &= ~(1 << 30);
          handleKeyButton(wParam, fake_lparam, millis);
        }
        /* Fall through */
      case WM_SYSKEYDOWN:
        /* Fall through */
      case WM_KEYDOWN:
        handleKeyButton(wParam, lParam, millis);
        break;
      case WM_QUIT:
        close_requested = true;
        return 0L;
      case WM_SYSCOMMAND:
        switch ((int) (wParam & 0xfff0)) {
          case SC_KEYMENU:
          case SC_MOUSEMENU:
          case SC_SCREENSAVE:
          case SC_MONITORPOWER:
            return 0L;
          case SC_CLOSE:
            close_requested = true;
            return 0L;
          default:
            break;
        }
        break;
      case WM_PAINT:
        is_dirty = true;
        break;
      case WM_MOUSELEAVE:
        mouseInside = false;
        trackingMouse = false;
        break;
      case WM_CANCELMODE:
        nReleaseCapture();
        /* fall through */
      case WM_CAPTURECHANGED:
        if (captureMouse != -1) {
          handleMouseButton(captureMouse, 0, millis);
          captureMouse = -1;
        }
        return 0L;
      case WM_WINDOWPOSCHANGED:
        if (getWindowRect(hwnd, rect_buffer)) {
          rect.copyFromBuffer(rect_buffer);
          x = rect.top;
          y = rect.bottom;
        } else {
          LWJGLUtil.log("WM_WINDOWPOSCHANGED: Unable to get window rect");
        }
        break;
      case WM_GETICON:
        iconsLoaded = true;
        break;
    }

    return defWindowProc(hwnd, msg, wParam, lParam);
  }
Ejemplo n.º 24
0
  private void init() throws LWJGLException {
    // create Window of size 800x600
    Display.setDisplayMode(new DisplayMode(1024, 768));
    Display.setLocation(
        (Display.getDisplayMode().getWidth() - 300) / 2,
        (Display.getDisplayMode().getHeight() - 300) / 2);
    Display.setTitle("Gears");

    try {
      Display.create();
    } catch (LWJGLException e) {
      // This COULD be because of a bug! A delay followed by a new attempt is supposed to fix it.
      e.printStackTrace();
      try {
        Thread.sleep(1000);
      } catch (InterruptedException ignored) {
      }

      Display.create();
    }

    // setup ogl
    FloatBuffer pos = BufferUtils.createFloatBuffer(4).put(new float[] {5.0f, 5.0f, 10.0f, 0.0f});
    FloatBuffer red = BufferUtils.createFloatBuffer(4).put(new float[] {0.8f, 0.1f, 0.0f, 1.0f});
    FloatBuffer green = BufferUtils.createFloatBuffer(4).put(new float[] {0.0f, 0.8f, 0.2f, 1.0f});
    FloatBuffer blue = BufferUtils.createFloatBuffer(4).put(new float[] {0.2f, 0.2f, 1.0f, 1.0f});

    pos.flip();
    red.flip();
    green.flip();
    blue.flip();

    glLight(GL_LIGHT0, GL_POSITION, pos);
    glEnable(GL_CULL_FACE);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_DEPTH_TEST);

    /* make the gears */
    gear1 = glGenLists(1);
    glNewList(gear1, GL_COMPILE);
    glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
    gear(1.0f, 4.0f, 1.0f, 20, 0.7f);
    glEndList();

    gear2 = glGenLists(1);
    glNewList(gear2, GL_COMPILE);
    glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
    gear(0.5f, 2.0f, 2.0f, 10, 0.7f);
    glEndList();

    gear3 = glGenLists(1);
    glNewList(gear3, GL_COMPILE);
    glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
    gear(1.3f, 2.0f, 0.5f, 10, 0.7f);
    glEndList();

    glEnable(GL_NORMALIZE);

    glMatrixMode(GL_PROJECTION);

    System.err.println("LWJGL: " + Sys.getVersion() + " / " + LWJGLUtil.getPlatformName());
    System.err.println("GL_VENDOR: " + glGetString(GL_VENDOR));
    System.err.println("GL_RENDERER: " + glGetString(GL_RENDERER));
    System.err.println("GL_VERSION: " + glGetString(GL_VERSION));
    System.err.println();
    System.err.println(
        "glLoadTransposeMatrixfARB() supported: "
            + GLContext.getCapabilities().GL_ARB_transpose_matrix);
    if (!GLContext.getCapabilities().GL_ARB_transpose_matrix) {
      // --- not using extensions
      glLoadIdentity();
    } else {
      // --- using extensions
      final FloatBuffer identityTranspose =
          BufferUtils.createFloatBuffer(16)
              .put(new float[] {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1});
      identityTranspose.flip();
      glLoadTransposeMatrixARB(identityTranspose);
    }

    float h = (float) 300 / (float) 300;
    glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.0f, 0.0f, -40.0f);
  }