GPWiki.org
GPWiki.org
It is currently Fri May 24, 2013 8:12 pm

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: JOGL Speed
PostPosted: Mon Jul 17, 2006 8:21 pm 
Gamer Geek

Joined: Sun Jul 02, 2006 7:24 pm
Posts: 30
Hi everyone -

I'm working on a project in JOGL where I need to render a few thousand quadrics (each is a helicopter flying around in the sky). I am using display lists to render these objects, but it is still very, very slow (especially when I send objects a few times a second to move them). I know that video games can render millions of polygons -- is there something I may be doing wrong (I know this is a vague question) or are there certain techniques I could use to speed this up?

Thanks,
Jeff


Top
 Profile  
 
 Post subject: JOGL Speed
PostPosted: Mon Jul 17, 2006 8:45 pm 
Gamer Geek

Joined: Sun Jul 02, 2006 7:24 pm
Posts: 30
A slight modification to my last post - I am rendering quadrics, not polygons.

Thanks,
Jeff


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 17, 2006 10:24 pm 
Digerati

Joined: Fri Sep 24, 2004 3:15 am
Posts: 1791
Location: No longer near Boston, MA
Are you creating one display list then drawing all of your objects with that, or are you making a display list for every quad?

Sorry that this is C++, but you should do something like -

Code:
   maindisplay=glGenLists(1);
   glNewList(maindisplay,GL_COMPILE);
    glBegin(GL_QUADS);{
         glTexCoord2f(0.0f,1.0f);
         glVertex3f(-1.0f, -1.0f,0.0f);
         glTexCoord2f(0.0f, 0.0f);
         glVertex3f(-1.0f ,1.0f,0.0f);
         glTexCoord2f(1.0f,0.0f);
         glVertex3f(1.0f,1.0f,0.0f);       
         glTexCoord2f(1.0f, 1.0f);
         glVertex3f(1.0f,-1.0f,0.0f);                                     
    }glEnd();                                    
   glEndList();


Then to draw something -

Code:
 glColor4f (r,g,b,a);
 glPushMatrix();
 glTranslatef(x,y,0.0f);   
 glRotatef(angle,0.0f,0.0f,1.0f);
 glScalef(width/2.0f,height/2.0f,0.0f);
 glCallList(maindisplay);   
 glPopMatrix();


Top
 Profile  
 
 Post subject: Re: JOGL Speed
PostPosted: Mon Jul 17, 2006 10:35 pm 
Gamer Geek

Joined: Sun Jul 02, 2006 7:24 pm
Posts: 30
I am using separate display lists for each object because they are added dynamically and I create the display list when the object is added.

Also, my terminology may be a little off - by quadric, I had meant I use glu***, such as gluSphere - I'm not sure how much of a difference that makes.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 17, 2006 10:51 pm 
Digerati

Joined: Fri Sep 24, 2004 3:15 am
Posts: 1791
Location: No longer near Boston, MA
oh, sorry, I read that a bit too fast. Your terminolgy is correct. I don't use glu except for gluBuild2DMipmaps, sorry.

Quote:
(especially when I send objects a few times a second to move them)


I figure this means you aren't using matrices... ?

Quote:
(each is a helicopter flying around in the sky)


I figure a lot of them won't be on the screen in this case, so you'll want to use visibility culling.


Top
 Profile  
 
 Post subject: Re: JOGL Speed
PostPosted: Mon Jul 17, 2006 11:02 pm 
Gamer Geek

Joined: Sun Jul 02, 2006 7:24 pm
Posts: 30
Hi - Thanks again for the reply. In terms of using matrices, I use them for rotating and translating, but not much else. As for visibility culling, I'm not very familiar with it. I figured that if something wasn't visible on the screen, it wouldn't get rendered (figured JOGL used some sort of ray tracing) - is that incorrect?

Also, I'm assuming there is an inherent slow down because I'm using JOGL and not C++ OpenGL.

Thanks!

Jeff


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 17, 2006 11:29 pm 
Digerati

Joined: Fri Sep 24, 2004 3:15 am
Posts: 1791
Location: No longer near Boston, MA
You still send data to the video card if you ask OpenGL to draw something that's offscreen, you'll get a speed increase if you use view-frustum culling.

Here's some code I used - call NewFrustum when you change around your camera, and then you can call point or sphere in frustum to see if you need to draw something.

Code:
void Camera::NewFrustum()
        {                       
        GLfloat   clip[16];
        GLfloat   proj[16];
        GLfloat   modl[16];
        GLfloat   t;

   // Get The Current PROJECTION Matrix From OpenGL
   glGetFloatv( GL_PROJECTION_MATRIX, proj );

   // Get The Current MODELVIEW Matrix From OpenGL
   glGetFloatv( GL_MODELVIEW_MATRIX, modl );

   // Combine The Two Matrices (Multiply Projection By Modelview)
   clip[ 0] = modl[ 0] * proj[ 0] + modl[ 1] * proj[ 4] + modl[ 2] * proj[ 8] + modl[ 3] * proj[12];
   clip[ 1] = modl[ 0] * proj[ 1] + modl[ 1] * proj[ 5] + modl[ 2] * proj[ 9] + modl[ 3] * proj[13];
   clip[ 2] = modl[ 0] * proj[ 2] + modl[ 1] * proj[ 6] + modl[ 2] * proj[10] + modl[ 3] * proj[14];
   clip[ 3] = modl[ 0] * proj[ 3] + modl[ 1] * proj[ 7] + modl[ 2] * proj[11] + modl[ 3] * proj[15];

   clip[ 4] = modl[ 4] * proj[ 0] + modl[ 5] * proj[ 4] + modl[ 6] * proj[ 8] + modl[ 7] * proj[12];
   clip[ 5] = modl[ 4] * proj[ 1] + modl[ 5] * proj[ 5] + modl[ 6] * proj[ 9] + modl[ 7] * proj[13];
   clip[ 6] = modl[ 4] * proj[ 2] + modl[ 5] * proj[ 6] + modl[ 6] * proj[10] + modl[ 7] * proj[14];
   clip[ 7] = modl[ 4] * proj[ 3] + modl[ 5] * proj[ 7] + modl[ 6] * proj[11] + modl[ 7] * proj[15];

   clip[ 8] = modl[ 8] * proj[ 0] + modl[ 9] * proj[ 4] + modl[10] * proj[ 8] + modl[11] * proj[12];
   clip[ 9] = modl[ 8] * proj[ 1] + modl[ 9] * proj[ 5] + modl[10] * proj[ 9] + modl[11] * proj[13];
   clip[10] = modl[ 8] * proj[ 2] + modl[ 9] * proj[ 6] + modl[10] * proj[10] + modl[11] * proj[14];
   clip[11] = modl[ 8] * proj[ 3] + modl[ 9] * proj[ 7] + modl[10] * proj[11] + modl[11] * proj[15];

   clip[12] = modl[12] * proj[ 0] + modl[13] * proj[ 4] + modl[14] * proj[ 8] + modl[15] * proj[12];
   clip[13] = modl[12] * proj[ 1] + modl[13] * proj[ 5] + modl[14] * proj[ 9] + modl[15] * proj[13];
   clip[14] = modl[12] * proj[ 2] + modl[13] * proj[ 6] + modl[14] * proj[10] + modl[15] * proj[14];
   clip[15] = modl[12] * proj[ 3] + modl[13] * proj[ 7] + modl[14] * proj[11] + modl[15] * proj[15];

   // Extract The Numbers For The RIGHT Plane
   m_Frustum[0][0] = clip[ 3] - clip[ 0];
   m_Frustum[0][1] = clip[ 7] - clip[ 4];
   m_Frustum[0][2] = clip[11] - clip[ 8];
   m_Frustum[0][3] = clip[15] - clip[12];

   // Normalize The Result
   t = GLfloat(sqrt( m_Frustum[0][0] * m_Frustum[0][0] + m_Frustum[0][1] * m_Frustum[0][1] + m_Frustum[0][2] * m_Frustum[0][2] ));
   m_Frustum[0][0] /= t;
   m_Frustum[0][1] /= t;
   m_Frustum[0][2] /= t;
   m_Frustum[0][3] /= t;

   // Extract The Numbers For The LEFT Plane
   m_Frustum[1][0] = clip[ 3] + clip[ 0];
   m_Frustum[1][1] = clip[ 7] + clip[ 4];
   m_Frustum[1][2] = clip[11] + clip[ 8];
   m_Frustum[1][3] = clip[15] + clip[12];

   // Normalize The Result
   t = GLfloat(sqrt( m_Frustum[1][0] * m_Frustum[1][0] + m_Frustum[1][1] * m_Frustum[1][1] + m_Frustum[1][2] * m_Frustum[1][2] ));
   m_Frustum[1][0] /= t;
   m_Frustum[1][1] /= t;
   m_Frustum[1][2] /= t;
   m_Frustum[1][3] /= t;

   // Extract The BOTTOM Plane
   m_Frustum[2][0] = clip[ 3] + clip[ 1];
   m_Frustum[2][1] = clip[ 7] + clip[ 5];
   m_Frustum[2][2] = clip[11] + clip[ 9];
   m_Frustum[2][3] = clip[15] + clip[13];

   // Normalize The Result
   t = GLfloat(sqrt( m_Frustum[2][0] * m_Frustum[2][0] + m_Frustum[2][1] * m_Frustum[2][1] + m_Frustum[2][2] * m_Frustum[2][2] ));
   m_Frustum[2][0] /= t;
   m_Frustum[2][1] /= t;
   m_Frustum[2][2] /= t;
   m_Frustum[2][3] /= t;

   // Extract The TOP Plane
   m_Frustum[3][0] = clip[ 3] - clip[ 1];
   m_Frustum[3][1] = clip[ 7] - clip[ 5];
   m_Frustum[3][2] = clip[11] - clip[ 9];
   m_Frustum[3][3] = clip[15] - clip[13];

   // Normalize The Result
   t = GLfloat(sqrt( m_Frustum[3][0] * m_Frustum[3][0] + m_Frustum[3][1] * m_Frustum[3][1] + m_Frustum[3][2] * m_Frustum[3][2] ));
   m_Frustum[3][0] /= t;
   m_Frustum[3][1] /= t;
   m_Frustum[3][2] /= t;
   m_Frustum[3][3] /= t;

   // Extract The FAR Plane
   m_Frustum[4][0] = clip[ 3] - clip[ 2];
   m_Frustum[4][1] = clip[ 7] - clip[ 6];
   m_Frustum[4][2] = clip[11] - clip[10];
   m_Frustum[4][3] = clip[15] - clip[14];

   // Normalize The Result
   t = GLfloat(sqrt( m_Frustum[4][0] * m_Frustum[4][0] + m_Frustum[4][1] * m_Frustum[4][1] + m_Frustum[4][2] * m_Frustum[4][2] ));
   m_Frustum[4][0] /= t;
   m_Frustum[4][1] /= t;
   m_Frustum[4][2] /= t;
   m_Frustum[4][3] /= t;

   // Extract The NEAR Plane
   m_Frustum[5][0] = clip[ 3] + clip[ 2];
   m_Frustum[5][1] = clip[ 7] + clip[ 6];
   m_Frustum[5][2] = clip[11] + clip[10];
   m_Frustum[5][3] = clip[15] + clip[14];

   // Normalize The Result
   t = GLfloat(sqrt( m_Frustum[5][0] * m_Frustum[5][0] + m_Frustum[5][1] * m_Frustum[5][1] + m_Frustum[5][2] * m_Frustum[5][2] ));
   m_Frustum[5][0] /= t;
   m_Frustum[5][1] /= t;
   m_Frustum[5][2] /= t;
   m_Frustum[5][3] /= t;

bool Camera::PtInFrustum(float x, float y, float z)
{
     int i;
   // The Idea Behind This Algorithum Is That If The Point
   // Is Inside All 6 Clipping Planes Then It Is Inside Our
   // Viewing Volume So We Can Return True.
   for(i = 0; i < 6; i++)
   {
      if(m_Frustum[i][0] * x + m_Frustum[i][1] * y + m_Frustum[i][2] * z + m_Frustum[i][3] <= 0)
      {
         return(false);
      }
   }
   return(true);
}
bool Camera::SphereInFrustum(float x, float y, float z,float radius)
{
     int i;
   // The Idea Behind This Algorithm Is That If The Point
   // Is Inside All 6 Clipping Planes Then It Is Inside Our
   // Viewing Volume So We Can Return True.
   for(i = 0; i < 6; i++)
   {
      if(m_Frustum[i][0] * x + m_Frustum[i][1] * y + m_Frustum[i][2] * z + m_Frustum[i][3] <= -radius)
      {
         return(false);
      }
   }
   return(true);
}


Top
 Profile  
 
 Post subject: Re: JOGL Speed
PostPosted: Mon Jul 17, 2006 11:51 pm 
Gamer Geek

Joined: Sun Jul 02, 2006 7:24 pm
Posts: 30
I'll give that a try - thanks!


Top
 Profile  
 
 Post subject: Re: View Frustum
PostPosted: Tue Jul 18, 2006 12:08 am 
Gamer Geek

Joined: Sun Jul 02, 2006 7:24 pm
Posts: 30
Hmm ... this seems like it may not work in my case. The reason being is that I'm drawing helicopters that fly around a world. The helicopters are all approximately the same distance off the earth, so they would all be in the view frustum. Some are just behind the earth, so they'd still fall into the frustum. Are there any other tips you may have?

Thanks -
Jeff


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 1:20 am 
Digerati

Joined: Fri Sep 24, 2004 3:15 am
Posts: 1791
Location: No longer near Boston, MA
Unless there is something extremely different between the spheres, I would use as few display lists as possible then use matrices for scaling. Also you could try to drop the general level of quality of the spheres.

There are ways of adding in solutions for finding if something is being blocked by another object, but I've never implemented anything like that in 3D, so hopefully another person could help you out there or you could search google a bit.


Top
 Profile  
 
 Post subject: Re: JOGL Speed
PostPosted: Tue Jul 18, 2006 1:30 am 
Gamer Geek

Joined: Sun Jul 02, 2006 7:24 pm
Posts: 30
Thanks, I appreciate all of the help. The more I explore, the more I find that I think the problem is the sheer number of function calls to update the display. I'm going to work on cutting that down, and maybe this will help make the display smoother.

Thanks again,
Jeff


Top
 Profile  
 
PostPosted: Tue May 31, 2011 9:40 am 
Hi,
I adjusted example from Sadistic Penguin for using in Java (JOGL). After integration in my project the frustum culling is working greatly. Really big thank for this very usefull example. :thumbs

Dan


Sadistic Penguin wrote:
You still send data to the video card if you ask OpenGL to draw something that's offscreen, you'll get a speed increase if you use view-frustum culling.

Here's some code I used - :thumbs call NewFrustum when you change around your camera, and then you can call point or sphere in frustum to see if you need to draw something.

Code:
void Camera::NewFrustum()
        {                       
        GLfloat   clip[16];
        GLfloat   proj[16];
        GLfloat   modl[16];
        GLfloat   t;

   // Get The Current PROJECTION Matrix From OpenGL
   glGetFloatv( GL_PROJECTION_MATRIX, proj );

   // Get The Current MODELVIEW Matrix From OpenGL
   glGetFloatv( GL_MODELVIEW_MATRIX, modl );

   // Combine The Two Matrices (Multiply Projection By Modelview)
   clip[ 0] = modl[ 0] * proj[ 0] + modl[ 1] * proj[ 4] + modl[ 2] * proj[ 8] + modl[ 3] * proj[12];
   clip[ 1] = modl[ 0] * proj[ 1] + modl[ 1] * proj[ 5] + modl[ 2] * proj[ 9] + modl[ 3] * proj[13];
   clip[ 2] = modl[ 0] * proj[ 2] + modl[ 1] * proj[ 6] + modl[ 2] * proj[10] + modl[ 3] * proj[14];
   clip[ 3] = modl[ 0] * proj[ 3] + modl[ 1] * proj[ 7] + modl[ 2] * proj[11] + modl[ 3] * proj[15];

   clip[ 4] = modl[ 4] * proj[ 0] + modl[ 5] * proj[ 4] + modl[ 6] * proj[ 8] + modl[ 7] * proj[12];
   clip[ 5] = modl[ 4] * proj[ 1] + modl[ 5] * proj[ 5] + modl[ 6] * proj[ 9] + modl[ 7] * proj[13];
   clip[ 6] = modl[ 4] * proj[ 2] + modl[ 5] * proj[ 6] + modl[ 6] * proj[10] + modl[ 7] * proj[14];
   clip[ 7] = modl[ 4] * proj[ 3] + modl[ 5] * proj[ 7] + modl[ 6] * proj[11] + modl[ 7] * proj[15];

   clip[ 8] = modl[ 8] * proj[ 0] + modl[ 9] * proj[ 4] + modl[10] * proj[ 8] + modl[11] * proj[12];
   clip[ 9] = modl[ 8] * proj[ 1] + modl[ 9] * proj[ 5] + modl[10] * proj[ 9] + modl[11] * proj[13];
   clip[10] = modl[ 8] * proj[ 2] + modl[ 9] * proj[ 6] + modl[10] * proj[10] + modl[11] * proj[14];
   clip[11] = modl[ 8] * proj[ 3] + modl[ 9] * proj[ 7] + modl[10] * proj[11] + modl[11] * proj[15];

   clip[12] = modl[12] * proj[ 0] + modl[13] * proj[ 4] + modl[14] * proj[ 8] + modl[15] * proj[12];
   clip[13] = modl[12] * proj[ 1] + modl[13] * proj[ 5] + modl[14] * proj[ 9] + modl[15] * proj[13];
   clip[14] = modl[12] * proj[ 2] + modl[13] * proj[ 6] + modl[14] * proj[10] + modl[15] * proj[14];
   clip[15] = modl[12] * proj[ 3] + modl[13] * proj[ 7] + modl[14] * proj[11] + modl[15] * proj[15];

   // Extract The Numbers For The RIGHT Plane
   m_Frustum[0][0] = clip[ 3] - clip[ 0];
   m_Frustum[0][1] = clip[ 7] - clip[ 4];
   m_Frustum[0][2] = clip[11] - clip[ 8];
   m_Frustum[0][3] = clip[15] - clip[12];

   // Normalize The Result
   t = GLfloat(sqrt( m_Frustum[0][0] * m_Frustum[0][0] + m_Frustum[0][1] * m_Frustum[0][1] + m_Frustum[0][2] * m_Frustum[0][2] ));
   m_Frustum[0][0] /= t;
   m_Frustum[0][1] /= t;
   m_Frustum[0][2] /= t;
   m_Frustum[0][3] /= t;

   // Extract The Numbers For The LEFT Plane
   m_Frustum[1][0] = clip[ 3] + clip[ 0];
   m_Frustum[1][1] = clip[ 7] + clip[ 4];
   m_Frustum[1][2] = clip[11] + clip[ 8];
   m_Frustum[1][3] = clip[15] + clip[12];

   // Normalize The Result
   t = GLfloat(sqrt( m_Frustum[1][0] * m_Frustum[1][0] + m_Frustum[1][1] * m_Frustum[1][1] + m_Frustum[1][2] * m_Frustum[1][2] ));
   m_Frustum[1][0] /= t;
   m_Frustum[1][1] /= t;
   m_Frustum[1][2] /= t;
   m_Frustum[1][3] /= t;

   // Extract The BOTTOM Plane
   m_Frustum[2][0] = clip[ 3] + clip[ 1];
   m_Frustum[2][1] = clip[ 7] + clip[ 5];
   m_Frustum[2][2] = clip[11] + clip[ 9];
   m_Frustum[2][3] = clip[15] + clip[13];

   // Normalize The Result
   t = GLfloat(sqrt( m_Frustum[2][0] * m_Frustum[2][0] + m_Frustum[2][1] * m_Frustum[2][1] + m_Frustum[2][2] * m_Frustum[2][2] ));
   m_Frustum[2][0] /= t;
   m_Frustum[2][1] /= t;
   m_Frustum[2][2] /= t;
   m_Frustum[2][3] /= t;

   // Extract The TOP Plane
   m_Frustum[3][0] = clip[ 3] - clip[ 1];
   m_Frustum[3][1] = clip[ 7] - clip[ 5];
   m_Frustum[3][2] = clip[11] - clip[ 9];
   m_Frustum[3][3] = clip[15] - clip[13];

   // Normalize The Result
   t = GLfloat(sqrt( m_Frustum[3][0] * m_Frustum[3][0] + m_Frustum[3][1] * m_Frustum[3][1] + m_Frustum[3][2] * m_Frustum[3][2] ));
   m_Frustum[3][0] /= t;
   m_Frustum[3][1] /= t;
   m_Frustum[3][2] /= t;
   m_Frustum[3][3] /= t;

   // Extract The FAR Plane
   m_Frustum[4][0] = clip[ 3] - clip[ 2];
   m_Frustum[4][1] = clip[ 7] - clip[ 6];
   m_Frustum[4][2] = clip[11] - clip[10];
   m_Frustum[4][3] = clip[15] - clip[14];

   // Normalize The Result
   t = GLfloat(sqrt( m_Frustum[4][0] * m_Frustum[4][0] + m_Frustum[4][1] * m_Frustum[4][1] + m_Frustum[4][2] * m_Frustum[4][2] ));
   m_Frustum[4][0] /= t;
   m_Frustum[4][1] /= t;
   m_Frustum[4][2] /= t;
   m_Frustum[4][3] /= t;

   // Extract The NEAR Plane
   m_Frustum[5][0] = clip[ 3] + clip[ 2];
   m_Frustum[5][1] = clip[ 7] + clip[ 6];
   m_Frustum[5][2] = clip[11] + clip[10];
   m_Frustum[5][3] = clip[15] + clip[14];

   // Normalize The Result
   t = GLfloat(sqrt( m_Frustum[5][0] * m_Frustum[5][0] + m_Frustum[5][1] * m_Frustum[5][1] + m_Frustum[5][2] * m_Frustum[5][2] ));
   m_Frustum[5][0] /= t;
   m_Frustum[5][1] /= t;
   m_Frustum[5][2] /= t;
   m_Frustum[5][3] /= t;

bool Camera::PtInFrustum(float x, float y, float z)
{
     int i;
   // The Idea Behind This Algorithum Is That If The Point
   // Is Inside All 6 Clipping Planes Then It Is Inside Our
   // Viewing Volume So We Can Return True.
   for(i = 0; i < 6; i++)
   {
      if(m_Frustum[i][0] * x + m_Frustum[i][1] * y + m_Frustum[i][2] * z + m_Frustum[i][3] <= 0)
      {
         return(false);
      }
   }
   return(true);
}
bool Camera::SphereInFrustum(float x, float y, float z,float radius)
{
     int i;
   // The Idea Behind This Algorithm Is That If The Point
   // Is Inside All 6 Clipping Planes Then It Is Inside Our
   // Viewing Volume So We Can Return True.
   for(i = 0; i < 6; i++)
   {
      if(m_Frustum[i][0] * x + m_Frustum[i][1] * y + m_Frustum[i][2] * z + m_Frustum[i][3] <= -radius)
      {
         return(false);
      }
   }
   return(true);
}


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group