Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a window's pixel format on GLFW in linux

Tags:

c++

glfw

I want to get a GLFW window's pixel format. I'm using ubuntu so win32 functions are out of the picture. I've stumbled upon this question but there are only win32 answers and there is an answer that uses HDC and PIXELFORMATDESCRIPTOR which I don't have access to (Since I will not be using the function permanently I rather not install a new library for this.)

I want to get the format in the form of YUV420P or RGB24.

like image 843
Turgut Avatar asked Oct 13 '25 07:10

Turgut


1 Answers

Conceptually the closest thing to a pixelformat in X11 is a so called Visual (X11 core) or FBConfig (through GLX extension).

First you need the native window handle. You can retrieve this from GLFW using

Window x11win = glfwGetX11Window(glfwwin);

A window's visual can be queried using XGetWindowAttributes

XWindowAttributs winattr;
XGetWindowAttributes(display, x11win, &winattr);
// winattr->visual
// use it to query a XVisualInfo which can then be
// passed to glXGetConfig

The FBConfig can be queried using glXQueryDrawable

unsigned fbconfigid;
glXQueryDrawable(display, x11win, GLX_FBCONFIG_ID, &fbconfigid);

unsigned n_fbconfigs;
GLXFBConfig glxfbconfigs = glXGetFBConfigs(display, screen, &n_fbconfigs);

if( fbconfigid >= n_fbconfigs ){ raise_error(...); }

int attribute_value;
glXGetFBConfigAttrib(display, glxfbconfigs[fbconfigid], GLX_…, &attribute_value);

XFree(fbconfigs);
like image 74
datenwolf Avatar answered Oct 14 '25 21:10

datenwolf