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 8388715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:31:56+00:00 2026-06-09T18:31:56+00:00

Basically what I want to do is generate my vertex coordinates programmatically instead of

  • 0

Basically what I want to do is generate my vertex coordinates programmatically instead of storing it in a statically predefined array. Unfortunately I am not able to convert a very simple example to a dynamic array.

Everything works fine if I stick to static arrays:

typedef struct {
    GLfloat Position[3];
    GLfloat Color[4];
    GLfloat TexCoord[2];
    float Normal[3];
} Vertex;


Vertex sphereVertices[] = {
    {{1, -1, 1}, {1, 0, 0, 1}, {1, 0}, {0, 0, 1}},
    {{1, 1, 1}, {0, 1, 0, 1}, {1, 1}, {0, 0, 1}},
    {{-1, 1, 1}, {0, 0, 1, 1}, {0, 1}, {0, 0, 1}},
    {{-1, -1, 1}, {0, 0, 0, 1}, {0, 0}, {0, 0, 1}}
};

GLubyte sphereIndices [] = {
    0, 1, 2,
    2, 3, 0
};

…

glGenBuffers(1, &sphereIndexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, sphereIndexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(sphereIndices), sphereIndices, GL_STATIC_DRAW);

glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, Position));

…

glDrawElements(GL_TRIANGLES, 6 * sizeof(GLubyte), GL_UNSIGNED_BYTE, 0);

As soon as I switch my indices to a dynamic array only the first triangle shows up.

GLubyte *sphereIndices;

+(void)initialize {
    sphereIndices = malloc(6 * sizeof(GLubyte));
    sphereIndices[0] = 0;
    sphereIndices[1] = 1;
    sphereIndices[2] = 2;
    sphereIndices[3] = 2;
    sphereIndices[4] = 3;
    sphereIndices[5] = 0;
}

Probably this has something to do with pointers. Does anybody know what I am doing wrong?

Thanks!

  • 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-06-09T18:31:58+00:00Added an answer on June 9, 2026 at 6:31 pm

    I was able to solve the problem myself. As I already expected the problem had to do with my missing understanding of pointers.

    As far as I found out, there is no way to get the size of a dynamic array. Because of that sizeof(sphereIndices) always returns 4 which is the size of the pointer not the size of the data. That’s why glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(sphereIndices), sphereIndices, GL_STATIC_DRAW) only sends 4 indices to openGL instead of 6.

    I fixed the problem by introducing an additional variable to keep track of the number of indices.

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

Sidebar

Related Questions

Basically, I want to generate an item, in this case, a ring. I have
I basically want to do this in code: PersonList myPersonList; //populate myPersonList here, not
I basically want to be able to deploy multiple versions of the same EAR
I basically want to make things easier by just looping LinkButtons instead of making
Basically I have a class and it is instincable (not static). Basically I want
Basically I want to generate random numbers that won't ever repeat for a very
I basically want to write me a bash script, where I'd generate a couple
I need to generate time-stamp in this format yyyymmdd. Basically I want to create
I basically want something like: TextView Button Button . . . TextView TextView SeekBar
I basically want to setup a relationship similar to Netflix's DVD rental model. There

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.