1

我在 Eclipse 中导入了 lwjgl。老师给了我们一个BaseWindow应用程序,也可以在Eclipse中导入。应用程序应显示 1024x768 黑色窗口。但不是黑色窗口,而是黑色和白色条纹在显示屏上闪烁。屏幕截图: http: //i.stack.imgur.com/JHsMC.png
我无法显示条纹图片,因为它们在屏幕截图中不可见。但是还有另一个可见的错误。

这是 BaseWindow.java 文件的来源:

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;
  }
}

该应用程序适用于除我之外的所有人。老师帮不了我。

我的电脑:

  • MacBook Pro(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 引擎

有没有人有任何想法,可能有什么问题?

4

2 回答 2

0

您似乎没有glClear()在任何时候清除帧缓冲区(通过)。在这种情况下,GL 实现给你垃圾是完全允许的。

于 2012-10-24T14:27:00.923 回答
0

GL11.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);在开始渲染之前调用。

于 2012-10-24T14:35:57.027 回答