|
|
@@ -114,10 +114,217 @@ int main() {
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
|
|
+#include <GL/glx.h>
|
|
|
+#include <X11/Xlib.h>
|
|
|
+#include <X11/Xutil.h>
|
|
|
+#include <X11/cursorfont.h>
|
|
|
#include <stdio.h>
|
|
|
+#include <unistd.h>
|
|
|
+#include <string.h>
|
|
|
+#include <stdlib.h>
|
|
|
+
|
|
|
+#include "log.h"
|
|
|
+#include "DynString.h"
|
|
|
+
|
|
|
+void print_pixmap_format_values(const XPixmapFormatValues* px) {
|
|
|
+ puts("{");
|
|
|
+ printf(" depth : %d\n", px->depth);
|
|
|
+ printf(" bits_per_pixel: %d\n", px->bits_per_pixel);
|
|
|
+ printf(" scanline_pad : %d\n", px->scanline_pad);
|
|
|
+ puts("}");
|
|
|
+}
|
|
|
+
|
|
|
+void print_visual_info(const XVisualInfo* vi) {
|
|
|
+ puts("{");
|
|
|
+ printf(" visual : %p\n", vi->visual);
|
|
|
+ printf(" visualid : %lu\n", vi->visualid);
|
|
|
+ printf(" screen : %d\n", vi->screen);
|
|
|
+ printf(" depth : %u\n", vi->depth);
|
|
|
+ printf(" class : %d\n", vi->class);
|
|
|
+ printf(" red_mask : %lu\n", vi->red_mask);
|
|
|
+ printf(" green_mask : %lu\n", vi->green_mask);
|
|
|
+ printf(" blue_mask : %lu\n", vi->blue_mask);
|
|
|
+ printf(" colormap_size: %d\n", vi->colormap_size);
|
|
|
+ printf(" bits_per_rgb : %d\n", vi->bits_per_rgb);
|
|
|
+ puts("}");
|
|
|
+}
|
|
|
+
|
|
|
+void print_info(Display* display) {
|
|
|
+ const int screen_num = DefaultScreen(display);
|
|
|
+ Colormap color_map = DefaultColormap(display, screen_num);
|
|
|
+ int default_depth = DefaultDepth(display, screen_num);
|
|
|
+ int depths_count = 0;
|
|
|
+ int* depths = XListDepths(display, screen_num, &depths_count);
|
|
|
+ if (depths == NULL) {
|
|
|
+ LOG_FATAL("XListDepths failed");
|
|
|
+ }
|
|
|
+ int cells = DisplayCells(display, screen_num);
|
|
|
+ int color_depth = DisplayPlanes(display, screen_num);
|
|
|
+ char* display_string = DisplayString(display);
|
|
|
+ int queue_length = QLength(display);
|
|
|
+ int screen_count = ScreenCount(display);
|
|
|
+ char* server_vendor = ServerVendor(display);
|
|
|
+ int vendor_release = VendorRelease(display);
|
|
|
+
|
|
|
+ printf("DefaultScreen : %d\n", screen_num);
|
|
|
+ printf("DefaultColormap: %lu\n", color_map);
|
|
|
+ printf("DefaultDepth : %d\n", default_depth);
|
|
|
+ printf("XListDepths : ");
|
|
|
+ for (int i = 0; i < depths_count; i++) {
|
|
|
+ printf("%d ", depths[i]);
|
|
|
+ }
|
|
|
+ puts("");
|
|
|
+ printf("DisplayCells : %d\n", cells);
|
|
|
+ printf("DisplayPlanes : %d\n", color_depth);
|
|
|
+ printf("DisplayString : %s\n", display_string);
|
|
|
+ printf("QLength : %d\n", queue_length);
|
|
|
+ printf("ScreenCount : %d\n", screen_count);
|
|
|
+ printf("ServerVendor : %s\n", server_vendor);
|
|
|
+ printf("VendorRelease : %d\n", vendor_release);
|
|
|
+
|
|
|
+ XFree(depths);
|
|
|
+
|
|
|
+ int d_supported_pixmap_formats_n = 0;
|
|
|
+ XPixmapFormatValues* d_supported_pixmap_formats = XListPixmapFormats(display, &d_supported_pixmap_formats_n);
|
|
|
+ if (d_supported_pixmap_formats == NULL) {
|
|
|
+ LOG_FATAL("XListPixmapFormats failed");
|
|
|
+ }
|
|
|
+ int img_byte_order = ImageByteOrder(display);
|
|
|
+ int bitmap_unit = XBitmapUnit(display);
|
|
|
+ int bitmap_bit_order = BitmapBitOrder(display);
|
|
|
+ int bitmap_pad = BitmapPad(display);
|
|
|
+ int s_height_px = DisplayHeight(display, screen_num);
|
|
|
+ int s_height_mm = DisplayHeightMM(display, screen_num);
|
|
|
+ int s_width_px = DisplayWidth(display, screen_num);
|
|
|
+ int s_width_mm = DisplayWidthMM(display, screen_num);
|
|
|
+
|
|
|
+ puts("");
|
|
|
+ printf("XListPixmapFormats (%d):\n", d_supported_pixmap_formats_n);
|
|
|
+ for (int i = 0; i < d_supported_pixmap_formats_n; i++) {
|
|
|
+ print_pixmap_format_values(d_supported_pixmap_formats + i);
|
|
|
+ }
|
|
|
+ printf("ImageByteOrder : %s\n", img_byte_order == LSBFirst ? "LSBFirst" : "MSBFirst");
|
|
|
+ printf("XBitmapUnit : %d\n", bitmap_unit);
|
|
|
+ printf("BitmapBitOrder : %s\n", bitmap_bit_order == LSBFirst ? "LSBFirst" : "MSBFirst");
|
|
|
+ printf("BitmapPad : %d\n", bitmap_pad);
|
|
|
+ printf("DisplayHeight (DefaultScreen): %d\n", s_height_px);
|
|
|
+ printf("DisplayHeightMM (DefaultScreen): %d\n", s_height_mm);
|
|
|
+ printf("DisplayWidth (DefaultScreen): %d\n", s_width_px);
|
|
|
+ printf("DisplayWidthMM (DefaultScreen): %d\n", s_width_mm);
|
|
|
+
|
|
|
+ XFree(d_supported_pixmap_formats);
|
|
|
+
|
|
|
+ Screen* screen = ScreenOfDisplay(display, screen_num);
|
|
|
+ unsigned long s_black_pixel = BlackPixelOfScreen(screen);
|
|
|
+ unsigned long s_white_pixel = WhitePixelOfScreen(screen);
|
|
|
+ int s_cells = CellsOfScreen(screen);
|
|
|
+ int s_default_depth = DefaultDepthOfScreen(screen);
|
|
|
+ int does_backing_store = DoesBackingStore(screen);
|
|
|
+ bool does_save_unders = DoesSaveUnders(screen);
|
|
|
+ int s_max_colormaps = MaxCmapsOfScreen(screen);
|
|
|
+ int s_min_colormaps = MinCmapsOfScreen(screen);
|
|
|
+ int s_planes_n = PlanesOfScreen(screen);
|
|
|
+
|
|
|
+ puts("\n(Default Screen)");
|
|
|
+ printf("BlackPixelOfScreen : %lu\n", s_black_pixel);
|
|
|
+ printf("WhitePixelOfScreen : %lu\n", s_white_pixel);
|
|
|
+ printf("CellsOfScreen : %d\n", s_cells);
|
|
|
+ printf("DefaultDepthOfScreen: %d\n", s_default_depth);
|
|
|
+ printf("DoesBackingStore : %s\n", does_backing_store == WhenMapped ? "WhenMapped" : (does_backing_store == NotUseful ? "NotUseful" : "Always"));
|
|
|
+ printf("DoesSaveUnders : %s\n", does_save_unders ? "true" : "false");
|
|
|
+ printf("MaxCmapsOfScreen : %d\n", s_max_colormaps);
|
|
|
+ printf("MinCmapsOfScreen : %d\n", s_min_colormaps);
|
|
|
+ printf("PlanesOfScreen : %d\n", s_planes_n);
|
|
|
+ puts("");
|
|
|
+}
|
|
|
|
|
|
int main() {
|
|
|
- printf("Hello linux\n");
|
|
|
+ Display* display = XOpenDisplay(NULL);
|
|
|
+ if (display == NULL) {
|
|
|
+ LOG_FATAL("XOpenDisplay failed.");
|
|
|
+ }
|
|
|
+
|
|
|
+ int err_base = 0;
|
|
|
+ int event_base = 0;
|
|
|
+ if (!glXQueryExtension(display, &err_base, &event_base)) {
|
|
|
+ LOG_FATALF(
|
|
|
+ "GLX extension not supported. err_base: %d, event_base: %d",
|
|
|
+ err_base,
|
|
|
+ event_base
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ int glx_major = 0;
|
|
|
+ int glx_minor = 0;
|
|
|
+ if (glXQueryVersion(display, &glx_major, &glx_minor)) {
|
|
|
+ printf("GLX Version %d.%d\n", glx_major, glx_minor);
|
|
|
+ if (glx_minor < 1) {
|
|
|
+ LOG_FATAL("GLX Version must be at least 1.1");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ LOG_ERROR("glXQueryVersion failed");
|
|
|
+ }
|
|
|
+
|
|
|
+ const char* glx_extensions_c_str = glXQueryExtensionsString(display, DefaultScreen(display));
|
|
|
+ printf("glx_extensions_c_str: %s\n", glx_extensions_c_str);
|
|
|
+ DynString glx_extensions_str = DynString_alloc(glx_extensions_c_str, strlen(glx_extensions_c_str));
|
|
|
+ size_t glx_ext_n = 0;
|
|
|
+ DynString* glx_extensions = DynString_split(&glx_extensions_str, " ", &glx_ext_n);
|
|
|
+
|
|
|
+ printf("GLX extensions:\n");
|
|
|
+ for (size_t i = 0; i < glx_ext_n; i++) {
|
|
|
+ printf(" %s\n", DynString_c_str(glx_extensions + i));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // XVisualInfo visual_info = { 0 };
|
|
|
+ // Status xstatus = XMatchVisualInfo(display, DefaultScreen(display), 32, TrueColor, &visual_info);
|
|
|
+ // if (xstatus == 0) {
|
|
|
+ // LOG_FATAL("XMatchVisualInfo failed");
|
|
|
+ // }
|
|
|
+ // printf("Matched visual:\n");
|
|
|
+ // print_visual_info(&visual_info);
|
|
|
+ //
|
|
|
+ // Cursor cursor = XCreateFontCursor(display, XC_iron_cross);
|
|
|
+ // XSetWindowAttributes win_attr = {
|
|
|
+ // .background_pixel = 0x00000000,
|
|
|
+ // .border_pixel = 0xFF000000,
|
|
|
+ // .colormap = XCreateColormap(display, DefaultRootWindow(display), visual_info.visual, AllocNone),
|
|
|
+ // .event_mask = Expose,
|
|
|
+ // .backing_store = WhenMapped,
|
|
|
+ // .cursor = cursor,
|
|
|
+ // };
|
|
|
+ //
|
|
|
+ // Window window = XCreateWindow(
|
|
|
+ // display,
|
|
|
+ // DefaultRootWindow(display),
|
|
|
+ // 0,
|
|
|
+ // 0,
|
|
|
+ // PLTF_DEFAULT_WINDOW_WIDTH,
|
|
|
+ // PLTF_DEFAULT_WINDOW_HEIGHT,
|
|
|
+ // 0,
|
|
|
+ // visual_info.depth,
|
|
|
+ // InputOutput,
|
|
|
+ // visual_info.visual,
|
|
|
+ // CWBackPixel |
|
|
|
+ // CWBorderPixel |
|
|
|
+ // CWColormap |
|
|
|
+ // CWEventMask |
|
|
|
+ // CWBackingStore |
|
|
|
+ // CWCursor,
|
|
|
+ // &win_attr
|
|
|
+ // );
|
|
|
+ //
|
|
|
+ // XMapWindow(display, window);
|
|
|
+ //
|
|
|
+ // XFlush(display);
|
|
|
+ //
|
|
|
+ // pause();
|
|
|
+ //
|
|
|
+ // XDestroyWindow(display, window);
|
|
|
+
|
|
|
+ XCloseDisplay(display);
|
|
|
+
|
|
|
return 0;
|
|
|
}
|
|
|
|