我在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;
}
}
该应用程序适用于除我之外的所有人。老师无法帮助我。
我的电脑:
10.8.2(12C60)
GL_VERSION:2.1 ATI-1.0.29
有没有人有任何想法,可能有什么不对?
答案 0 :(得分:0)
您似乎无法在任何时候清除帧缓冲区(通过glClear()
)。在这种情况下,GL实现完全允许为您提供垃圾。
答案 1 :(得分:0)
在开始渲染之前调用GL11.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
。