Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create opengl context via drm (Linux)

I want to use OpenGL rendering without X, with google i find it: http://dvdhrm.wordpress.com/2012/08/11/kmscon-linux-kmsdrm-based-virtual-console/ there says that it is possible. I should use DRM and EGL. EGL can create opengl context but requires a NativeWindow. DRM probably will provide me NativeWindow, is not it? Should i use KMS? I know that i must have open source video driver. I want exactly OpenGL context, but not OpenGL ES (Linux). Maybe, someone knows tutorial or example code?

like image 821
user2616346 Avatar asked Apr 17 '14 17:04

user2616346


1 Answers

Yes, you need kms stack (example). Here is a simple example under linux, it use OpenGL es, But the step to have it working against OpenGL api are simple.

In the egl attribs set EGL_RENRERABLE_TYPE to EGL_OPENGL_BIT

And tell egl which api to bind to:

eglBindAPI(EGL_OPENGL_API);

Be sure to have latest kernel drivers and mesa-dev, libdrm-dev, libgbm-dev. This pieces of code is portable on android, it's just not so easy to have default android graphic stack silenced.

note: I had trouble with 32bit version, but still don't know why. those libs are actively developed, so not sure it wasn't a bug.

*note2: depending on your GLSL version, float precision is supported or not.

precision mediump float;

note3: if you have permision failure with /dev/dri/card0, grant it with:

sudo chmod 666 /dev/dri/card0

or add current user to video group with

sudo adduser $user video

you may also setguid for your executable with group set to video. (maybe best option)

like image 102
j-p Avatar answered Sep 20 '22 09:09

j-p