如何通过drm创建opengl上下文(Linux) [英] How to create opengl context via drm (Linux)
问题描述
我想在不使用X的情况下使用OpenGL渲染,并在Google上找到它:
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?
推荐答案
是的,您需要公里堆栈(示例). 此处是linux下的一个简单示例,它使用OpenGL es,但是使它与OpenGL api兼容的步骤很简单.
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.
在egl属性中,将EGL_RENRERABLE_TYPE
设置为EGL_OPENGL_BIT
In the egl attribs set EGL_RENRERABLE_TYPE
to EGL_OPENGL_BIT
并告诉egl绑定到哪个api:
And tell egl which api to bind to:
eglBindAPI(EGL_OPENGL_API);
确保具有最新的内核驱动程序和mesa-dev
,libdrm-dev
,libgbm-dev
.这些代码可在android上移植,而让默认的android图形堆栈静默起来并不是那么容易.
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.
注意:我在使用32位版本时遇到了麻烦,但仍然不知道为什么.这些库是积极开发的,因此不确定这不是一个错误.
* note2:是否支持浮点精度,具体取决于您的GLSL版本.
*note2: depending on your GLSL version, float precision is supported or not.
precision mediump float;
note3:如果您对/dev/dri/card0
的渗透失败,请授予:
note3: if you have permision failure with /dev/dri/card0
, grant it with:
sudo chmod 666 /dev/dri/card0
或使用
将当前用户添加到video
组
sudo adduser $user video
您也可以为可执行文件设置setguid,并将组设置为video. (也许是最好的选择)
you may also setguid for your executable with group set to video. (maybe best option)
这篇关于如何通过drm创建opengl上下文(Linux)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!