Disappearing Quads

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

Disappearing Quads

Postby arachnospore » Fri Mar 05, 2010 5:59 pm

Hi,

I'm trying to draw 6 identical quads (NOT as a cube) onto my screen just as a test but they appear then disappear straight away. I'm just creating a for loop in onDrawFrame.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public void onDrawFrame(GL10 gl)
  3.  
  4.     {
  5.  
  6.        
  7.  
  8.         gl.glClearColor(_red, _green, _blue, 1.0f);
  9.  
  10.         gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
  11.  
  12.         gl.glLoadIdentity();
  13.  
  14.        
  15.  
  16.         for(int i=0; i<6; i++)
  17.  
  18.         {
  19.  
  20.                 gl.glTranslatef(tX, 0, tZ);
  21.  
  22.                 images.draw(gl);
  23.  
  24.                 tX = tX + 0.5f;
  25.  
  26.                 tZ = tZ - 0.5f;
  27.  
  28.         }
  29.  
  30.        
  31.  
  32.        
  33.  
  34.     }
  35.  
  36.  
Parsed in 0.078 seconds, using GeSHi 1.0.8.4


I understand that when it comes out the for loop it's got nothing to draw on the next frames so I'm really just looking for a solution to keep these quads after it comes out the for loop.

Cheers in Advance,
Arachnospore
Put on some golf shoes man or we'll never leave this place alive!
arachnospore
Junior Developer
Junior Developer
 
Posts: 11
Joined: Wed Nov 04, 2009 8:44 pm

Top

Postby romainflash » Fri Mar 05, 2010 10:02 pm

Hi,

maybe you should add these lines just before your for loop :
tX = 0;
tZ = 0;
romainflash
Freshman
Freshman
 
Posts: 4
Joined: Mon Feb 08, 2010 10:08 am

Re: Disappearing Quads

Postby mb_zi » Fri Mar 05, 2010 11:59 pm

I believe your problem is that you only have one instance of images(aka the square). so every time you go .draw it re draws its position. and due to you translating it each time the square just seams to appear, move, appear again in new position.

try making n times the instances of images. add them to an array and iterate through the array alongside your for loop to get the desired effect. e.g. below is kinda pseudo code on outputting 3 images aka squares in the positions you was kinda after.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4.         private ArrayList<Images> ImagesObjects = new ArrayList<Images>();// global
  5.  
  6.         float tx, tz;
  7.  
  8.  
  9.  
  10.         constructor()
  11.  
  12.          {
  13.  
  14.                 Images images = new Images();
  15.  
  16.                  Images images2 = new Images();
  17.  
  18.                 Images images3 = new Images();
  19.  
  20.  
  21.  
  22.                 ImagesObjects.add(images);
  23.  
  24.                  ImagesObjects.add(images2);
  25.  
  26.                   ImagesObjects.add(images3);
  27.  
  28.                  tx = 0;
  29.  
  30.                  tz = 0;
  31.  
  32.           }
  33.  
  34.  
  35.  
  36.         public void onDrawFrame(GL10 gl)
  37.  
  38.         {
  39.  
  40.                 //Clear Screen And Depth Buffer
  41.  
  42.                 gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);       
  43.  
  44.                 gl.glLoadIdentity();           
  45.  
  46.                 gl.glShadeModel(GL10.GL_SMOOTH);               
  47.  
  48.  
  49.  
  50.                         try
  51.  
  52.                         {
  53.  
  54.                                 for(int i = 0; i < ImagesObjects.size();i++)
  55.  
  56.                                 {
  57.  
  58.                        gl.glTranslatef(tX, 0, tZ);
  59.  
  60.                                         ImageseObjects.get(i).draw(gl);
  61.  
  62.                         tX = tX + 0.5f;
  63.  
  64.                         tZ = tZ - 0.5f;
  65.  
  66.                                 }
  67.  
  68.                         }
  69.  
  70.                         catch(Exception e)
  71.  
  72.                         {
  73.  
  74.                                 System.err.println("End of list or no objects in list");
  75.  
  76.                         }
  77.  
  78.                 gl.glPopMatrix();
  79.  
  80.         }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


sorry if its a messy explanation ive been coding all day and have a massive headache!
mb_zi
Junior Developer
Junior Developer
 
Posts: 17
Joined: Sat Feb 27, 2010 2:16 am

Postby arachnospore » Sun Mar 07, 2010 5:39 pm

Cheers Zi, It's so obvious now you've explained it. I had been coding for about 13 hours solid and my brain refused to do anything more it'd appear.

Thanks again,
Arachnospore
Put on some golf shoes man or we'll never leave this place alive!
arachnospore
Junior Developer
Junior Developer
 
Posts: 11
Joined: Wed Nov 04, 2009 8:44 pm

Postby mb_zi » Mon Mar 08, 2010 3:22 pm

No problem :)
mb_zi
Junior Developer
Junior Developer
 
Posts: 17
Joined: Sat Feb 27, 2010 2:16 am

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 6 guests