Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6391569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:41:16+00:00 2026-05-25T03:41:16+00:00

i am writing a simple application for iphone wich displays a rotating cube. I

  • 0

i am writing a simple application for iphone wich displays a rotating cube.
I am using glDrawElements (openGl es) to draw the triangles of the cube and to rotate it. I’ve noticed that when i increase the size of the cube to 100*100*100 voxels the display performance gets bad
(clarification: i dont draw the whole cube, i draw only it’s outline (mesh). I get all the triangles of the mesh by applying the marching cubes algorithm on the cube … eventually i get something like 120k triangle to draw which are represented by 40k vertices)…

To draw the cube i hold an array of vertices, array of colors and an array if indices to vertices. The indices array defines the triangles of vertexes to be drawn. It is passed to glDrawElements as a param.

Recently i’ve red about a different technique to draw the cube using Vertex Buffer Objects (VBO). I’ve implemented it but the Performance was Even worser then by previous technique

Here is my code, Maybe i’ve done a silly mistake, Any improvement suggestions will be well received 🙂

by the way, i used the following articles as references:

http://playcontrol.net/ewing/jibberjabber/opengl_vertex_buffer_object.html
http://iphonedevelopment.blogspot.com/2009/05/opengl-es-from-ground-up-table-of.html

//all the 7 variables down are initialized by other function at the beginning 
GLushort* meshIndices;    //array of indices (ushort)
MeshVertex* meshVertices; //array of vertices (floats)
Color3D* meshColors;      //array of colors  (floats)

int numberOfTriangles; //number of Triangle to draw the cube
int numberOfVertices;  //number of all Vertices to draw the cube
int numberOfIndices;   //number of all Indices to draw the cube, each 3 indices define 3 vertices which define 1 triangle
int numberOfColors;    //number of colors used to draw the cube. each color is of tip Color3D

//in this function i initializing the VBOs 
- (void) setupMeshVBOs { 

    glGenBuffers(1, &triangleVBO);
    glBindBuffer(GL_ARRAY_BUFFER, triangleVBO);

    const GLsizeiptr vertex_size = numberOfVertices * sizeof(MeshVertex);
    const GLsizeiptr color_size = numberOfColors * sizeof(Color3D);

    glBufferData(GL_ARRAY_BUFFER, vertex_size + color_size, 0, GL_STATIC_DRAW);

    GLvoid* vbo_buffer = glMapBufferOES(GL_ARRAY_BUFFER, GL_WRITE_ONLY_OES); 
    memcpy(vbo_buffer, meshVertices, vertex_size);

    GLbyte* temp = (GLbyte*)vbo_buffer;
    temp += vertex_size;
    memcpy((GLvoid*)temp, meshColors, color_size);

    glUnmapBufferOES(GL_ARRAY_BUFFER); 

    glVertexPointer(3, GL_FLOAT, 0, (GLvoid*)((char*)NULL));

    glColorPointer(4, GL_FLOAT, 0, (GLvoid*)((char*)NULL+vertex_size));

    glGenBuffers(1, &triangleIBO);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, triangleIBO);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, numberOfIndices * sizeof(GLushort), meshIndices, GL_STATIC_DRAW);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}

//this function is the one which draws the VBOs
- (void)drawView:(GLView*)view;
{

    static GLfloat rot = 0.0;


    glLoadIdentity();
    glTranslatef(-1.0f,-2.0f,-20.0f);
    glRotatef(rot,1.0f,1.0f,1.0f);
    glClearColor(0.7, 0.7, 0.7, 1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glBindBuffer(GL_ARRAY_BUFFER, triangleVBO);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, triangleIBO);

        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);

        glDrawElements(GL_TRIANGLE_STRIP, numberOfIndices, GL_UNSIGNED_SHORT, (GLvoid*)((char*)NULL));

        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_COLOR_ARRAY);

    static NSTimeInterval lastDrawTime;
    if (lastDrawTime)
    {
        NSTimeInterval timeSinceLastDraw = [NSDate timeIntervalSinceReferenceDate] - lastDrawTime;
        rot+=50 * timeSinceLastDraw;                
    }
    lastDrawTime = [NSDate timeIntervalSinceReferenceDate];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:41:16+00:00Added an answer on May 25, 2026 at 3:41 am

    Firstly, to draw a 100x100x100 map of cubes, you shouldn’t draw each cube individually. If have, say, six boxes in a row then you should draw them as one long cuboid for twelve triangles total. Any cube that is surrounded on six sides definitely doesn’t need to be considered. You should apply strategies like those to reduce your geometry count significantly.

    Apple’s advice on GL optimisation is here. The summary version is that you should aim to use VBOs with aligned, interleaved data, using the smallest acceptable types. So, implicitly, reading data is a bottleneck. Using two separate lists could conceivably be halving your geometry input rate, and using floats is likely to be slowing it further.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a simple application using the Facebook iPhone SDK. The Facebook code
Hey folks - I'm writing a pretty simple iPhone application. The data comes from
I am writing a very simple application, for the iPhone. Unfortunately I am really
I'm writing a simple OpenGL application that uses GLUT . I don't want to
I am writing a simple iPhone application and I am wondering if there is
I want to create one simple application for sending request from iphone(client) by using
I am writing a iphone application using phonegap and ios. I have a weird
I am writing an application using Objective-C for iPhone. In this application, the user,
I'm writing fairly simple application which connects to server through SSH (using paramiko ),
I'm writing a simple P2P application to test the feasibilty of using UDP hole-punching

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.