Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.glDisable(GL10.GL_DITHER);
         gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);   
         gl.glMatrixMode(GL10.GL_MODELVIEW);
        gl.glClientActiveTexture(DRAWING_CACHE_QUALITY_HIGH);
         gl.glLoadIdentity();
         for(int i=0;i<mParticleSystem.getParticleCount();i++){
            gl.glPushMatrix();
                  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);
                  gl.glEnable(GL10.GL_TEXTURE_2D);   
                  mParticleSystem.getBall(i).draw(gl);
            gl.glPopMatrix();

         }


    }

Here is my void draw(GL10 gl) method

public void draw(GL10 gl){

gl.glEnable(GL10.GL_CULL_FACE);
gl.glEnable(GL10.GL_SMOOTH);
gl.glEnable(GL10.GL_DEPTH_TEST);
//  gl.glTranslatef(0.2f, 0.2f, -3.0f); 
//  gl.glScalef(size, size, 1.0f);

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

}

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
2  
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
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.