opengl画布不更新

发布于 2024-12-10 22:05:43 字数 1070 浏览 0 评论 0原文

我正在编写我的第一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

破晓 2024-12-17 22:05:43

你的交换缓冲区调用在哪里?你是双缓冲,是吗?

Where is your swap buffers call? You are double buffering, yes?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文