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) {}
Where is your swap buffers call? You are double buffering, yes?