LWJGL 2.8.5 を使用して 3D 視覚化アプリケーションを開発しています。プロジェクトのホームページから最初のチュートリアルを読んだ後、OpenGL の本を読んで分析を深めました。OpenGL での一般的な手順は、init 関数でシーンを描画し、表示の更新をループで呼び出すだけです。
ただし、LWJGL でこれを試してみると、ディスプレイがちらつきます。ちらつきをなくす唯一の方法は、表示更新サイクルでシーンを再描画することです。なぜこうなった?
私の問題をよりよく説明するために、問題を再現する簡単なクラスを作成しました。画面の中央にクワッドを描画するだけで、無限の画面更新ループに入ります。
サイクル内でドローコールのコメントを外すと、ちらつきが消えてすべてが機能することに注意してください。なんで?
オブジェクトを一度だけ描画し、カメラを動かして静的なシーンの別のビューを取得するという私の期待に何か問題がありますか?
ここにコードがあります:
package test;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;
import static org.lwjgl.opengl.GL11.*;
public class DisplayTest
{
public static void initGL()
{
GL11.glViewport(0, 0, 640, 480);
glMatrixMode(GL_PROJECTION);
GLU.gluPerspective(45.0f, 640f/480f,0.1f, 100.0f);
draw();
}
public static void draw()
{
glMatrixMode(GL_MODELVIEW);
GL11.glLoadIdentity(); // Reset The Current Modelview Matrix
GL11.glTranslatef(0, 0, -6.0f);//Place at the center at -6 depth units
//Start drawing a quad
//--------------------------------------------------
GL11.glBegin(GL11.GL_QUADS);
int size=1;
GL11.glColor3f(.3f, .5f, .8f);
GL11.glVertex3f(-size/2f,-size/2f,+size/2f);
GL11.glVertex3f(+size/2f,-size/2f,+size/2f);
GL11.glVertex3f(+size/2f,+size/2f,+size/2f);
GL11.glVertex3f(-size/2f,+size/2f,+size/2f);
glEnd();
}
public static void main(String[] args)
{
try
{
// Sets the width of the display to 640 and the height to 480
Display.setDisplayMode(new DisplayMode(640, 480));
// Sets the title of the display
Display.setTitle("Drawing a quad");
// Creates and shows the display
Display.create();
}
catch (LWJGLException e)
{
e.printStackTrace();
Display.destroy();
System.exit(1);
}
initGL();
// While we aren't pressing the red button on the display
while (!Display.isCloseRequested())
{
//draw();
// Update the contents of the display and check for input
Display.update();
// Wait until we reach 60 frames-per-second
Display.sync(60);
}
// Destroy the display and render it invisible
Display.destroy();
System.exit(0);
}
}