Bouncing Ball/Point animation using openGL

Hi, Im new to opengl and only know a little bit of c++, so I was wondering how would I go about creating a simple animation of a ball/point etc. bouncing up and down in a window. I already have the window created, so its just the actual movement of the point im stuck on.
Thanks in advance!

This is the code I have so far, not sure why the point isn’t moving?

// includes
#include “stdafx.h”
#include <stdio.h>
#include <math.h>

int xpos = 0;
int xvel = 1;

// renderScene() - render the scene

void renderScene()
// clear the back buffer

// render code here...


glColor3f( 1.0f, 1.0f, 1.0f ); //white
glVertex2f(0.0, 0.0);
xpos = xpos + xvel;

    if(xpos &gt;= 500)
	xvel = -xvel;
if( xpos &lt;= -500)
	xvel = -xvel;


// swap the buffers of the current window


Please use [noparse]

[/noparse] around source code to preserve formatting, thanks!

You are drawing the point at a fixed position (0, 0) instead of at the location you compute.

Oh okay, will do!

I’ve now got movement, thanks! but it is really quick as if there’s a few points, so is there a way to reduce the speed?

Sorry, these are probably really basic things!

If you want to do it ‘properly’, your animation should be made independent of the rendering speed. Right now every time you render an image the object is moved by a fixed amount, instead move the object by a distance that depends on how much time has expired since the last frame.
The other option is to just reduce the amount you move the object each frame, i.e. make xvel smaller (make it a floating point value, so it can have values between 0 and 1).

I gave the other option ago because I’m not sure how to do the first part, but as soon as I change to a floating point number, the point becomes stationary.

Did you change the type of xpos as well? Otherwise you add a float (that probably is < 1) to an integer and store as integer, so that looses all the decimal digits.

That was exactly the problem. Thank you! Slowed down to the perfect speed now. I just need to implement motion blur to the animation now and that’ll be my first animation using opengl and c!
I’ve read up on the accumulation buffer, but is it a hard job to get motion blur? I have’t seen any examples that I understand fully.

Hmm, never used the accumulation buffer and I don’t think it gets much use and love these days. There should be examples on the net that show how it can be used for motion blur.
Examples how motion blur can be done without accumulation buffer, see for example NVidia motionblur sample. However, note that it makes use of shaders and other technology that is used in ‘modern’ OpenGL, so you may have to get familiar with those things first. Then again you may want to do that anyway :wink:

Haha no worries! Thank you for your help! :smiley: