Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am doing the following to render multiple balls move around the screen but only 1 ball is seen to appear and function. I don't know why the rest (count-1) balls are not being drawn

public void onDrawFrame(GL10 gl) {
        // TODO Auto-generated method stub
         gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);   
         for(int i=0;i<mParticleSystem.getParticleCount();i++){
                  gl.glTranslatef(mParticleSystem.getPosX(i), mParticleSystem.getPosY(i), -3.0f);
                  gl.glScalef(0.3f, 0.3f, 0.3f);
                  gl.glColor4f(r.nextFloat(), r.nextFloat(), r.nextFloat(), 1);



Here is my void draw(GL10 gl) method

public void draw(GL10 gl){

//  gl.glTranslatef(0.2f, 0.2f, -3.0f); 
//  gl.glScalef(size, size, 1.0f);

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertBuff);
gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, points/2);


I couldnt take the snapshot on my Samsung Phone but here is the emulator screenshot. In reality, the ball moves around with change in orientation and acceleration and keeps changing color randomly (due to r.nextFLoat()) . However, the other 35 balls arent even being rendered as you can see. How can I fix this?

enter image description here

share|improve this question
Aren't you rendering the same ball multiple times? Try to render only one ball (try more of them, but only one ball at a time). If only one is rendered, which one? First? Last? Random? – zacharmarz Apr 6 '12 at 8:54
The mParticleSystem class contains an array of balls. I Iterate over each ball and set their position. Yea, so only first ball is rendered. – ladiesMan217 Apr 6 '12 at 9:39
The code you posted does not seem to contain an error, so it is most likely an error in the code you didn't post. Are you sure your getPos(i) actually returns significantly different results for each i? if you replace them by ad-hoc random values, do you still only see one ball? If you step through the debugger, do the expected values show up? If you unroll the loop for the first couple of indices, does it still break? What if you start i at a different index? Is your code sufficiently randomized, i.e. could it be the other balls show up outside the screen every time? – Paul-Jan Apr 7 '12 at 11:21
Have you tried to execute "loadIdentity" inside the "for" loop? I think you should clear the transformations before render every object. – Gloomcoder Oct 18 '12 at 17:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.