bouncing a quad back and forth

OK I have a simple quad drawn on the screen. I use the gl.translatef (x, 0, 0)
and
x = x + .05f
to move it to the right

My question is this. If I wanted to make it change direction after a bit in Java2d I would just say if
(x > Screenwidth)
x = -x;

But in openGL if I try that then the quad goes to its original starting position instead of moving in the -x direction. How can I fix it so when it moves a certain distance to the right it then changes its direction of movement?

Almost - swap the direction of the increment instead of the x value:

float dx = 0.05f ;

x = x + dx ;

if(x > Screenwidth)
  dx = -dx ;

The process you mention wouldn’t work in Java2D either - you’re using x as the absolute position of the quad, not the difference in position.

right thanx