tdrmk / pygame_recorder

Video Recorder for PyGame applications using OpenCV
MIT License
10 stars 3 forks source link

Not working for 3D drawing #2

Open nam-usth opened 1 year ago

nam-usth commented 1 year ago

Good day.

I saw your code work flawlessly with the 2D images (since the win.fill() function works well in 2D graphics).

However, I'm trying to record a 3D scene; I have a cube() function that draws the cube into the scene.

[...]
datas = pygame.image.tostring(image, 'RGBA')
texID = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, texID)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.get_width(), image.get_height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, datas)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)

glEnable(GL_TEXTURE_2D)

# Create a screen recorder object
recorder = ScreenRecorder(1376, 768, 60, out_file='output.avi')

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

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)

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

    glRotatef(rotation_speed, 0, 1, 0)

    # Draw       
    solid_cube()

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

    pygame.display.flip()

    recorder.capture_frame(screen)

    clock.tick(60)

recorder.end_recording()

When I call your recorder, the code runs without any error, but the output video is completely black. Is there any solution to this?

p/s: The source code for 3D Cube with texture can be found at https://stackoverflow.com/questions/67367424/how-do-i-add-an-image-as-texture-of-my-3d-cube-in-pyopengl

Matyas2003 commented 7 months ago

Good day.

I saw your code work flawlessly with the 2D images (since the win.fill() function works well in 2D graphics).

However, I'm trying to record a 3D scene; I have a cube() function that draws the cube into the scene.

[...]
datas = pygame.image.tostring(image, 'RGBA')
texID = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, texID)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.get_width(), image.get_height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, datas)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)

glEnable(GL_TEXTURE_2D)

# Create a screen recorder object
recorder = ScreenRecorder(1376, 768, 60, out_file='output.avi')

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

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)

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

    glRotatef(rotation_speed, 0, 1, 0)

    # Draw       
    solid_cube()

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

    pygame.display.flip()

    recorder.capture_frame(screen)

    clock.tick(60)

recorder.end_recording()

When I call your recorder, the code runs without any error, but the output video is completely black. Is there any solution to this?

p/s: The source code for 3D Cube with texture can be found at https://stackoverflow.com/questions/67367424/how-do-i-add-an-image-as-texture-of-my-3d-cube-in-pyopengl

Did you find asolution? I have the same problem.