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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:09:09+00:00 2026-06-10T02:09:09+00:00

Link to code I have been struggling with this code for about two weeks

  • 0

Link to code

I have been struggling with this code for about two weeks now. I have created a new OpenGL project using the standard apple boiler plate code generated when creating a new OpenGL ES project. It usually consists of two spinning cubes.

I decided that I wanted to change the cubes to pyramids (triangle based). I got the code to work except for the fact that the pyramids are black, as the colour is not rendering correctly. At first I thought is was my normals, but I think they are correct. I would be most grateful if someone could help me with this problem. all the coordinates are in a header file I created.


I also discovered that some of the normal mathematics was out

GLfloat norms[36] = {

0, -1, 0,
0, -1, 0,
0, -1, 0,

1, 0.25, -0.5,
1, 0.25, -0.5,
1, 0.25, -0.5,

-1, 0.25, -0.5,
-1, 0.25, -0.5,
-1, 0.25, -0.5,

0, 0.5, 1,
0, 0.5, 1,
0, 0.5, 1
};

These are the correct norms. thanks for all your help GC

spinning pyramids image

  • 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-10T02:09:10+00:00Added an answer on June 10, 2026 at 2:09 am

    You cannot bind 2 vertex arrays at a time (glBindVertexArrayOES). You will have to create only 1 and then put all the data into it. Try this approach:

    glGenVertexArraysOES(1, &_vertexArray); //create vertex array
    glBindVertexArrayOES(_vertexArray);
    
    glGenBuffers(1, &_vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(verts) + sizeof(norms), NULL, GL_STATIC_DRAW); //create vertex buffer big enough for both verts and norms and pass NULL as data..
    uint8_t *ptr = (uint8_t *)glMapBufferOES(GL_ARRAY_BUFFER, GL_WRITE_ONLY_OES); //map buffer to pass data to it
    memcpy(ptr, verts, sizeof(verts)); //copy verts
    memcpy(ptr+sizeof(verts), norms, sizeof(norms)); //copy norms to position after verts
    glUnmapBufferOES(GL_ARRAY_BUFFER);
    glEnableVertexAttribArray(GLKVertexAttribPosition);
    glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0)); //tell GL where verts are in buffer
    glEnableVertexAttribArray(GLKVertexAttribNormal);
    glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(verts))); //tell GL where norms are in buffer
    glBindVertexArrayOES(0);
    

    As for checking or computing the normals:

    You can compute and check your normals for sharp edges (whitch is your case) with cross product. For each triangle defined by positions A, B and C:

         s1 = B-A //s1 and s2 are just for easier reading
         s2 = C-A
         N = s1 x s2 //N is normal (not quite ready)
         (cross product:) 
         N.x = s1.y*s2.z - s2.y*s1.z
         N.y = s1.z*s2.x - s2.z*s1.x
         N.z = s1.x*s2.y - s2.x*s1.y
    

    Since ABC can be oriented in any way you might need to turn normal the other way.. You can use the dot product to get this info.. In your case take a point that is near the center of a shape and does not lie on any of triangles defining it (vector Center(0,0,0) just might do). Now for each A, B, C, N:

    vector Average = (A+B+C)/3 //center of a triangle
    if(dotProduct(N, Center-Average)  >  0) N = N * -1
    (dotProduct:)
    dot(M,N) = M.x*N.x + M.y*N.y + M.z*N.z
    

    After that you should normalize each normal (divide each component by lenght of a normal resulting in each normal having a lenght of 1) Alternatively you can set normalize flag on:
    glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_TRUE…

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

Sidebar

Related Questions

so I've been struggling with this piece of code for hours now, I have
I have been struggling in fixing this code, wonder what is wrong at all...
I have this code: ie1.link(:text, /Exception:/) It is producing an error message which I
I have borrowed code from this link PHP regex templating - find all occurrences
I have some code right now that executes when a link is clicked. The
I have this code in the end of link button click: Response.ContentType = application/zip;
i have this code: $('.access a').toggle(function() { $('link').attr('href', 'styles/accessstyles.css'); $('body').css('font-size', '16px'); }, function() {
When I have download sample code from this link and than try to build
I have this code in my view.. <span class=bold>Comment: <%=Html.TextAreaFor(model => model.Comment, new {
I have been struggling for too long a time now with a rather simple

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.