Preliminary X11 backend work
parent
1f6f21489c
commit
b80ec7c47d
|
@ -44,6 +44,10 @@ recrossref
|
|||
"cocoa" get [
|
||||
"/library/cocoa/load.factor" run-resource
|
||||
] when
|
||||
|
||||
"x11" get [
|
||||
"/library/x11/load.factor" run-resource
|
||||
] when
|
||||
] when
|
||||
|
||||
[
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
! Copyright (C) 2005, 2006 Eduardo Cavazos
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
|
||||
! Based on X.h
|
||||
|
||||
USING: alien math ; IN: x11
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
#! based on glx.h from xfree86, and some of glxtokens.h
|
||||
! Copyright (C) 2005, 2006 Eduardo Cavazos
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
!
|
||||
! based on glx.h from xfree86, and some of glxtokens.h
|
||||
IN: x11
|
||||
USING: alien ;
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
! Copyright (C) 2005, 2006 Eduardo Cavazos
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: kernel parser words compiler sequences ;
|
||||
|
||||
{
|
||||
"/library/x11/xlib.factor"
|
||||
"/library/x11/x.factor"
|
||||
"/library/x11/glx.factor"
|
||||
"/library/x11/constants.factor"
|
||||
} [ run-resource ] each
|
||||
|
||||
{ "x11" } [ words [ try-compile ] each ] each
|
||||
{ "x11" } compile-vocabs
|
|
@ -0,0 +1,59 @@
|
|||
USING: kernel math namespaces opengl ;
|
||||
USE: x11
|
||||
|
||||
":0.0" initialize-x
|
||||
|
||||
{ 500 500 0 } create-window
|
||||
dup map-window
|
||||
|
||||
dup StructureNotifyMask select-input
|
||||
|
||||
dup choose-visual create-context make-current
|
||||
|
||||
: init ( -- )
|
||||
0.0 0.0 0.0 0.0 glClearColor GL_FLAT glShadeModel ;
|
||||
|
||||
SYMBOL: pval
|
||||
|
||||
: p pval get ;
|
||||
: -p pval get neg ;
|
||||
|
||||
: wire-cube ( size -- )
|
||||
2.0 / pval set
|
||||
GL_LINE_LOOP glBegin
|
||||
-p -p -p glVertex3f
|
||||
p -p -p glVertex3f
|
||||
p p -p glVertex3f
|
||||
-p p -p glVertex3f
|
||||
glEnd
|
||||
GL_LINE_LOOP glBegin
|
||||
-p -p p glVertex3f
|
||||
p -p p glVertex3f
|
||||
p p p glVertex3f
|
||||
-p p p glVertex3f
|
||||
glEnd
|
||||
GL_LINES glBegin
|
||||
-p -p -p glVertex3f
|
||||
-p -p p glVertex3f
|
||||
p -p -p glVertex3f
|
||||
p -p p glVertex3f
|
||||
-p p -p glVertex3f
|
||||
-p p p glVertex3f
|
||||
p p -p glVertex3f
|
||||
p p p glVertex3f
|
||||
glEnd ;
|
||||
|
||||
: display ( -- )
|
||||
GL_COLOR_BUFFER_BIT glClear
|
||||
1.0 1.0 1.0 glColor3f
|
||||
glLoadIdentity
|
||||
0.0 0.0 5.0 0.0 0.0 0.0 0.0 1.0 0.0 gluLookAt
|
||||
1.0 2.0 1.0 glScalef
|
||||
1.0 wire-cube
|
||||
glFlush ;
|
||||
|
||||
init display
|
||||
|
||||
dup swap-buffers
|
||||
|
||||
flush-dpy
|
|
@ -0,0 +1,79 @@
|
|||
! Copyright (C) 2005, 2006 Eduardo Cavazos and Slava Pestov
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
IN: x11
|
||||
USING: alien arrays errors kernel namespaces sequences ;
|
||||
|
||||
SYMBOL: dpy
|
||||
SYMBOL: scr
|
||||
SYMBOL: root
|
||||
SYMBOL: black-pixel
|
||||
SYMBOL: white-pixel
|
||||
|
||||
! Initialization
|
||||
|
||||
: initialize-x ( display-string -- )
|
||||
XOpenDisplay [ "Cannot connect to X server" throw ] unless*
|
||||
dpy set
|
||||
dpy get XDefaultScreen scr set
|
||||
dpy get scr get XRootWindow root set
|
||||
dpy get scr get XBlackPixel black-pixel set
|
||||
dpy get scr get XWhitePixel white-pixel set ;
|
||||
|
||||
! Window management
|
||||
|
||||
: create-window ( dim -- win )
|
||||
>r dpy get root get 0 0 r> first2
|
||||
0 black-pixel get white-pixel get
|
||||
XCreateSimpleWindow ;
|
||||
|
||||
: destroy-window ( win -- )
|
||||
dpy get swap XDestroyWindow drop ;
|
||||
|
||||
: map-window ( win -- )
|
||||
dpy get swap XMapWindow drop ;
|
||||
|
||||
: map-subwindows ( win -- )
|
||||
dpy get swap XMapSubwindows drop ;
|
||||
|
||||
: unmap-window ( win -- )
|
||||
dpy get swap XUnmapWindow drop ;
|
||||
|
||||
: unmap-subwindows ( win -- )
|
||||
dpy get swap XUnmapSubwindows drop ;
|
||||
|
||||
! Event handling
|
||||
|
||||
: select-input ( win mask -- )
|
||||
>r dpy get swap r> XSelectInput drop ;
|
||||
|
||||
: flush-dpy ( -- ) dpy get XFlush drop ;
|
||||
|
||||
: sync-dpy ( discard -- ) >r dpy get r> XSync ;
|
||||
|
||||
: next-event ( -- event )
|
||||
dpy get "XEvent" <c-object> dup >r XNextEvent drop r> ;
|
||||
|
||||
: mask-event ( mask -- event )
|
||||
>r dpy get r> "XEvent" <c-object> dup >r XMaskEvent drop r> ;
|
||||
|
||||
: events-queued ( mode -- n ) >r dpy get r> XEventsQueued ;
|
||||
|
||||
! GLX
|
||||
|
||||
: >int-array ( seq -- <int-array> )
|
||||
[ length "int" <c-array> ] keep dup length
|
||||
[ pick set-int-nth ] 2each ;
|
||||
|
||||
: choose-visual ( -- XVisualInfo* )
|
||||
dpy get scr get
|
||||
GLX_RGBA GLX_DOUBLEBUFFER 0 3array >int-array
|
||||
glXChooseVisual ;
|
||||
|
||||
: create-context ( XVisualInfo* -- GLXContext )
|
||||
>r dpy get r> f 1 glXCreateContext ;
|
||||
|
||||
: make-current ( win GLXContext -- )
|
||||
>r dpy get swap r> glXMakeCurrent drop ;
|
||||
|
||||
: swap-buffers ( win -- )
|
||||
dpy get swap glXSwapBuffers ;
|
|
@ -1,20 +1,21 @@
|
|||
! Eduardo Cavazos - wayo.cavazos@gmail.com
|
||||
! Copyright (C) 2005, 2006 Eduardo Cavazos
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
!
|
||||
! The most popular guides to programming the X Window System are the
|
||||
! series from Oreilly. For programming with Xlib, there is the
|
||||
! reference manual and the programmers guide. However, a lesser known
|
||||
! manual is the free Xlib manual that comes with the MIT X
|
||||
! distribution. The arrangement and order of these bindings follows
|
||||
! the structure of the free Xlib manual. If you add to this library
|
||||
! and are wondering what part of the file to modify, just find the
|
||||
! function or data structure in the manual and note the section.
|
||||
! The most popular guides to programming the X Window System are
|
||||
! the series from Oreilly. For programming with Xlib, there is
|
||||
! the reference manual and the programmers guide. However, a
|
||||
! lesser known manual is the free Xlib manual that comes with
|
||||
! the MIT X distribution. The arrangement and order of these
|
||||
! bindings follows the structure of the free Xlib manual. If you
|
||||
! add to this library and are wondering what part of the file to
|
||||
! modify, just find the function or data structure in the manual
|
||||
! and note the section.
|
||||
|
||||
USING: kernel arrays alien math words sequences ; IN: x11
|
||||
USING: kernel arrays alien math words sequences ;
|
||||
IN: x11
|
||||
|
||||
LIBRARY: xlib
|
||||
|
||||
"xlib" "libX11.so" "cdecl" add-library
|
||||
|
||||
TYPEDEF: ulong XID
|
||||
TYPEDEF: XID Window
|
||||
TYPEDEF: XID Drawable
|
||||
|
|
Loading…
Reference in New Issue