   Bouncing square
  hi , i am trying to make a bouncing square in opengl.I want to know the logicof it.If the square reaches the extreme left or right it should bounce back inside its range... how to calculate that...   
  If you have a set window size doif( square_y > window_length ) {//go other way}if( square_x > window_length ) {//go other way}if( square_x < 0 ) {//go other way}etc., something along them lines I'm pretty sure, been a while since i did something like that before.   ;  I don't know much OpenGL but, I don't believe it's required. Now assuming your just moving according to the velocity instead of the X & Y coordinates then you'd do it like the example below:// If the the player touches the left part of the screenif(player_x < 0){player_x += player_speed_x;}// If the player touches the right part of the screenelse if(player_x + player_width > screen_width){player_x -= player_speed_x;}// If the player touches the top of the screenif(player_y < 0){player_y += player_speed_y;}// If the player touches the bottom of the screenelse if(player_y + player_height > screen_height){player_y -= player_speed_y;}The reason why you have to add the width or height is because the X coordinate is based of the very top left of an image, so you have to check to see if the bottom of it (or right side of it) is touched by adding that on there to get the exact position. Hope that makes sense.   ;  Nooblet, your solution doesn't seem to add the bounce effect. To build on your code, I'd do it something like:// If the player touches the left or right edge of the screenif(player_x < 0 || player_x + player_width > screen_width){// Reverse horizontal speedplayer_speed_x = -player_speed_x;}// If the player touches the top or bottom edge of the screenif(player_y < 0 || player_y + player_height > screen_height){// Reverse vertical speedplayer_speed_y = -player_speed_y;}