Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: How to Draw Cylinder with better performance

  1. #1
    Newbie Newbie
    Join Date
    Aug 2014
    Posts
    1

    Exclamation How to Draw Cylinder with better performance

    Hello there, I am new to Opengl
    I am creating building of LEGO Blocks, so each lego block will have small cylinder on top.

    it will be look like this
    Click image for larger version. 

Name:	legooo_zpse480796e.jpg 
Views:	68 
Size:	20.8 KB 
ID:	1389
    Click image for larger version. 

Name:	Capture_zpsac8b6059.jpg 
Views:	60 
Size:	8.9 KB 
ID:	1390

    I had create cylinder using gluCylinder as follow.
    glPushMatrix();
    glTranslatef(-0.5f,0.0f, 0.0f);
    gluCylinder(pObj, 0.25f, 0.25f, 0.2f, 26, 13);
    glTranslatef( 1.0f, 0.0f, 0.0f);
    gluCylinder(pObj, 0.25f, 0.25f, 0.2f, 26, 13);
    glPopMatrix();
    BUT Once my building become bigger and bigger, it is become very very lag.
    i tried temporary remove the cylinder and it is become very smooth, even when i put 10 big building with many blocks.

    is there any way to improve the speed???
    may i create cylinder using vertex??

    thanks in advance

  2. #2
    Junior Member Regular Contributor
    Join Date
    Nov 2012
    Location
    Oldenburg, Germany
    Posts
    186
    For simplicity - try putting the cylinder in a display list.
    More advanced: Generate the geometry by yourself and put the Vertices into buffers and draw from there.

  3. #3
    Intern Newbie
    Join Date
    Apr 2014
    Posts
    47
    Another thing to reduce the number of stacks/slices you are using, or determine the number of stacks/slices to use based on the distance from the camera so farther cylinders use fewer stacks/slices.

    I'd recommend reducing the number of stacks you are using by at least half. Because the cylinders are small compared to the distance to your light sources, I doubt lighting changes much over the height of the cylinder from end to end so you shouldn't see much difference.
    Code :
    const int stacks = 5;
    const int slices = 26;
    glPushMatrix();
    glTranslatef(-0.5f,0.0f, 0.0f);
    gluCylinder(pObj, 0.25f, 0.25f, 0.2f, slices, stacks);
    glTranslatef( 1.0f, 0.0f, 0.0f);
    gluCylinder(pObj, 0.25f, 0.25f, 0.2f, slices, stacks);
    glPopMatrix();

    Check other performance optimizations such as ensuring you have fall culling on.
    Code :
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

    If you want to go super-advanced, you could use parallax (relief) mapping on the top of your geometry to represent the cylinders (never done it before, but if you will always view geometry from above and never from the side it might work. Disclaimer: never done it before myself... yet!)

  4. #4
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    211
    The 'glu' functions are o.k. for small applications or applications where they are only called a few times. But it's not a good idea to use them when they are going to be called 100's or 1000's of times. This is because they calculate vertex coordinates each time they are called. This sucks up CPU time. Those coordinates only have to be computed once. I would do as Hlewin suggested. MtRoad also has a good suggestion - only 1 stack is needed in your situation.

    Another more basic issue is that gluCylinder does not display the tops and bottoms of cylinders. This is evident even in your small image, where it looks like only the inner facing sides of the cylinders are displayed. What you really need is to display the outer facing side surfaces of the cylinders, plus a top which can be put on using gluDisk. The image below demonstrates what I'm saying. All of the cylinders were generated with 1 stack and 24 slices.

    However, repeating what I said above, you shouldn't be using glu functions in your application.

    Click image for larger version. 

Name:	glu_Cyl_Dsk.jpg 
Views:	67 
Size:	57.9 KB 
ID:	1395
    Last edited by Carmine; 08-13-2014 at 01:41 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •