I shouldn't be getting a black box...or should I?

I was just playing around with getting LWJGL working today and ran into something strange, or at least I think it should be strange.

Running a demo class, all I get is a black rectangle on the screen that is very buggy in interacting with objects behind it. The code I use (below) isn’t much, but it seems to imply that there would be a window with a title present, which is not what I’m getting. Keep in mind that this could be a blatant error in my code or something having to do with how I set up LWJGL.


import org.lwjgl.LWJGLException;

import org.lwjgl.Sys;

import org.lwjgl.opengl.Display;

import org.lwjgl.opengl.DisplayMode;

import org.lwjgl.opengl.GL11;



/**

 * @author eyuzwa

 * A big "thanks" also goes out to Kevin Glass over at

 * http://www.cokeandcode.com. He also has a lot of

 * excellent LWJGL resources!

 *

 */

public class LwjglTest {

   public LwjglTest(){	
      try {
         // find out what the current bits per pixel of the desktop is
         int currentBpp = Display.getDisplayMode().getBitsPerPixel();

         // find a display mode at 800x600
         DisplayMode mode = findDisplayMode(800, 600, currentBpp);


         // if can't find a mode, notify the user the give up
         if (mode == null) {

            Sys.alert("Error", "800x600x"+currentBpp+" display mode unavailable");
            return;

         }



         // configure and create the LWJGL display
         Display.setTitle("Empty Project");
         Display.setDisplayMode(mode);

         //keep things windowed for now
         Display.setFullscreen(false);

         //create the main display
         Display.create();
      } catch (LWJGLException e) {
         e.printStackTrace();
         Sys.alert("Error", "Failed: "+e.getMessage());
      }		
   }

	

   /**
   * Start the game
   */
   public void startGame() {
      // enter the game loop
      gameLoop();

   }

   /**
   * Get the current time in milliseconds based on the LWJGL
   * high res system clock.
   *
   * @return The time in milliseconds based on the LWJGL high res clock
   */
   private long getTime() {
      return (Sys.getTime() * 1000) / Sys.getTimerResolution();
   }

   /**
   * Determine an available display that matches the specified
   * parameters.
   *
   * @param width The desired width of the screen
   * @param height The desired height of the screen
   * @param bpp The desired color depth (bits per pixel) of the screen
   * @return The display mode matching the requirements or null
   * if none could be found
   * @throws LWJGLException
   * library.
   */
   private DisplayMode findDisplayMode(int width, int height, int bpp) throws LWJGLException {
      DisplayMode[] modes = Display.getAvailableDisplayModes();
      DisplayMode mode = null;

      for (int i=0;i<modes.length;i++) {
         if ((modes[i].getBitsPerPixel() == bpp) || (mode == null)) {
            if ((modes[i].getWidth() == width) && (modes[i].getHeight() == height)) {
               mode = modes[i];

	    }

         }

      }
      return mode;
   }

	

   /**
   * The main game loop which is cycled to update / render
   */
   public void gameLoop() {
      boolean gameRunning = true;

      while (gameRunning) {

         GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

         Display.update();

         // if the user has requested that the window be closed, either
         // pressing ALT-F4 on windows, or clicking the close button
         // on the window - then we want to stop the game
         if (Display.isCloseRequested()) {
            gameRunning = false;
            System.exit(0);
         }
     }
   }	



   /**

   * @param args
   */

   public static void main(String[] args) {

      // TODO Auto-generated method stub

      LwjglTest g = new LwjglTest();

      g.startGame();
   }

}


I didn’t try the code, but one thing caught my eye:

// find out what the current bits per pixel of the desktop is
int currentBpp = Display.getDisplayMode().getBitsPerPixel();

You probably want to have Display.getDesktopDisplayMode() in there… :slight_smile: It might not solve the problem though, but can’t hurt either. :wink:

Hmm, I may have found a problem. Going from the tutorial in the jogl section I ran:

System.loadLibrary(“lwjgl”);

And I get:

Exception in thread “main” java.lang.UnsatisfiedLinkError: /home/delirious/Documents/Java/jre/lib/i386/client/liblwjgl.so: libmawt.so: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1778)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1703)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1030)
at LwjglTest.(LwjglTest.java:17)
at LwjglTest.main(LwjglTest.java:118)

Is this libmawt.so causing the problem?

Btw, I’m using Ubuntu and Java 1.6