Preliminary X11 backend work

slava 2006-03-20 00:37:01 +00:00
parent 1f6f21489c
commit b80ec7c47d
7 changed files with 165 additions and 15 deletions

View File

@ -44,6 +44,10 @@ recrossref
"cocoa" get [ "cocoa" get [
"/library/cocoa/load.factor" run-resource "/library/cocoa/load.factor" run-resource
] when ] when
"x11" get [
"/library/x11/load.factor" run-resource
] when
] when ] when
[ [

View File

@ -1,3 +1,6 @@
! Copyright (C) 2005, 2006 Eduardo Cavazos
! See http://factorcode.org/license.txt for BSD license.
! Based on X.h ! Based on X.h
USING: alien math ; IN: x11 USING: alien math ; IN: x11

View File

@ -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 IN: x11
USING: alien ; USING: alien ;

View File

@ -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 ; USING: kernel parser words compiler sequences ;
{ {
"/library/x11/xlib.factor" "/library/x11/xlib.factor"
"/library/x11/x.factor"
"/library/x11/glx.factor" "/library/x11/glx.factor"
"/library/x11/constants.factor" "/library/x11/constants.factor"
} [ run-resource ] each } [ run-resource ] each
{ "x11" } [ words [ try-compile ] each ] each { "x11" } compile-vocabs

59
library/x11/ui.factor Normal file
View File

@ -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

View File

@ -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 ;

View File

@ -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 ! The most popular guides to programming the X Window System are
! series from Oreilly. For programming with Xlib, there is the ! the series from Oreilly. For programming with Xlib, there is
! reference manual and the programmers guide. However, a lesser known ! the reference manual and the programmers guide. However, a
! manual is the free Xlib manual that comes with the MIT X ! lesser known manual is the free Xlib manual that comes with
! distribution. The arrangement and order of these bindings follows ! the MIT X distribution. The arrangement and order of these
! the structure of the free Xlib manual. If you add to this library ! bindings follows the structure of the free Xlib manual. If you
! and are wondering what part of the file to modify, just find the ! add to this library and are wondering what part of the file to
! function or data structure in the manual and note the section. ! 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 LIBRARY: xlib
"xlib" "libX11.so" "cdecl" add-library
TYPEDEF: ulong XID TYPEDEF: ulong XID
TYPEDEF: XID Window TYPEDEF: XID Window
TYPEDEF: XID Drawable TYPEDEF: XID Drawable