简体   繁体   中英

how to apply lighting to .obj file on pyopengl

i implement arcball with an object from .obj file in the center when i try to implement lighting, the object show strange behaviour

初始状态

when i turn the object slightly, the object deconstruct and suddenly show the back side

对象解构

显示背面

this behaviour doesn's come up until i implement lighting based on this How to correctly add a light to make object get a better view with pygame and pyopengl

this is what i do regarding the lighting impelementation

if __name__ == "__main__":
    pygame.init()
    display = (SCREEN_WIDTH,SCREEN_HEIGHT)
    screen = pygame.display.set_mode(display, DOUBLEBUF|OPENGL)

    glMatrixMode( GL_PROJECTION );
    gluPerspective(45, (display[0]/display[1]), 0.1, 30000.0)

    glTranslatef(0.0, 0.0, -250)

    glLight(GL_LIGHT0, GL_POSITION,  (1, 1, 1, 0)) 
    glLightfv(GL_LIGHT0, GL_AMBIENT, (0, 0, 0, 1))
    glLightfv(GL_LIGHT0, GL_DIFFUSE, (2, 2, 2, 1))
    
    while True:
        mouse_pos = pygame.mouse.get_pos()

        glMatrixMode( GL_MODELVIEW )
        glLoadIdentity()

        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)

        glEnable(GL_LIGHTING)
        glEnable(GL_LIGHT0)
        glEnable(GL_COLOR_MATERIAL)
        glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE )

        object1.draw()

        glDisable(GL_LIGHT0)
        glDisable(GL_LIGHTING)
        glDisable(GL_COLOR_MATERIAL)

        pygame.display.flip()
        pygame.time.wait(10)

You have to enable the Depth Test . Enable the depth test before the application loop:

glEnable(GL_DEPTH_TEST)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM