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

  • Home
  • SEARCH
  • 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 7667889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:13:08+00:00 2026-05-31T15:13:08+00:00

Without any code at first let me describe the problem. I recreated the basic

  • 0

Without any code at first let me describe the problem.

I recreated the basic lesson for a rotating cube. Lesson 4 Learning Webgl
http://learningwebgl.com/lessons/lesson04/index.html

The code has 4 vertices listed for each face for a total of 24 vertices. It uses indices to these 24 vertices 0-23 to do a drawElements(…) and it uses a color buffer array with 24 different colors.

So the end result of course is a rotating cube with each face assigned a different color.

What I did was work with the fact that a cube really only has 8 vertices not 24. So I made an array of 8 vertices. And I reworked the position index array to work with indices from 0-7 instead of what was given 0-23. I left the color buffer array alone since I put the same order to the face creation as in the original lesson.

When I completed the drawElements(…), I did have a perfect rotating cube. But the cube is not colored correctly. Each vertex has a single color so only the first eight of the color array elements (out of 24) were used. Basically The top half is one color and the bottom half is another color. And the faces of the cube do not have a unique color.

The question is : is there a way to assign color to vertex indices instead of to vertices?
I am suspecting that I could use gl_vertexID in the shaders, but I thought I’d get some opinions first?

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-05-31T15:13:09+00:00Added an answer on May 31, 2026 at 3:13 pm

    The short answer is no.

    Basically you have tree options for assigning values to vertices:

    1. Assign a unique value per vertex. Note that if you want to use a vertex with different values (such as different colors for each face), then there must exist a unique vertex for each ‘configuration’
    2. Sometimes it is possible to compute the value in the vertex or fragment shader (this will actually work in your case).
    3. Use a uniform shader value – this will assign the same value to all vertices (that is clearly not what you want in this case).

    For more information I suggest you read my blog-posts about Procedural Mesh Generation in Unity , since it explains the basic concepts:

    • http://blog.nobel-joergensen.com/2010/12/25/procedural-generated-mesh-in-unity/
    • http://blog.nobel-joergensen.com/2011/04/05/procedural-generated-mesh-in-unity-part-2-with-uv-mapping/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WCF service and without changing any code on the client side,
Is it possible to create a Line in XAML (without any C# code behind)
I tried this aproach without any success the code I'm using: // File name
I tried without any result. My code looks like this: #include stdafx.h #include <iostream>
First let me introduce implementation without Dependency Injection (which will break Dependency Inversion Principle):
Let's say there is a simple test code typedef struct { int first; int
Building the same project (without any changes) produces binary different exe-files: some small regions
I have two tables without any cascade deleting. I want to delete parent object
We have a small embedded system without any video or serial ports (i.e. we
I like to create a Cocoa window without any chrome whatsoever. The only thing

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.