我正在编写我的第一个opengl程序,并希望通过单击鼠标来改变我的形状颜色,但它不起作用。 我的代码....我的错是什么?
float red = 1.0f, green = 1.0f, blue = 1.0f;
public void init(GLAutoDrawable drawable)
{
GL2 gl=drawable.getGL().getGL2();
gl.glClearColor(0.0f,0.0f,0.0f,0.0f);
}
public void display(GLAutoDrawable drawable)
{
GL2 gl=drawable.getGL().getGL2();
gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
gl.glColor3f (red, green, blue);
gl.glBegin(GL2.GL_LINES);
gl.glVertex3f(0.5f,0.5f,0.1f);
gl.glVertex3f(-0.5f,-0.5f,0.0f);
gl.glEnd();
gl.glFlush();
gl.glRectf(0.0f,0.0f,0.5f,-0.5f);
gl.glRectf(0.0f,0.0f,-0.5f,0.5f);
gl.glFlush();
}
public void reshape(GLAutoDrawable drawable, int x,int y,int width,int height){}
public void dispose(GLAutoDrawable drawable){}
public void mouseClicked(MouseEvent e) {
red = 1.0f; green = 0.0f; blue = 1.0f;
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
答案 0 :(得分:1)
您的交换缓冲区调用在哪里?你是双缓冲,是吗?