Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Ligthing problems

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2013
    Posts
    7

    Ligthing problems

    I have a problem with ligthing. In the picture below, the arms and legs of the robot are drawn with the same code as the center pole. But for some
    reason, the lighting just works on the center pole. Does someone know whats going on??

    Click image for larger version. 

Name:	open-gl-output.jpg 
Views:	114 
Size:	4.1 KB 
ID:	1018


    ************************************************** ************************************************** *****
    **********************************This is my display function****************************************
    ************************************************** ************************************************** *****
    def display():
    global RobotSwingAngle
    glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT) #Clear the buffer that stores color information.
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()

    glPushMatrix()



    glPushMatrix()
    #Scale the axis
    glScalef(50,50,50)
    #X is Red
    #Y is Green
    #Z is Blue
    axis()
    glScalef(.04,.04,.04)
    glTranslated(0,28,30)
    glRotated(-90,1,0,0)
    glRotated(-90,0,1,0)

    glColor3f(1,0,0) # the default color is red

    global CubicSurfaceControlPointList
    global StopFlagWaving

    if StopFlagWaving == False:
    #Make the flag wave

    CubicSurfaceControlPointList[0][3] = 10*sin(FlagWaving)
    CubicSurfaceControlPointList[1][3] = 10*sin(FlagWaving)
    CubicSurfaceControlPointList[2][3] = 10*sin(FlagWaving)
    CubicSurfaceControlPointList[3][3] = 10*sin(FlagWaving)

    CubicSurfaceControlPointList[4][3] = 10*cos(FlagWaving)
    CubicSurfaceControlPointList[5][3] = 10*cos(FlagWaving)
    CubicSurfaceControlPointList[6][3] = 10*cos(FlagWaving)
    CubicSurfaceControlPointList[7][3] = 10*cos(FlagWaving)


    CubicSurfaceControlPointListCOPY = copy.deepcopy(CubicSurfaceControlPointList)
    ComputeCubicSurfacePointList(CubicSurfaceControlPo intList)
    CubicSurfaceControlPointList = CubicSurfaceControlPointListCOPY


    glBegin(GL_TRIANGLES)

    for k in range(0,len(CubicSurfacePointList),1):


    if CubicSurfacePointList[k][0] == 'f':
    p = CubicSurfacePointList[k][1]

    x0 = float(CubicSurfacePointList[int(p)-1][1])

    y0 = float(CubicSurfacePointList[int(p)-1][2])

    z0 = float(CubicSurfacePointList[int(p)-1][3])


    p = CubicSurfacePointList[k][2]

    x1 = float(CubicSurfacePointList[int(p)-1][1])

    y1 = float(CubicSurfacePointList[int(p)-1][2])

    z1 = float(CubicSurfacePointList[int(p)-1][3])


    p = CubicSurfacePointList[k][3]

    x2 = float(CubicSurfacePointList[int(p)-1][1])

    y2 = float(CubicSurfacePointList[int(p)-1][2])

    z2 = float(CubicSurfacePointList[int(p)-1][3])

    drawFace(x2,y2,z2, x1,y1,z1, x0,y0,z0)

    glEnd()
    glPopMatrix()

    DrawFloor(150.0,150.0)

    #The pole is drawn in the z axis
    glPushMatrix()
    glColor(.5,.5,1)
    glRotated(-90,1,0,0)

    DrawCenterPole()

    glPopMatrix()



    #glCallList(1) => Paralellogram
    #glCallList(2) => Cylinder
    #glCallList(3) => Sphere
    glRotated(RobotRotationAngle,0,1,0)

    #glCallList(1)

    #The robot will be draw to respect to its torso

    glTranslated(100,40.0,0.0)


    glPushMatrix()

    #Scale the robot
    glScalef(40,40,40)


    #Draw Robot's Torso
    glColor(.5,.5,.1)
    glCallList(1)


    #Draw Robot's Head
    glPushMatrix()
    glColor(0,0,1)
    glTranslated(0.0,.8,0.0)
    #glCallList(3)
    glutSolidSphere(.3,20,20)
    glPopMatrix()


    #Draw Robot's Right Arm
    glPushMatrix()
    glColor(0,1.0,0)
    glRotated(90,1,0,0)
    #Make the arm swing
    glTranslated(0.3,0,-.4)
    glRotated(80*cos(RobotSwingAngle),1,0,0)
    glCallList(2)
    glPopMatrix()

    #Draw Robot's Left Arm
    glPushMatrix()
    glColor(0,1,1)
    glRotated(90,1,0,0)
    #Make the arm swing
    glTranslated(-0.3,0,-.4)
    glRotated(-80*cos(RobotSwingAngle),1,0,0)
    glCallList(2)
    glPopMatrix()

    #Draw Robot's Right leg
    glPushMatrix()
    glColor(1,0,0)
    glRotated(90,1,0,0)
    #Make the arm swing
    glTranslated(0.3,0,.4)
    glRotated(-80*cos(RobotSwingAngle),1,0,0)


    glCallList(2)
    glPopMatrix()

    #Draw Robot's Left leg
    glPushMatrix()
    glColor(1,0,1)
    glRotated(90,1,0,0)
    #Make the arm swing
    glTranslated(-0.3,0,.4)
    glRotated(80*cos(RobotSwingAngle),1,0,0)
    glCallList(2)
    glPopMatrix()


    glPopMatrix()

    glPopMatrix()

    DisplayCam()

    glFlush() #Flush
    #empties all of these buffers, causing all issued commands to
    #be executed as quickly as they are accepted by the actual rendering engine

    glutSwapBuffers() #Draw the frame in one of the buffers and calculate the
    #the frame of the other buffer.


    ************************************************** ************************************************** *****
    *******************This are the DrawCenterPole Function and Cylinder function*****************
    ************************************************** ************************************************** *****

    def DrawCenterPole():
    quadric = gluNewQuadric();
    gluQuadricTexture(quadric, True)


    gluQuadricDrawStyle(quadric, GLU_FILL);

    gluCylinder(quadric, 4, 4, 120, 20, 20);









    def Cylinder(BaseRadius,TopRadius,Height):

    glNewList(2,GL_COMPILE)
    quadric = gluNewQuadric();

    gluQuadricDrawStyle(quadric, GLU_FILL);

    gluCylinder(quadric, BaseRadius, TopRadius, Height, 20, 20);

    glEndList()
    Last edited by farrington; 05-05-2013 at 02:59 PM.

  2. #2
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    if you want someone to read this, you should format your code and use [ CODE][ /CODE] tags.

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2013
    Posts
    7
    Can you give a smal example of how to use the

    [ CODE] [ /CODE] tags?
    The above post is Python code.

  4. #4
    Junior Member Newbie
    Join Date
    Mar 2013
    Posts
    7

    I figured out how to solve my problem

    The problem is that after scaling for a scaling factor greater than 1, the normals doesn't stay normalized.
    So, I just used "glEnable(GL_NORMALIZE)" and the problem was solved.


    But, Why Open GL scale the normals in conjunction with the model??

  5. #5
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,220
    The default is set for maximum efficiency. This is the case where your MODELVIEW transform does not contain any scales or shears (just rotates and translates).

    If you do use scales in your MODELVIEW, then there is a (nowadays small) perf cost associated with renormalizing the normals to support this. You choose to accept that when you enable GL_NORMALIZE.

    Also, if dusty fixed-function pipe memory serves, there is a GL_RESCALE_NORMAL enable that IIRC allegedly could be more efficient that GL_NORMALIZE if you just had uniform scales in your MODELVIEW. Might read up on it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •