Opengl 显示屏上闪烁的黑白条纹

Opengl 显示屏上闪烁的黑白条纹,opengl,lwjgl,Opengl,Lwjgl,我已经在Eclipse中导入了lwjgl。老师也给了我们一个BaseWindow应用程序来导入Eclipse。应用程序应显示1024x768黑色窗口。但不是黑色的窗口,而是黑白条纹在显示屏上闪烁。屏幕截图: 我无法显示条纹的图片,因为它们在屏幕截图上不可见。但还有另一个明显的错误 这是BaseWindow.java文件的源: import org.lwjgl.*; import org.lwjgl.opengl.*; import org.lwjgl.input.*; import java.n

我已经在Eclipse中导入了lwjgl。老师也给了我们一个BaseWindow应用程序来导入Eclipse。应用程序应显示1024x768黑色窗口。但不是黑色的窗口,而是黑白条纹在显示屏上闪烁。屏幕截图:
我无法显示条纹的图片,因为它们在屏幕截图上不可见。但还有另一个明显的错误

这是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;
  }
}
import org.lwjgl.*;
导入org.lwjgl.opengl.*;
导入组织lwjgl.input.*;
导入java.nio.*;
公共类基本窗口
{
受保护的静态布尔值isRunning=false;
公共静态void main(字符串[]args)
{
//支持什么版本的OpenGL?
//开始我们的节目
(新建BaseWindow()).execute();
}
/**
*初始化显示并进入主循环
*/
受保护的void execute()
{
尝试
{
initDisplay();
}捕获(LWJGLEXE)
{
System.err.println(“无法打开显示”);
系统出口(0);
}
BaseWindow.isRunning=true;
mainLoop();
Display.destroy();
}
/**
*主循环:呈现和处理输入事件
*/
受保护的void mainLoop()
{
//设置摄像机和灯光
setupView();
while(BaseWindow.isRunning)
{
//重置视图
重置视图();
//让我们来画画
renderFrame();
//处理输入事件
processInput();
//更新窗口内容并处理输入消息
Display.update();
}
}
/**
*将场景投影到屏幕、灯光等上的初始设置。
*/
受保护的void setupView()
{
}
/**
*重置当前帧的视图
*/
受保护的void resetView()
{
}
/**
*渲染当前帧
*/
受保护的void renderFrame()
{
}
/**
*处理键盘和鼠标输入并生成操作
*/
受保护的void processInput()
{
if(Display.isCloseRequested()| | Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
{
BaseWindow.isRunning=false;
}
}
/**
*找到最佳的1024x768显示模式并进行设置
* 
*@jglexception
*/
受保护的void initDisplay()引发LWJGLException
{
DisplayMode bestMode=null;
DisplayMode[]dm=Display.getAvailableDisplayModes();
对于(int-nI=0;nIbestMode.getFrequency())
最佳模式=模式;
}
}
System.out.println(“最佳\n”+bestMode.getFrequency()+“”+bestMode.getWidth()+“”+bestMode.getHeight());
显示。设置显示模式(最佳模式);
//FSAA
创建(新的像素格式(8,8,8,4));
//无FSAA
//Display.create();
Display.setTitle(this.getClass().getName());
System.out.println(“GL_版本:+GL11.glGetString(GL11.GL_版本));
System.out.println(“GL_供应商:+GL11.glGetString(GL11.GL_供应商));
System.out.println(“GL_渲染器:+GL11.glGetString(GL11.GL_渲染器));
}
/**
*用于创建本机缓冲区的UTIL
* 
*@jglexception
*/
公共静态ByteBuffer allocBytes(整数多少)
{
返回ByteBuffer.allocateDirect(多少).order(ByteOrder.nativeOrder());
}
公共静态IntBuffer allocInts(int多少)
{
返回ByteBuffer.allocateDirect(多少).order(ByteOrder.nativeOrder())
.asIntBuffer();
}
公共静态浮动缓冲区allocFloats(整数多少)
{
返回ByteBuffer.allocateDirect(多少).order(ByteOrder.nativeOrder())
.asFloatBuffer();
}
公共静态字节缓冲分配字节(字节[]字节数组)
{
ByteBuffer bb=ByteBuffer.allocateDirect(bytearray.length*1).order(
ByteOrder.nativeOrder());
b.put(bytearray.flip();
返回bb;
}
公共静态IntBuffer分配(int[]intarray)
{
IntBuffer ib=ByteBuffer.allocateDirect(intarray.length*4).order(
ByteOrder.nativeOrder()).asIntBuffer();
ib.put(intarray.flip();
返回ib;
}
公共静态FloatBuffer allocFloats(float[]floatarray)
{
FloatBuffer fb=ByteBuffer.allocateDirect(floatarray.length*4).order(
ByteOrder.nativeOrder()).asFloatBuffer();
put(floatarray.flip();
返回fb;
}
}
除了我之外,这个申请对每个人都很有效。老师没能帮助我

我的电脑:

  • MacBookPro(2011年末)
  • AMD Radeon高清6750M 512 MB
  • 10.8.2(12C60)

  • GL_版本:2.1 ATI-1.0.29

  • GL_供应商:ATI技术公司
  • GL_渲染器:AMD Radeon HD 6750M OpenGL引擎

有人有什么想法吗?有什么问题吗?

您似乎在任何时候都没有清除帧缓冲区(via)。在这种情况下,完全允许GL实现给您带来垃圾。

调用
GL11.glClear(GL_COLOR\u BUFFER\u BIT | GL_DEPTH\u BUFFER\u BIT)开始渲染之前