Giter Club home page Giter Club logo

gl's Introduction

May 31 2021: I wrote this repository in hope it could be useful for anyone else, but this was a very temporary project for me. I am no longer working on this subject and have no time to maintain it. So this repository is now archived.

OpenGL headless on linux (EGL): sample program

This repository contains a sample python program which runs GPU computations (OpenGL) in headless mode (no display).

The program initializes an OpenGL context using EGL (and, optionally, GBM). It will connect to kernel DRM interface file at /dev/dri/<something>.

Then, to test if it works, it calls very basic OpenGL drawing functions to draw a blue rectangle, and writes a ppm image file.

Requirements

OS libs

In any case, you need appropriate GPU drivers, with libGL and libEGL. If you use a recent Nvidia driver, this will probably be enough. Otherwise (intel integrated GPU for example), the program will try load libgbm.

For example on an ubuntu OS with a mesa-compatible GPU, the following should work:

$ apt install libgl1-mesa-dri libegl1-mesa libgbm1

python libs

You need PyOpenGL and numpy:

$ pip install wheel
$ pip install pyopengl numpy

On my machine, I also had to fix file [python_dir]/site-packages/OpenGL/raw/EGL/_types.py, by applying this modification. It may be already fixed in your pyopengl distribution when you read this.

For more optimized transfers between PyOpenGL and numpy, do:

$ pip install Cython
$ pip install PyOpenGL_accelerate

How to run

To run the program, just type

$ ./main.py

Links

The code is mostly based on the following sample codes and documentation:

gl's People

Contributors

eduble avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gl's Issues

Getting EGL_BAD_DISPLAY on Centos

  File "/gl-master/main.py", line 18, in main
    if not ctx.initialize(WIDTH, HEIGHT):
  File "/gl-master/libegl/context.py", line 10, in initialize
    if not self.initialize_on_device(device, width, height):
  File "/gl-master/libegl/context.py", line 29, in initialize_on_device
    if not egl.eglInitialize(egl_dpy, pointer(major), pointer(minor)):
  File "/var/lang/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 415, in __call__
    return self( *args, **named )
  File "/var/lang/lib/python3.8/site-packages/OpenGL/error.py", line 230, in glCheckError
    raise self._errorClass(
OpenGL.raw.EGL._errors.EGLError: EGLError(
	err = EGL_BAD_DISPLAY,
	baseOperation = eglInitialize,
	cArguments = (
		<OpenGL._opaque.EGLDisplay_pointer object at 0x7f0a07af5e40>,
		<OpenGL.arrays.arraydatatype.LP_c_int object at 0x7f0a07a8c0c0>,
		<OpenGL.arrays.arraydatatype.LP_c_int object at 0x7f0a07a8c140>,
	),
	result = 0
)

You know what may be causing this bug?

AttributeError: 'NoneType' object has no attribute 'decode'

Thank for your example,I find this error.
Traceback (most recent call last):
File "./main.py", line 26, in
main()
File "./main.py", line 18, in main
if not ctx.initialize(WIDTH, HEIGHT):
File "/test/liwei/PIFu-master/gl-master/libegl/context.py", line 10, in initialize
if not self.initialize_on_device(device, width, height):
File "/test/liwei/PIFu-master/gl-master/libegl/context.py", line 15, in initialize_on_device
print("selected: " + device.name)
File "/test/liwei/PIFu-master/gl-master/libegl/devices/generic.py", line 55, in name
return "EGL device " + devstr.decode('ASCII')
AttributeError: 'NoneType' object has no attribute 'decode'

Sorry, could not initialize OpenGL context.

Hi, i want to run opengl without x-server, and i find that our code is the python version of this link, https://developer.nvidia.com/blog/egl-eye-opengl-visualization-without-x-server/
But saddly that i can not run main.py in my server, the error message is as follows:
image
apt install libgl1-mesa-dri libegl1-mesa libgbm1
pip install pyopengl numpy
pip install wheel
All the command that referenced in the readme have been excuted.
the nvidia-smi info is as follows:
image
Do you have any suggestions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.