pythonpygamepyopenglobjloader

Python PyOpenGl OBJ model shown with fliped normals


i made this small program using Python, Pygame, PyOpenGl and the objloader module (https://github.com/yarolig/OBJFileLoader), it just displays a OBJ model:

import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
from objloader import *


from camera import handle_camera_movement

if __name__ == "__main__":
    pygame.init()
    display = (1000,600)
    pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
    glMatrixMode(GL_PROJECTION) # <---- specify projection matrix
    gluPerspective(90, (display[0]/display[1]), 0.1, 100)

    glMatrixMode(GL_MODELVIEW)  # <---- specify model view matrix
    glTranslatef(0.0, 0.0, -5)

    gluPerspective(90, (display[0]/display[1]), 1, 100)

    glTranslatef(0.0,0.0, -10)

    # import file
    model1 = OBJ('chao.obj')

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
        
        # draw model

        handle_camera_movement()

        glPushMatrix()
        model1.render()
        glPopMatrix()
        
        pygame.display.flip()
        pygame.time.wait(10)

but when i run the program, the model appears as if the normals are fliped, or the textures are inside out. It appears as if the normals are fliped.


Solution

  • This is not a problem with the normal ones. The back sides of the stitches are partially drawn over the front sides. You just need to enable the Depth Test:

    glEnable(GL_DEPTH_TEST)