File: XScreenSaver.xs

package info (click to toggle)
libopengl-xscreensaver-perl 0.05-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, stretch
  • size: 120 kB
  • ctags: 15
  • sloc: perl: 318; makefile: 2
file content (74 lines) | stat: -rw-r--r-- 1,294 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#include <X11/Xlib.h>
#include <GL/glx.h>

static Display *dpy = 0;
static Window win;
static XVisualInfo *vi;
static GLXContext cx;

MODULE = OpenGL::XScreenSaver          PACKAGE = OpenGL::XScreenSaver

PROTOTYPES: DISABLE

int
xss_connect()
	CODE:
		if (!dpy)
			dpy = XOpenDisplay(0);

		if (!dpy) {
			XSRETURN_NO;
		} else {
			XSRETURN_YES;
		}

int
xss_init_gl(wid)
	int wid
	CODE:
		win = wid;

		vi = glXChooseVisual(dpy, DefaultScreen(dpy), (int[]){ GLX_RGBA, GLX_DOUBLEBUFFER, None });
		cx = glXCreateContext(dpy, vi, 0, GL_TRUE);

		if (!win) {
			win = XCreateSimpleWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 640, 480, 0, 0, 0);
			XMapWindow(dpy, win);
		}

		glXMakeCurrent(dpy, win, cx);

		XSRETURN_YES;

void
xss_update_frame()
	CODE:
		glXSwapBuffers(dpy, win);

void
xss_update_viewport()
	CODE:
		XWindowAttributes xwa;
		XGetWindowAttributes(dpy, win, &xwa);
		glXMakeCurrent(dpy, win, cx);
		glViewport(0, 0, xwa.width, xwa.height);

int
xss_root_window()
	CODE:
		RETVAL = DefaultRootWindow(dpy);
	OUTPUT:
		RETVAL

void
xss_viewport_dimensions()
	PPCODE:
		XWindowAttributes xwa;
		XGetWindowAttributes(dpy, win, &xwa);
		XPUSHs(sv_2mortal(newSVnv(xwa.width)));
		XPUSHs(sv_2mortal(newSVnv(xwa.height)));