1

I have imported lwjgl in Eclipse. The teacher gave us a BaseWindow application to import in Eclipse, too. The application should display a 1024x768 black window. But instead of black window I get black and white stripes flickering on the display. Screenshot: https://i.stack.imgur.com/JHsMC.png
I can't show a picture of stripes, because they were not visible on the screenshot. But there is another error visible.

This is the source of BaseWindow.java file:

import org.lwjgl.*;
import org.lwjgl.opengl.*;
import org.lwjgl.input.*;
import java.nio.*;

public class BaseWindow
{

  protected static boolean isRunning = false;

  public static void main(String[] args)
  {
    // What version of OpenGL is supported?

    // Start our program
    (new BaseWindow()).execute();
  }

  /**
   * Initializes display and enters main loop
   */
  protected void execute()
  {
    try
    {
      initDisplay();
    } catch (LWJGLException e)
    {
      System.err.println("Can't open display.");
      System.exit(0);
    }

    BaseWindow.isRunning = true;
    mainLoop();
    Display.destroy();
  }

  /**
   * Main loop: renders and processes input events
   */
  protected void mainLoop()
  {
    // setup camera and lights
    setupView();

    while (BaseWindow.isRunning)
    {
      // reset view
      resetView();

      // let subsystem paint
      renderFrame();

      // process input events
      processInput();

      // update window contents and process input messages
      Display.update();
    }
  }

  /**
   * Initial setup of projection of the scene onto screen, lights, etc.
   */
  protected void setupView()
  {

  }

  /**
   * Resets the view of current frame
   */
  protected void resetView()
  {

  }

  /**
   * Renders current frame
   */
  protected void renderFrame()
  {
  }

  /**
   * Processes Keyboard and Mouse input and spawns actions
   */
  protected void processInput()
  {
    if (Display.isCloseRequested() || Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
    {
      BaseWindow.isRunning = false;
    }
  }

  /**
   * Finds best 1024x768 display mode and sets it
   * 
   * @throws LWJGLException
   */
  protected void initDisplay() throws LWJGLException
  {
    DisplayMode bestMode = null;
    DisplayMode[] dm = Display.getAvailableDisplayModes();
    for (int nI = 0; nI < dm.length; nI++)
    {
      DisplayMode mode = dm[nI];
      System.out.println(mode.getFrequency() + " " + mode.getWidth() + " " + mode.getHeight());
      if (mode.getWidth() == 1024 && mode.getHeight() == 768
          && mode.getFrequency() <= 85)
      {
        if (bestMode == null
            || (mode.getBitsPerPixel() >= bestMode.getBitsPerPixel() && mode
                .getFrequency() > bestMode.getFrequency()))
          bestMode = mode;
      }
    }
    System.out.println("Best\n" + bestMode.getFrequency() + " " + bestMode.getWidth() + " " + bestMode.getHeight());
    Display.setDisplayMode(bestMode);
//    FSAA
    Display.create(new PixelFormat(8, 8, 8, 4));
//    No FSAA
//    Display.create();
    Display.setTitle(this.getClass().getName());

    System.out.println("GL_VERSION: "+GL11.glGetString(GL11.GL_VERSION));
    System.out.println("GL_VENDOR: "+GL11.glGetString(GL11.GL_VENDOR));
    System.out.println("GL_RENDERER: "+GL11.glGetString(GL11.GL_RENDERER));
  }

  /**
   * Utils for creating native buffers
   * 
   * @throws LWJGLException
   */
  public static ByteBuffer allocBytes(int howmany)
  {
    return ByteBuffer.allocateDirect(howmany).order(ByteOrder.nativeOrder());
  }

  public static IntBuffer allocInts(int howmany)
  {
    return ByteBuffer.allocateDirect(howmany).order(ByteOrder.nativeOrder())
    .asIntBuffer();
  }

  public static FloatBuffer allocFloats(int howmany)
  {
    return ByteBuffer.allocateDirect(howmany).order(ByteOrder.nativeOrder())
    .asFloatBuffer();
  }

  public static ByteBuffer allocBytes(byte[] bytearray)
  {
    ByteBuffer bb = ByteBuffer.allocateDirect(bytearray.length * 1).order(
        ByteOrder.nativeOrder());
    bb.put(bytearray).flip();
    return bb;
  }

  public static IntBuffer allocInts(int[] intarray)
  {
    IntBuffer ib = ByteBuffer.allocateDirect(intarray.length * 4).order(
        ByteOrder.nativeOrder()).asIntBuffer();
    ib.put(intarray).flip();
    return ib;
  }

  public static FloatBuffer allocFloats(float[] floatarray)
  {
    FloatBuffer fb = ByteBuffer.allocateDirect(floatarray.length * 4).order(
        ByteOrder.nativeOrder()).asFloatBuffer();
    fb.put(floatarray).flip();
    return fb;
  }
}

The application worked fine for everybody but me. The teacher wasn't able to help me.

My computer:

  • MacBook Pro (late 2011)
  • AMD Radeon HD 6750M 512 MB
  • 10.8.2 (12C60)

  • GL_VERSION: 2.1 ATI-1.0.29

  • GL_VENDOR: ATI Technologies Inc.
  • GL_RENDERER: AMD Radeon HD 6750M OpenGL Engine

Does anybody have any ideas, what could be wrong?

genpfault
  • 51,148
  • 11
  • 85
  • 139
jurebajt
  • 23
  • 2

2 Answers2

0

You don't seem to be clearing the framebuffer (via glClear()) at any point. It's perfectly allowable for the GL implementation to give you garbage in that case.

genpfault
  • 51,148
  • 11
  • 85
  • 139
0

Call GL11.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); before starting to render.

Georgi Khomeriki
  • 674
  • 6
  • 17