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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:39:16+00:00 2026-05-24T15:39:16+00:00

In OpenGL, I draw tree(composed of lines) like structure(neurons), and based on activity, i

  • 0

In OpenGL, I draw tree(composed of lines) like structure(neurons), and based on activity, i apply a color on each of the branches of the tree. Each branch portion may have a different color at an instance. I keep record of the color at an instance corresponding to the branch.

I am able to rotate (by changing the modelview matrix) the tree. I can see the changing color (activity) on the branches when updating.

However, i am not able to rotate the tree while the color change is happening. (the rotation is seen after the complete updating) This is also true with translating the model, not able to translate while updating.

How should i be doing this to see them simultaneously?

i call the updateViz function to update the colors.

def render(self):
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()
    self.renderAxis()   #draws 3 axes at origin
    for obj in self.vizObjects:
        glPushMatrix()
        glColor(obj.r, obj.g, obj.b)
        glLineWidth(2)
        glBegin(GL_LINES)
        glVertex3f(obj.l_coords[0],obj.l_coords[1],obj.l_coords[2])
        glVertex3f(obj.l_coords[3],obj.l_coords[4],obj.l_coords[5])
        glEnd()     
        glPopMatrix()

def updateViz(self,vals):
    inds = digitize(vals,colrMapVals)
    for i in range(0,len(self.vizObjects)):
        self.vizObjects[i].r,self.vizObjects[i].g,self.vizObjects[i].b= colorMap[inds[i]-1]

def translate(self, _trans):
    self.makeCurrent()
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()
    glTranslated(_trans[0], _trans[1], _trans[2])
    glMultMatrixd(self.modelview_matrix_)
    self.modelview_matrix_ = glGetDoublev(GL_MODELVIEW_MATRIX)
    self.translate_vector_[0] = self.modelview_matrix_[3][0]
    self.translate_vector_[1] = self.modelview_matrix_[3][1]
    self.translate_vector_[2] = self.modelview_matrix_[3][2]

def rotate(self, _axis, _angle):
    #self.modelview_matrix_ = glGetDoublev(GL_MODELVIEW_MATRIX)
    t = [self.modelview_matrix_[0][0] * self.center_[0] +
         self.modelview_matrix_[1][0] * self.center_[1] +
         self.modelview_matrix_[2][0] * self.center_[2] +
         self.modelview_matrix_[3][0],
         self.modelview_matrix_[0][1] * self.center_[0] +
         self.modelview_matrix_[1][1] * self.center_[1] +
         self.modelview_matrix_[2][1] * self.center_[2] +
         self.modelview_matrix_[3][1],
         self.modelview_matrix_[0][2] * self.center_[0] +
         self.modelview_matrix_[1][2] * self.center_[1] +
         self.modelview_matrix_[2][2] * self.center_[2] +
         self.modelview_matrix_[3][2]]

    self.makeCurrent()
    glLoadIdentity()
    glTranslatef(t[0], t[1], t[2])
    glRotated(_angle, _axis[0], _axis[1], _axis[2])
    glTranslatef(-t[0], -t[1], -t[2])
    glMultMatrixd(self.modelview_matrix_)
    self.modelview_matrix_ = glGetDoublev(GL_MODELVIEW_MATRIX)

def keyPressEvent(self, ev):
    if (ev.key() == QtCore.Qt.Key_Left):
        self.translate([-0.25, 0.0, 0.0])
        self.updateGL()
    elif (ev.key() == QtCore.Qt.Key_Right):
        self.translate([0.25, 0.0, 0.0])
        self.updateGL()
    elif (ev.key() == QtCore.Qt.Key_A):
        self.rotate([1.0, 0.0, 0.0],2.0)
        self.updateGL()
    elif (ev.key() == QtCore.Qt.Key_Q):
        self.rotate([1.0, 0.0, 0.0],-2.0)
        self.updateGL()

I use PyQt4 and PyGLWidget

  • 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-24T15:39:18+00:00Added an answer on May 24, 2026 at 3:39 pm

    your code looks all right to me. I think the problem is caused by how you update the rotation and color. OpenGL is a state machine, you feed it with all kinds of info (vertex pos, color, etc) and things get rendered, so MAKE SURE updateVis and translate/rotate are called on EVERY FRAME.

    maybe your rotation/translation depends on Qt’s signal/event mechanism, and it’s not called every frame?

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

Sidebar

Related Questions

I have some functions that use opengl to draw lines on the screen (health
I would like to draw a chart in OpenGL similar to the donut graph
I'm using OpenGL and was told I should draw circles at each vertex of
I draw in opengl with RGBA colors these texts (with the color between parenthesis)
I'm using OpenGL ES to draw things in my iPhone game. Sometimes I like
So I would like to draw a 2D point in OpenGL, but not in
I want to draw my opengl es animation in a customed UIView, how can
I need an OpenGL buffer to draw on and retrieve pixel values from. I
I made a fancy shape with OpenGL and I draw that shape this function:
I need to draw 2D overlay over OpenGL scene. OpenGL is used for 2D

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.