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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:41:40+00:00 2026-06-12T23:41:40+00:00

I’m starting from the Apple-spupplied iOS OpenGL game template in Xcode and I have

  • 0

I’m starting from the Apple-spupplied iOS OpenGL game template in Xcode and I have an array of structs (more of an array of structs of structs, if you will) that I’m trying to use with an OpenGL VBO. However, while I get no errors, nothing is drawn to the screen.

First I create and populate this array which is of type VecAttributeType, a struct which in turn has 3 other structs: vPosition, vTCoordinates and vNormal.
Then I try copying the array to a VBO and binding the positions and normals (meaning VecAttributeType.vPosition and VecAttributeType.vNormal in terms of offsets) via glVertexAttribPointer to the appropriate in / attributes in the vertex shader.
Then I try rendering.

And nothing is drawn :/

Mind you, the arrayOfStructs contains ALL vertices needed to draw the model. That is, I’m not using indices to vertices. Rather, for this test, I’m going through the face definitions in the obj and for each index, retrieving the appropriate vertex,texture,normal and copying it in the arraOfStructures.

So for instance, for a classic cube in obj format, the file lists 8 vertices but my final arrayOfStructs has length 12 and there’s 12 VecAttributeType structs in it, each with the right position, texture coord and normal for that vertex, derived from the indices in the obj file’s face definition. And yes, I’m offsetting the indices in the f definitions by -1 to account for the fact that obj files index starting at 1.

My guess is that I’m simply calculating the offset into the VBO for the positions and normals wrong. I think so because I’ve tried printing the first position x coordinate in the first VecAttributeType in the arrayOfStructures like so:

NSLog(@"\nTEST:\nfirst vertex X = %f", arrayOfStructs[0].vPosition.x);

and I get the expected value, while trying to print like so:

char* address = (char*)arrayOfStructs+offsetof(VecAttributeType, vPosition.x);
    float b = *address;
    NSLog(@"\nTEST:\nfirst vertex X = %f",  b);

prints 0 instead (the right value should be 1);

Here are the relevant sections of code:

//Inside a c++ class I'm parsing an Obj and creating the vertex attribute array:
typedef struct
{
    float x;
    float y;
    float z;

} Vec3fType;

typedef struct
{
    float s;
    float t;

} Vec2fType;

typedef struct
{
    int p;
    int n;
    int t;

} Vec3iType;

typedef struct
{
    Vec3fType vPosition;
    Vec3fType vNormal;
    Vec2fType vTCoordinates;

} VecAttributeType;

int arrayLength = // Some number;
VecAttributeType* arrayOfStructs = new VecAttributeType[arrayLength];

//  Populate the array.

// . . .

// Then, in the ViewController (Objective-C) class, I try binding to the VBO and getting the offsets right:


[EAGLContext setCurrentContext:self.context];

[self loadShaders];

glEnable(GL_DEPTH_TEST);

GLuint _vertexBuffer;
glGenBuffers(1, &_vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(VecAttributeType)*arrayLength, arrayOfStructs, GL_STATIC_DRAW);
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(VecAttributeType), BUFFER_OFFSET(0) + offsetof(VecAttributeType, vPosition) + offsetof(Vec3fType, x));
glEnableVertexAttribArray(GLKVertexAttribNormal);
glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, sizeof(VecAttributeType), BUFFER_OFFSET(0) + offsetof(VecAttributeType, vNormal) + offsetof(Vec3fType, x));

And finally, the drawing code is:

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
    glClearColor(1.f, 0.f, 0.f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBindVertexArrayOES(_vertexArray);

    // Render the object again with ES2
    glUseProgram(_program);

    glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX], 1, 0, _modelViewProjectionMatrix.m);
    glUniformMatrix3fv(uniforms[UNIFORM_NORMAL_MATRIX], 1, 0, _normalMatrix.m);
    glDrawArrays(GL_TRIANGLES, 0, arrayLength);
}

Any ideas?

  • 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-12T23:41:41+00:00Added an answer on June 12, 2026 at 11:41 pm

    Ok I got it…
    Turns out at some point I forgot I was using the VAO extension (glBindVertexArrayOES) and after disabling it at the end of the VBO setup, I was forgetting to enable it in glkView:draInRect:

    My code above shows it enabled, but only cause I created a new project to copy the relevant sections of code to before posting on SO.

    Also, the glVertexAttribPointer lines can be rewritten a bit more compactly like this:

    glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(VecAttributeType),(void*)offsetof(VecAttributeType, vPosition.x));
    glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, sizeof(VecAttributeType), (void*)offsetof(VecAttributeType, vNormal.x));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't

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.