-
Notifications
You must be signed in to change notification settings - Fork 2
/
colab_render.py
52 lines (43 loc) · 1.7 KB
/
colab_render.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from pyvirtualdisplay import Display
# from selenium import webdriver
# from selenium.webdriver.firefox.options import Options
# Virtual display settings
import numpy as np
import json
import moviepy.editor as mvp
from google.colab import files
def init_virtual_display():
display = Display (visible = 0, size = (800, 600))
display.start ()
import os
import pyrender
if 'PYOPENGL_PLATFORM' not in os.environ:
from pyrender.platforms.pyglet_platform import PygletPlatform
_platform = PygletPlatform(500, 600)
elif os.environ['PYOPENGL_PLATFORM'] == 'egl':
from pyrender.platforms import egl
device_id = int(os.environ.get('EGL_DEVICE_ID', '0'))
egl_device = egl.get_device_by_index(device_id)
_platform = egl.EGLPlatform(500, 600,
device=egl_device)
import ctypes
from ctypes import pointer, util
import os
from lucid.misc.gl.glcontext import create_opengl_context
# Now it's safe to import OpenGL and EGL functions
import OpenGL.GL as gl
# create_opengl_context() creates GL context that is attached to an
# offscreen surface of specified size. Note that rendering to buffers
# of different size and format is still possible with OpenGL Framebuffers.
#
# Users are expected to directly use EGL calls in case more advanced
# context management is required.
WIDTH, HEIGHT = 640, 480
create_opengl_context((WIDTH, HEIGHT))
# OpenGL context is available here.
print(gl.glGetString(gl.GL_VERSION))
print(gl.glGetString(gl.GL_VENDOR))
# print(gl.glGetString(gl.GL_EXTENSIONS))
if __name__ == "__main__":
init_virtual_display()
init_virtual_display()