-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
linux_video FreeGlut handling base example ; added X11 part in video.h
- Loading branch information
Showing
3 changed files
with
82 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,69 @@ | ||
// NOTE: Any system running X11 can be handled by linux_video | ||
|
||
#ifdef __linux__ | ||
|
||
#include "../../../include/video.h" | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
/* X11 */ | ||
|
||
#ifdef __linux__ | ||
|
||
#include <X11/Xlib.h> | ||
|
||
static Display *d; | ||
static Window w; | ||
static XEvent e; | ||
static int s; | ||
static GC gc; | ||
|
||
void createWindow(int width, int height) { | ||
|
||
d = XOpenDisplay(NULL); | ||
w = XCreateSimpleWindow(d, RootWindow(d,s), 0, 0, width, height, 1, | ||
BlackPixel(d,s), WhitePixel(d,s)); | ||
void axCreateWindow(int width, int height) { | ||
d = XOpenDisplay(NULL); | ||
if (d == NULL) { | ||
printf("Cannot open display\n"); | ||
exit(1); | ||
} | ||
|
||
s = DefaultScreen(d); | ||
s = DefaultScreen(d); | ||
w = XCreateSimpleWindow(d, RootWindow(d,s), 0, 0, width, height, 1, | ||
BlackPixel(d,s), WhitePixel(d,s)); | ||
|
||
// Enable key press and expose events | ||
XSelectInput(d, w, KeyPressMask | ExposureMask); | ||
|
||
if (d == NULL) { | ||
printf("Cannot open display"); | ||
exit(1); | ||
} | ||
|
||
XMapWindow(d, w); | ||
XPending(d); | ||
// Create graphics context | ||
gc = DefaultGC(d, s); | ||
|
||
XMapWindow(d, w); | ||
XFlush(d); | ||
} | ||
|
||
void axDrawRect(unsigned long color, int x, int y, int width, int height) { | ||
XSetForeground(d, gc, color); | ||
XFillRectangle(d, w, gc, x, y, width, height); | ||
XFlush(d); | ||
} | ||
|
||
void axClearWindow() { | ||
XClearWindow(d, w); | ||
XFlush(d); | ||
} | ||
|
||
int axGetNextEvent(XEvent *event) { | ||
if (XPending(d)) { | ||
XNextEvent(d, event); | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
void axCloseWindow() { | ||
XCloseDisplay(d); | ||
} | ||
|
||
#endif | ||
|
||
/* FreeGLUT (cross-platform) */ | ||
|
||
|
||
|
||
/* | ||
Copyright (C) 2024 Ellouze Adam <[email protected]> | ||
|