opengl画布不更新
我正在编写我的第一个 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) {}
I'm writing my first opengl program and want to by clicking the mouse the color of my shape is changed but it not work.
it my code.... what is my fault?
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) {}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的交换缓冲区调用在哪里?你是双缓冲,是吗?
Where is your swap buffers call? You are double buffering, yes?