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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:54:24+00:00 2026-06-17T07:54:24+00:00

I’m working in python / PyOpenGL, but the calls are basically mapped straight to

  • 0

I’m working in python / PyOpenGL, but the calls are basically mapped straight to OpenGL itself so I’m asking for help from people who know either.

I’ve got a big 3D system which I’ve decomposed into facets myself. My first attempt at the code looked something like this:

from OpenGL.GL import *

def render(facets):
  for facet in facets:
    glColor( facet['color'] )
    glBegin(GL_TRIANGLES)
    for v in facet['vertices']:
      glVertex(v)
    glEnd()

i.e. I ran over the python objects one at a time, and drew them each individually. The color rendered was set per facet, i.e. per triangle, as the triangle’s surface color.

Having debugged my code for generating the facets this way, I wanted to render them faster using a native OpenGL list, like this (based on a source snippet from pyglet):

def build_compiled_gllist(vertices, facets):
  """this time, the vertices must be specified globally, and referenced by
  indices in order to use the list paradigm. vertices is a list of 3-vectors, and
  facets are dicts containing 'normal' (a 3-vector) 'vertices' (indices to the 
  other argument) and 'color' (the color the triangle should be)."""

  # first flatten out the arrays:
  vertices = [x for point in vertices for x in point]
  normals = [x for facet in facets for x in facet['normal']]
  indices = [i for facet in facets for i in facet['vertices']]
  colors = [x for facet in facets for x in facet['color']]

  # then convert to OpenGL / ctypes arrays:
  vertices = (GLfloat * len(vertices))(*vertices)
  normals = (GLfloat * len(normals))(*normals)
  indices = (GLuint * len(indices))(*indices)
  colors = (GLfloat * len(colors))(*colors)

  # finally, build the list:
  list = glGenLists(1)
  glNewList(list, GL_COMPILE)

  glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT)
  glEnableClientState(GL_VERTEX_ARRAY)
  glEnableClientState(GL_NORMAL_ARRAY)
  glEnableClientState(GL_COLOR_ARRAY)
  glVertexPointer(3, GL_FLOAT, 0, vertices)
  glNormalPointer(GL_FLOAT, 0, normals)
  glColorPointer(3, GL_FLOAT, 0, colors)
  glDrawElements(GL_TRIANGLES, len(indices), GL_UNSIGNED_INT, indices)
  glPopClientAttrib()

  glEndList()

  return list

def run_gl_render(render_list):
  """trivial render function"""
  glCallList(render_list)

However, my colors come out completely wrong. The facets are grouped into objects, and within an object all the facet colors should be the same; instead they seem to be completely random.

Looking at other examples, it seems that this array of colors is per-vertex rather than per-facet. How does that make sense? Vertices are points which by definition can’t be rendered – the facets are what are rendered and what have colors! Every vertex in my system is shared between two of the facet-collections / objects, and thus should have two colours to its name.

Someone please clarify how this data is supposed to be structured; I have clearly misunderstood the model I’m working with.

  • 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-17T07:54:26+00:00Added an answer on June 17, 2026 at 7:54 am

    Yes, color is specified per-vertex. Depending on the shade model, only one of the colors may be used, but each vertex still gets a color. Your code should work if you replace

    colors = [x for facet in facets for x in facet['color']]
    

    with

    colors = [x for facet in facets for x in facet['color']*3]
    

    to duplicate the color for each vertex. If your normal data is per-face then you will have to do the same for the normal data. Note also that the color and normal values have to match up with the vertices argument, not the indices.

    By the way, you can still create a display list using your original code. That is, it’s perfectly valid to do

    def compile_object(facets):
      displist = glGenLists(1)
      glNewList(displist, GL_COMPILE)
      # You can call glColor inside of glBegin/glEnd, so I moved them
      # outside the loop, which might improve performance somewhat
      glBegin(GL_TRIANGLES)
      for facet in facets:
        glColor( facet['color'] )
        for v in facet['vertices']:
          glVertex(v)
      glEnd()
      glEndList()
      return displist
    

    Try these tutorials

    • Display Lists
    • Vertex Arrays
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

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.