display() 似乎只在调整大小时被调用
display() seems to only get called upon resize
基本上,我实现的旋转只会在调整屏幕大小时绘制到屏幕上。为了调试,我在 display() 函数中插入了一个打印,输出角度。在 运行 程序中,这仅显示 display() 的 2 次迭代的输出,然后在随后的屏幕大小时再次显示。
这让我相信 display() 只被调用了两次?
我已经在下面发布了相关的回调,但如果需要任何其他代码,请告诉我。
float angle = 0.0f;
float increment = 0.5f;
@Override
public void init(GLAutoDrawable drawable)
{
GL2 gl = drawable.getGL().getGL2(); // get the OpenGL graphics context
glu = new GLU(); // get GL Utilities
glut = new GLUT();
gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // set background (clear) color
gl.glClearDepth(1.0f); // set clear depth value to farthest
gl.glEnable(GL_DEPTH_TEST); // enables depth testing
gl.glDepthFunc(GL_LEQUAL); // the type of depth test to do
gl.glShadeModel(GL_SMOOTH); // blends colors nicely, and smoothes out lighting
calculateSpecks(noSpecks);
}
@Override
public void dispose(GLAutoDrawable drawable)
{
}
@Override
public void display(GLAutoDrawable drawable)
{
GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth buffers
gl.glColor3f(1.0f, 0.0f, 0.0f);
gl.glLoadIdentity();
glu.gluLookAt(1.0, 0.0, 3.0, 0.0, 0.0, -0.5, 0.0, 1.0, 0.0);
gl.glRotatef(angle, 1.0f, 0.0f, 0.0f);
angle+=increment;
//setLighting(gl);
glut.glutWireSphere(1, 32, 32);
gl.glColor3f(0.0f, 0.0f, 0.0f);
for(int i = 0; i < noSpecks; i++)
{
gl.glBegin(GL.GL_POINTS);
gl.glVertex3i(specks[i][0], specks[i][1], specks[i][2]);
gl.glEnd();
}
}
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width,
int height)
{
GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context
if (height == 0) height = 1; // prevent divide by zero
float aspect = (float)width / height;
// Set the view port (display area) to cover the entire window
gl.glViewport(0, 0, width, height);
// Setup perspective projection, with aspect ratio matches viewport
gl.glMatrixMode(GL_PROJECTION); // choose projection matrix
gl.glLoadIdentity(); // reset projection matrix
glu.gluPerspective(45.0, aspect, 0.1, 100.0); // fovy, aspect, zNear, zFar
// Enable the model-view transform
gl.glMatrixMode(GL_MODELVIEW);
gl.glLoadIdentity(); // reset
}
刚刚意识到,我忘记了必须使用动画师来驱动 JOGL 中的 display() 函数。问题已解决
基本上,我实现的旋转只会在调整屏幕大小时绘制到屏幕上。为了调试,我在 display() 函数中插入了一个打印,输出角度。在 运行 程序中,这仅显示 display() 的 2 次迭代的输出,然后在随后的屏幕大小时再次显示。 这让我相信 display() 只被调用了两次? 我已经在下面发布了相关的回调,但如果需要任何其他代码,请告诉我。
float angle = 0.0f;
float increment = 0.5f;
@Override
public void init(GLAutoDrawable drawable)
{
GL2 gl = drawable.getGL().getGL2(); // get the OpenGL graphics context
glu = new GLU(); // get GL Utilities
glut = new GLUT();
gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // set background (clear) color
gl.glClearDepth(1.0f); // set clear depth value to farthest
gl.glEnable(GL_DEPTH_TEST); // enables depth testing
gl.glDepthFunc(GL_LEQUAL); // the type of depth test to do
gl.glShadeModel(GL_SMOOTH); // blends colors nicely, and smoothes out lighting
calculateSpecks(noSpecks);
}
@Override
public void dispose(GLAutoDrawable drawable)
{
}
@Override
public void display(GLAutoDrawable drawable)
{
GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth buffers
gl.glColor3f(1.0f, 0.0f, 0.0f);
gl.glLoadIdentity();
glu.gluLookAt(1.0, 0.0, 3.0, 0.0, 0.0, -0.5, 0.0, 1.0, 0.0);
gl.glRotatef(angle, 1.0f, 0.0f, 0.0f);
angle+=increment;
//setLighting(gl);
glut.glutWireSphere(1, 32, 32);
gl.glColor3f(0.0f, 0.0f, 0.0f);
for(int i = 0; i < noSpecks; i++)
{
gl.glBegin(GL.GL_POINTS);
gl.glVertex3i(specks[i][0], specks[i][1], specks[i][2]);
gl.glEnd();
}
}
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width,
int height)
{
GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context
if (height == 0) height = 1; // prevent divide by zero
float aspect = (float)width / height;
// Set the view port (display area) to cover the entire window
gl.glViewport(0, 0, width, height);
// Setup perspective projection, with aspect ratio matches viewport
gl.glMatrixMode(GL_PROJECTION); // choose projection matrix
gl.glLoadIdentity(); // reset projection matrix
glu.gluPerspective(45.0, aspect, 0.1, 100.0); // fovy, aspect, zNear, zFar
// Enable the model-view transform
gl.glMatrixMode(GL_MODELVIEW);
gl.glLoadIdentity(); // reset
}
刚刚意识到,我忘记了必须使用动画师来驱动 JOGL 中的 display() 函数。问题已解决