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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:06:42+00:00 2026-06-09T16:06:42+00:00

I am not able to render my all objects using more than 1 pair

  • 0

I am not able to render my all objects using more than 1 pair of vertex and index buffer objects. To check everything, I initialized just 3 objects and render them. This results in a distorted geometry for the first two and the third objects geometry renders somewhat fine (not perfect).

When I just initialize all of the 3 but render just first, it again shows distorted geometry and somehow the third geometry is more visible (even when I am not rendering it).

However, If I am initializing and rendering any one of them, it renders just fine (perfect).
here is my code:

float tempAngles[4] = {0, 60, 180, 360};
pieOne = [[IVNode alloc]initWithPieGeometry:0.75 thickness:0.20 startAngle:tempAngles[0]*M_PI/180   andEndAngle:tempAngles[1]*M_PI/180];

glGenBuffers(1, &vertexBuffer1);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer1);//vertexBuffer[i]);
glBufferData(GL_ARRAY_BUFFER, [pieOne.pie getVertexSize]*sizeof(GLfloat), [pieOne.pie returnVertexArray] , GL_STATIC_DRAW);

glGenBuffers(1, &indexBuffer1);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer1);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, [pieOne.pie getIndicesSize]*sizeof(GLushort),[pieOne.pie returnIndexArray], GL_STATIC_DRAW);

pieTwo = [[IVNode alloc]initWithPieGeometry:1.0 thickness:0.20 startAngle:tempAngles[1]*M_PI/180 andEndAngle:tempAngles[2]*M_PI/180];

glGenBuffers(1, &vertexBuffer2);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer2);//vertexBuffer[i]);
glBufferData(GL_ARRAY_BUFFER, [pieTwo.pie getVertexSize]*sizeof(GLfloat), [pieTwo.pie returnVertexArray] , GL_STATIC_DRAW);

glGenBuffers(1, &indexBuffer2);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer2);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, [pieTwo.pie getIndicesSize]*sizeof(GLushort),[pieTwo.pie returnIndexArray], GL_STATIC_DRAW);


pieThree = [[IVNode alloc]initWithPieGeometry:0.75 thickness:0.20 startAngle:tempAngles[2]*M_PI/180 andEndAngle:tempAngles[3]*M_PI/180];

glGenBuffers(1, &vertexBuffer3);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer3);//vertexBuffer[i]);
glBufferData(GL_ARRAY_BUFFER, [pieThree.pie getVertexSize]*sizeof(GLfloat), [pieThree.pie returnVertexArray] , GL_STATIC_DRAW);

glGenBuffers(1, &indexBuffer3);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer3);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, [pieThree.pie getIndicesSize]*sizeof(GLushort),[pieThree.pie returnIndexArray], GL_STATIC_DRAW);

//#define BUFFER_OFFSET(i) ((char *)NULL + (i))
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 6*sizeof(GLfloat), BUFFER_OFFSET(0));
glEnableVertexAttribArray(GLKVertexAttribNormal);
glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 6*sizeof(GLfloat), BUFFER_OFFSET(12));

Now In my rendering function I have:

-(void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{

glClearColor(0.77f, 0.88f, 1.0f, 1.0f);     
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


float yellow[3][4] = {1.0f, 1.0f, 0.0f, 1.0f,
    1.0f, 0.0f, 0.0f, 1.0f,
    1.0f, 1.0f, 1.0f, 1.0f};

glUseProgram(_program);
//1st   
GLKMatrix4 model = GLKMatrix4Identity;// GLKMatrix4MakeTranslation(1.5, 0, 0);
_modelViewProjectionMatrix = GLKMatrix4Multiply(_modelViewProjectionMatrix, model);

glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX], 1, 0, _modelViewProjectionMatrix.m);
glUniformMatrix3fv(uniforms[UNIFORM_NORMAL_MATRIX], 1, 0,_normalMatrix.m);
glUniform4f(uniforms[COLOR_VECTOR], yellow[0][0], yellow[0][1], yellow[0][2], yellow[0][3]);   

//bind corresponding buffer before drawing
glBindBuffer(GL_ARRAY_BUFFER, indexBuffer1);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer1);
glDrawElements(GL_TRIANGLES, [pieOne.pie getIndicesSize], GL_UNSIGNED_SHORT, (void*)0);

//2nd    
model = GLKMatrix4MakeTranslation(0, -1, 0);
_modelViewProjectionMatrix = GLKMatrix4Multiply(_modelViewProjectionMatrix, model);

glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX], 1, 0, _modelViewProjectionMatrix.m);
glUniformMatrix3fv(uniforms[UNIFORM_NORMAL_MATRIX], 1, 0,_normalMatrix.m);//
glUniform4f(uniforms[COLOR_VECTOR], yellow[1][0], yellow[1][1], yellow[1][2], yellow[1][3]);   

//bind corresponding buffer before drawing
glBindBuffer(GL_ARRAY_BUFFER, indexBuffer2);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer2);
glDrawElements(GL_TRIANGLES, [pieTwo.pie getIndicesSize], GL_UNSIGNED_SHORT,(void*)0);

//3rd
model = GLKMatrix4MakeTranslation(-1.5, 0, 0);
_modelViewProjectionMatrix = GLKMatrix4Multiply(_modelViewProjectionMatrix, model);
glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX], 1, 0, _modelViewProjectionMatrix.m);
glUniformMatrix3fv(uniforms[UNIFORM_NORMAL_MATRIX], 1, 0,_normalMatrix.m);
glUniform4f(uniforms[COLOR_VECTOR], yellow[2][0], yellow[2][1], yellow[2][2], yellow[2][3]);   

//bind corresponding buffer before drawing
glBindBuffer(GL_ARRAY_BUFFER, indexBuffer3);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer3);
glDrawElements(GL_TRIANGLES, [pieThree.pie getIndicesSize], GL_UNSIGNED_SHORT, (void*)0);

}

getIndicesSize returns the number of elements in indexArray.
getVertexSize return the number of elements in vertexArray.
returnVertexArray returns the vertex array of the geometry.
returnIndexArray returns the index array of the geometry.
vertex array is of type GLfloat.
index array is of type GLushort.

Number of elements in vertex array generated is 24522.
Number of elements in Index array generated is 22680.
On the internet, only examples of multiple VBO/IBO I found were not using GLkit and they did exactly what I am doing here in terms of initializing buffers and rendering.
I have spent almost 2 days on this issue. I feel there is some very basic thing missing. Somehow the last bound buffer affects all other geometries I feel (based on my results as I explained above). Could it be a simulator issue (I don’t think so)? Fast response will be appreciated. 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-09T16:06:44+00:00Added an answer on June 9, 2026 at 4:06 pm

    You seem to have some confusion about how the glVertexAttribPointer functions are supposed to work. When you call glVertexAttribPointer, it tells OpenGL:

    On the next draw call, render starting from the address of the currently bound buffer plus the provided buffer offset.

    After this, it doesn’t matter if you change what buffer is bound, because the pointer still points to the buffer that was bound at the time of the function call.

    Therefore in this code:

    glBindBuffer(GL_ARRAY_BUFFER, indexBuffer1);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer1);
    glDrawElements(GL_TRIANGLES, [pieOne.pie getIndicesSize], GL_UNSIGNED_SHORT, (void*)0);
    

    Calling glBindBuffer(GL_ARRAY_BUFFER) does absolutely nothing here, because you’re not updating the pointer.

    glBindBuffer(GL_ARRAY_BUFFER, indexBuffer1);
    //need to set glVertexAttribPointers here
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer1);
    glDrawElements(GL_TRIANGLES, [pieOne.pie getIndicesSize], GL_UNSIGNED_SHORT, (void*)0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not able to store all binary data values into sqlite3 table using QT. For
i am not being able to render a bulleted list through xml/xsl transformation. I
Hi I am not able to capture the screen shot using selenium webdriver .
Not able to download artifacts from central maven repository. <mirrors> <!-- mirror | Specifies
not able to get this, can someone help for this LINQ query? select col1,
Im not able to load the page with circlepageindicator. This is the xml <FrameLayout
I am not able to understand how to rotate the image. I am trying
I am not able to find a similar question else where on this site,
I am not able to apply onclick event in global custom text field. This
I am not able to build my application via Ant build.xml file when I

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.