Changeset 3547 in project


Ignore:
Timestamp:
03/20/07 17:16:22 (14 years ago)
Author:
thu
Message:

commit before removal of non gl-display files

Location:
gl-display-glx
Files:
1 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • gl-display-glx/TODO

    r3343 r3547  
    99- clean source code from use/require/etc
    1010- use finalizers (register a feature when the code uses finalizers?)
     11- use foreign-parse for some wrapping (it's done by hand atm.).
    1112
    1213- event queue
     
    5253- graphical representation of list...
    5354- pos and evo :)
     55
     56- documentation : define-foreign-enum is used with a long list of symbols in
     57  gl-dislay-glx.scm, thus needing libffi.
  • gl-display-glx/gl-display-events-util.scm

    r3343 r3547  
    2424(define (write-event e)
    2525  (case (car e)
    26     ((KEY-PRESSED)     (print "key pressed " (gl-display:event-key e)))
    27     ((KEY-RELEASED)    (print "key released " (gl-display:event-key e)))
     26    ((KEY-PRESSED)     (print "key pressed " (gl-display:event-keycode e)))
     27    ((KEY-RELEASED)    (print "key released " (gl-display:event-keycode e)))
    2828    ((BUTTON-PRESSED)  (print "button pressed"))
    2929    ((BUTTON-RELEASED) (print "button released"))
     
    7979(define (escape-key-released? event)
    8080  (and (key-released? event)
    81        (eqv? #\esc (gl-display:event-key event))))
     81       (eqv? #\esc (gl-display:event-keycode event))))
    8282
    8383(define (up-key-released? event)
    8484  (and (key-released? event)
    85        (eqv? 'UP-KEY (gl-display:event-key event))))
     85       (eqv? 'UP-KEY (gl-display:event-keycode event))))
    8686(define (up-key-pressed? event)
    8787  (and (key-pressed? event)
    88        (eqv? 'UP-KEY (gl-display:event-key event))))
     88       (eqv? 'UP-KEY (gl-display:event-keycode event))))
    8989(define (down-key-released? event)
    9090  (and (key-released? event)
    91        (eqv? 'DOWN-KEY (gl-display:event-key event))))
     91       (eqv? 'DOWN-KEY (gl-display:event-keycode event))))
    9292(define (down-key-pressed? event)
    9393  (and (key-pressed? event)
    94        (eqv? 'DOWN-KEY (gl-display:event-key event))))
     94       (eqv? 'DOWN-KEY (gl-display:event-keycode event))))
    9595(define (left-key-released? event)
    9696  (and (key-released? event)
    97        (eqv? 'LEFT-KEY (gl-display:event-key event))))
     97       (eqv? 'LEFT-KEY (gl-display:event-keycode event))))
    9898(define (left-key-pressed? event)
    9999  (and (key-pressed? event)
    100        (eqv? 'LEFT-KEY (gl-display:event-key event))))
     100       (eqv? 'LEFT-KEY (gl-display:event-keycode event))))
    101101(define (right-key-released? event)
    102102  (and (key-released? event)
    103        (eqv? 'RIGHT-KEY (gl-display:event-key event))))
     103       (eqv? 'RIGHT-KEY (gl-display:event-keycode event))))
    104104(define (right-key-pressed? event)
    105105  (and (key-pressed? event)
    106        (eqv? 'RIGHT-KEY (gl-display:event-key event))))
     106       (eqv? 'RIGHT-KEY (gl-display:event-keycode event))))
    107107
    108108(define (space-key-released? event)
    109109  (and (key-released? event)
    110        (eqv? #\space (gl-display:event-key event))))
     110       (eqv? #\space (gl-display:event-keycode event))))
    111111(define (space-key-pressed? event)
    112112  (and (key-pressed? event)
    113        (eqv? #\space (gl-display:event-key event))))
     113       (eqv? #\space (gl-display:event-keycode event))))
    114114
    115115(define (lmb-released? event)
    116116  (and (button-released? event)
    117        (eqv? 'LMB (gl-display:event-key event))))
     117       (eqv? 'LMB (gl-display:event-keycode event))))
    118118(define (lmb-pressed? event)
    119119  (and (button-pressed? event)
    120        (eqv? 'LMB (gl-display:event-key event))))
     120       (eqv? 'LMB (gl-display:event-keycode event))))
  • gl-display-glx/gl-display-glx.scm

    r3343 r3547  
    2626    gl-display:event-x
    2727    gl-display:event-y
     28    gl-display:event-dx
     29    gl-display:event-dy
    2830    gl-display:event-time
    29     gl-display:event-key
     31    gl-display:event-keycode
     32    gl-display:event-keysym
    3033    gl-display:width
    3134    gl-display:height
     
    3437    gl-display:enable-autorepeat
    3538    gl-display:disable-autorepeat
     39    gl-display:disable-cursor
     40    gl-display:enable-centered-cursor
     41    gl-display:disable-centered-cursor
     42    gl-display:enable-cycling-cursor
     43    gl-display:disable-cycling-cursor
    3644    )
    3745  )
     
    4654#include <keysym.h>
    4755<#
     56
     57
     58(define-foreign-enum (keycode_t (enum "keycode_t"))
     59  K_BACKSPACE
     60  K_TAB
     61  K_ENTER
     62  K_ESCAPE
     63
     64  K_SPACE
     65  K_EXCLAM
     66  K_DOUBLE_QUOTE
     67  K_NUMBER_SIGNE
     68  K_DOLLAR
     69  K_PERCENT
     70  K_AMPERSAND
     71  K_APOSTROPHE
     72  K_LEFT_PAREN
     73  K_RIGHT_PAREN
     74  K_ASTERISK
     75  K_PLUS
     76  K_COMMA
     77  K_MINUS
     78  K_PERIOD
     79  K_SLASH
     80  K_0
     81  K_1
     82  K_2
     83  K_3
     84  K_4
     85  K_5
     86  K_6
     87  K_7
     88  K_8
     89  K_9
     90  K_COLON
     91  K_SEMICOLON
     92  K_LESS
     93  K_EQUAL
     94  K_GREATER
     95  K_QUESTION
     96  K_AT
     97  K_A
     98  K_B
     99  K_C
     100  K_D
     101  K_E
     102  K_F
     103  K_G
     104  K_H
     105  K_I
     106  K_J
     107  K_K
     108  K_L
     109  K_M
     110  K_N
     111  K_O
     112  K_P
     113  K_Q
     114  K_R
     115  K_S
     116  K_T
     117  K_U
     118  K_V
     119  K_W
     120  K_X
     121  K_Y
     122  K_Z
     123  K_LEFT_BRACKET
     124  K_BACKSLASH
     125  K_RIGHT_BRACKET
     126  K_ASCII_CIRCUM
     127  K_UNDERSCORE
     128  K_GRAVE
     129  K_a
     130  K_b
     131  K_c
     132  K_d
     133  K_e
     134  K_f
     135  K_g
     136  K_h
     137  K_i
     138  K_j
     139  K_k
     140  K_l
     141  K_m
     142  K_n
     143  K_o
     144  K_p
     145  K_q
     146  K_r
     147  K_s
     148  K_t
     149  K_u
     150  K_v
     151  K_w
     152  K_x
     153  K_y
     154  K_z
     155  K_LEFT_BRACE
     156  K_BAR
     157  K_RIGHT_BRACE
     158  K_ASCII_TILDE
     159
     160  K_COMMAND
     161  K_CAPSLOCK
     162  K_POWER
     163  K_PAUSE
     164
     165  K_UP_ARROW
     166  K_DOWN_ARROW
     167  K_LEFT_ARROW
     168  K_RIGHT_ARROW
     169
     170  K_LEFT_ALT
     171  K_RIGHT_ALT
     172  K_LEFT_CONTROL
     173  K_RIGHT_CONTROL
     174  K_LEFT_SHIFT
     175  K_RIGHT_SHIFT
     176  K_INSERT
     177  K_DELETE
     178  K_PAGE_DOWN
     179  K_PAGE_UP
     180  K_HOME
     181  K_END
     182
     183  K_F1
     184  K_F2
     185  K_F3
     186  K_F4
     187  K_F5
     188  K_F6
     189  K_F7
     190  K_F8
     191  K_F9
     192  K_F10
     193  K_F11
     194  K_F12
     195  K_F13
     196  K_F14
     197  K_F15
     198
     199  K_KP_HOME
     200  K_KP_UP_ARROW
     201  K_KP_PAGE_UP
     202  K_KP_LEFT_ARROW
     203  K_KP_5
     204  K_KP_RIGHT_ARROW
     205  K_KP_END
     206  K_KP_DOWN_ARROW
     207  K_KP_PAGE_DOWN
     208  K_KP_ENTER
     209  K_KP_INSERT
     210  K_KP_DELETE
     211  K_KP_SLASH
     212  K_KP_MINUS
     213  K_KP_PLUS
     214  K_KP_NUMLOCK
     215  K_KP_STAR
     216  K_KP_EQUALS
     217
     218  K_MOUSE1
     219  K_MOUSE2
     220  K_MOUSE3
     221  K_MOUSE4
     222  K_MOUSE5
     223
     224  K_WHEEL_DOWN
     225  K_WHEEL_UP
     226
     227  K_LAST_KEY
     228)
    48229
    49230; don't export this
     
    60241(define NO-EVENT        (+ LAST-EVENT 1))
    61242
    62 (define ESCAPE-KEY    (foreign-value "XK_Escape" int))
    63 (define RETURN-KEY    (foreign-value "XK_Return" int))
    64 (define BACKSPACE-KEY (foreign-value "XK_BackSpace" int))
    65 
    66 (define UP-KEY     (foreign-value "XK_Up"     int))
    67 (define DOWN-KEY   (foreign-value "XK_Down"   int))
    68 (define LEFT-KEY   (foreign-value "XK_Left"   int))
    69 (define RIGHT-KEY  (foreign-value "XK_Right"  int))
     243;(define ESCAPE-KEY    (foreign-value "XK_Escape" int))
     244;(define RETURN-KEY    (foreign-value "XK_Return" int))
     245;(define BACKSPACE-KEY (foreign-value "XK_BackSpace" int))
     246
     247;(define UP-KEY     (foreign-value "XK_Up"     int))
     248;(define DOWN-KEY   (foreign-value "XK_Down"   int))
     249;(define LEFT-KEY   (foreign-value "XK_Left"   int))
     250;(define RIGHT-KEY  (foreign-value "XK_Right"  int))
    70251
    71252(define LEFT-MOUSE-BUTTON  (foreign-value "Button1"    int))
     
    80261(define x-event-y
    81262  (foreign-lambda int "event_y" c-pointer))
    82 (define (x-event-key event)
    83   (define event-keycode
    84     (foreign-lambda int "event_keycode" c-pointer))
    85   (let ((k (event-keycode event)))
    86     (cond ((eq? k ESCAPE-KEY) #\esc)
    87           ((eq? k RETURN-KEY) #\return)
    88           ((eq? k BACKSPACE-KEY) #\backspace)
    89           ((eq? k UP-KEY)     'UP-KEY)
    90           ((eq? k DOWN-KEY)   'DOWN-KEY)
    91           ((eq? k LEFT-KEY)   'LEFT-KEY)
    92           ((eq? k RIGHT-KEY)  'RIGHT-KEY)
    93           (else (integer->char k)))))
     263(define x-event-dx
     264  (foreign-lambda int "event_dx" c-pointer))
     265(define x-event-dy
     266  (foreign-lambda int "event_dy" c-pointer))
     267
     268(define x-event-keycode
     269  (foreign-lambda keycode_t "event_keycode" c-pointer))
     270(define x-event-keysym
     271  (foreign-lambda unsigned-int "event_keysym" c-pointer))
     272
     273;(define (x-event-key event)
     274;  (define event-xkeycode
     275;    (foreign-lambda int "event_xkeycode" c-pointer))
     276;  (let ((k (event-xkeycode event)))
     277;    (cond ((eq? k ESCAPE-KEY) #\esc)
     278;         ((eq? k RETURN-KEY) #\return)
     279;         ((eq? k BACKSPACE-KEY) #\backspace)
     280;         ((eq? k UP-KEY)     'UP-KEY)
     281;         ((eq? k DOWN-KEY)   'DOWN-KEY)
     282;         ((eq? k LEFT-KEY)   'LEFT-KEY)
     283;         ((eq? k RIGHT-KEY)  'RIGHT-KEY)
     284;         (else (integer->char k)))))
     285
     286; TODO x-event-char for unicode character instead of keycode.
    94287
    95288(define (x-event-button event)
     
    101294          (else 'MMB))))
    102295
     296(define (keysym->char i)
     297  (integer->char i))
     298
    103299; returns an event from xlib
    104300(define (gl-display:receive-event window)
     
    108304         (type (x-event-type e))
    109305         (time (gl-display:time)))
    110     (cond ((eq? type KEY-PRESSED)     (list 'KEY-PRESSED time (x-event-key e)))
    111           ((eq? type KEY-RELEASED)    (list 'KEY-RELEASED time (x-event-key e)))
     306    (cond ((eq? type KEY-PRESSED)     (list 'KEY-PRESSED time (x-event-keycode e) (keysym->char (x-event-keysym e))))
     307          ((eq? type KEY-RELEASED)    (list 'KEY-RELEASED time (x-event-keycode e) (keysym->char (x-event-keysym e))))
    112308          ((eq? type BUTTON-PRESSED)  (list 'BUTTON-PRESSED time (x-event-button e) (x-event-x e) (x-event-y e)))
    113309          ((eq? type BUTTON-RELEASED) (list 'BUTTON-RELEASED time (x-event-button e) (x-event-x e) (x-event-y e)))
    114           ((eq? type MOUSE-MOVED)     (list 'MOUSE-MOVED time 'dummy (x-event-x e) (x-event-y e))) ; TODO add delta
     310          ((eq? type MOUSE-MOVED)     (list 'MOUSE-MOVED time 'dummy
     311                                            (x-event-x e) (x-event-y e) (x-event-dx window) (x-event-dy window)))
    115312          ((eq? type NO-EVENT)        (list 'NO-EVENT))
    116313          (else                       (gl-display:receive-event window))))) ; pump and discard all other events
     
    123320(define (gl-display:event-y event)
    124321  (fifth event))
     322(define (gl-display:event-dx event)
     323  (sixth event))
     324(define (gl-display:event-dy event)
     325  (seventh event))
    125326
    126327(define (gl-display:event-time event)
    127328  (cadr event))
    128329
    129 (define (gl-display:event-key event)
     330(define (gl-display:event-keycode event)
    130331  (caddr event))
    131332
     333(define (gl-display:event-keysym event)
     334  (cadddr event))
    132335
    133336;
     337(define gl-display:disable-cursor
     338  (foreign-lambda void "disable_cursor" c-pointer))
    134339
    135340; puts the back-buffer content into the front-buffer.
     
    150355(define gl-display:disable-autorepeat
    151356  (foreign-lambda void "disable_autorepeat" c-pointer))
     357(define gl-display:enable-centered-cursor
     358  (foreign-lambda void "enable_centered_cursor" c-pointer))
     359(define gl-display:disable-centered-cursor
     360  (foreign-lambda void "disable_centered_cursor" c-pointer))
     361(define gl-display:enable-cycling-cursor
     362  (foreign-lambda void "enable_cycling_cursor" c-pointer))
     363(define gl-display:disable-cycling-cursor
     364  (foreign-lambda void "disable_cycling_cursor" c-pointer))
    152365
    153366; An optional list of properties can be provided.
  • gl-display-glx/gl-display-glx.setup

    r3309 r3547  
    1313 '("gl-display-glx.so")
    1414 '((version 0.1)
    15    (documentation "gl-display-glx.html")))
     15   ))
    1616
  • gl-display-glx/gl-proj.scm

    r3343 r3547  
    4646  ; Q: is it normal that I have to use height-1 and -1, and not height and 0 ?
    4747  ; Maybe 0.375 as in blender ? I think there's a discussion about this in the red book
    48 ;    (gl:Ortho 0 w (- h 1) -1 -1 1)
    49     (gl:Ortho (- (/ w 2)) (/ w 2) (- (/ h 2)) (/ h 2) -4 4)
     48;    (gl:Ortho 0 w (- h 1) -1 -4 4) ; y goes up
     49    (gl:Ortho 0 w 0 h -4 4)         ; y goes down
     50;    (gl:Ortho (- (/ w 2)) (/ w 2) (- (/ h 2)) (/ h 2) -4 4) ; 0/0 at center
    5051;    (gl:Ortho *xmin* *xmax* *ymin* *ymax* -1 1)
    5152    (gl:MatrixMode gl:MODELVIEW)
  • gl-display-glx/gl-util.scm

    r3343 r3547  
    3434              (lambda rest
    3535                `(in-mode gl:LINES ,@rest)))
     36(define-macro emit-line-loop
     37              (lambda rest
     38                `(in-mode gl:LINE_LOOP ,@rest)))
     39(define-macro emit-triangle-fan
     40              (lambda rest
     41                `(in-mode gl:TRIANGLE_FAN ,@rest)))
    3642;
    3743; One usefull event processing abstraction is related to
     
    109115    (vertex size 0 0)
    110116
    111     (gl:Color3f 0 0 1) ; y
     117    (gl:Color3f 0 1 0) ; y
    112118    (vertex 0 0 0)
    113119    (vertex 0 size 0)
    114120
    115     (gl:Color3f 0 1 0) ; z
     121    (gl:Color3f 0 0 1) ; z
    116122    (vertex 0 0 0)
    117     (vertex 0 0 size)))
     123    (vertex 0 0 size))
     124
     125  (gl:Color3f 1 0 0)
     126  (gl-util:8-sides-cone-x (/ size 10) (/ size 2) size)
     127  (gl:Color3f 0 1 0)
     128  (gl-util:8-sides-cone-y (/ size 10) (/ size 2) size)
     129  (gl:Color3f 0 0 1)
     130  (gl-util:8-sides-cone-z (/ size 10) (/ size 2) size)
     131  )
     132
     133(define (gl-util:cursor-3d size x y z)
     134  (emit-lines
     135    (gl:Color3f 0.2 0.1 1)
     136   
     137    (vertex x y z)
     138    (vertex (- x size) y z)
     139
     140    (vertex x y z)
     141    (vertex x (- y size) z)
     142
     143    (vertex x y z)
     144    (vertex x y (- z size))))
     145
     146(define (gl-util:8-sides-cone-x radius len offset)
     147  (emit-triangle-fan
     148    (gl:Vertex2f offset 0)
     149    (gl:Vertex3f offset (* (cos 0.000000) radius) (* (sin 0.000000) radius))
     150    (gl:Vertex3f offset (* (cos 0.785398) radius) (* (sin 0.785398) radius))
     151    (gl:Vertex3f offset (* (cos 1.570796) radius) (* (sin 1.570796) radius))
     152    (gl:Vertex3f offset (* (cos 2.356194) radius) (* (sin 2.356194) radius))
     153    (gl:Vertex3f offset (* (cos 3.141593) radius) (* (sin 3.141593) radius))
     154    (gl:Vertex3f offset (* (cos 3.926991) radius) (* (sin 3.926991) radius))
     155    (gl:Vertex3f offset (* (cos 4.712389) radius) (* (sin 4.712389) radius))
     156    (gl:Vertex3f offset (* (cos 5.497787) radius) (* (sin 5.497787) radius))
     157    (gl:Vertex3f offset (* (cos 0.000000) radius) (* (sin 0.000000) radius)))
     158  (emit-triangle-fan
     159    (gl:Vertex3f (+ offset len) 0 0)
     160    (gl:Vertex3f offset (* (cos 0.000000) radius) (* (sin 0.000000) radius))
     161    (gl:Vertex3f offset (* (cos 5.497787) radius) (* (sin 5.497787) radius))
     162    (gl:Vertex3f offset (* (cos 4.712389) radius) (* (sin 4.712389) radius))
     163    (gl:Vertex3f offset (* (cos 3.926991) radius) (* (sin 3.926991) radius))
     164    (gl:Vertex3f offset (* (cos 3.141593) radius) (* (sin 3.141593) radius))
     165    (gl:Vertex3f offset (* (cos 2.356194) radius) (* (sin 2.356194) radius))
     166    (gl:Vertex3f offset (* (cos 1.570796) radius) (* (sin 1.570796) radius))
     167    (gl:Vertex3f offset (* (cos 0.785398) radius) (* (sin 0.785398) radius))
     168    (gl:Vertex3f offset (* (cos 0.000000) radius) (* (sin 0.000000) radius))))
     169(define (gl-util:8-sides-cone-y radius len offset)
     170  (emit-triangle-fan
     171    (gl:Vertex2f 0 offset)
     172    (gl:Vertex3f (* (cos 0.000000) radius) offset (* (sin 0.000000) radius))
     173    (gl:Vertex3f (* (cos 0.785398) radius) offset (* (sin 0.785398) radius))
     174    (gl:Vertex3f (* (cos 1.570796) radius) offset (* (sin 1.570796) radius))
     175    (gl:Vertex3f (* (cos 2.356194) radius) offset (* (sin 2.356194) radius))
     176    (gl:Vertex3f (* (cos 3.141593) radius) offset (* (sin 3.141593) radius))
     177    (gl:Vertex3f (* (cos 3.926991) radius) offset (* (sin 3.926991) radius))
     178    (gl:Vertex3f (* (cos 4.712389) radius) offset (* (sin 4.712389) radius))
     179    (gl:Vertex3f (* (cos 5.497787) radius) offset (* (sin 5.497787) radius))
     180    (gl:Vertex3f (* (cos 0.000000) radius) offset (* (sin 0.000000) radius)))
     181  (emit-triangle-fan
     182    (gl:Vertex3f 0 (+ offset len) 0)
     183    (gl:Vertex3f (* (cos 0.000000) radius) offset (* (sin 0.000000) radius))
     184    (gl:Vertex3f (* (cos 5.497787) radius) offset (* (sin 5.497787) radius))
     185    (gl:Vertex3f (* (cos 4.712389) radius) offset (* (sin 4.712389) radius))
     186    (gl:Vertex3f (* (cos 3.926991) radius) offset (* (sin 3.926991) radius))
     187    (gl:Vertex3f (* (cos 3.141593) radius) offset (* (sin 3.141593) radius))
     188    (gl:Vertex3f (* (cos 2.356194) radius) offset (* (sin 2.356194) radius))
     189    (gl:Vertex3f (* (cos 1.570796) radius) offset (* (sin 1.570796) radius))
     190    (gl:Vertex3f (* (cos 0.785398) radius) offset (* (sin 0.785398) radius))
     191    (gl:Vertex3f (* (cos 0.000000) radius) offset (* (sin 0.000000) radius))))
     192(define (gl-util:8-sides-cone-z radius len offset)
     193  (emit-triangle-fan
     194    (gl:Vertex3f 0 0 offset)
     195    (gl:Vertex3f (* (cos 0.000000) radius) (* (sin 0.000000) radius) offset)
     196    (gl:Vertex3f (* (cos 0.785398) radius) (* (sin 0.785398) radius) offset)
     197    (gl:Vertex3f (* (cos 1.570796) radius) (* (sin 1.570796) radius) offset)
     198    (gl:Vertex3f (* (cos 2.356194) radius) (* (sin 2.356194) radius) offset)
     199    (gl:Vertex3f (* (cos 3.141593) radius) (* (sin 3.141593) radius) offset)
     200    (gl:Vertex3f (* (cos 3.926991) radius) (* (sin 3.926991) radius) offset)
     201    (gl:Vertex3f (* (cos 4.712389) radius) (* (sin 4.712389) radius) offset)
     202    (gl:Vertex3f (* (cos 5.497787) radius) (* (sin 5.497787) radius) offset)
     203    (gl:Vertex3f (* (cos 0.000000) radius) (* (sin 0.000000) radius) offset))
     204  (emit-triangle-fan
     205    (gl:Vertex3f 0 0 (+ offset len))
     206    (gl:Vertex3f (* (cos 0.000000) radius) (* (sin 0.000000) radius) offset)
     207    (gl:Vertex3f (* (cos 5.497787) radius) (* (sin 5.497787) radius) offset)
     208    (gl:Vertex3f (* (cos 4.712389) radius) (* (sin 4.712389) radius) offset)
     209    (gl:Vertex3f (* (cos 3.926991) radius) (* (sin 3.926991) radius) offset)
     210    (gl:Vertex3f (* (cos 3.141593) radius) (* (sin 3.141593) radius) offset)
     211    (gl:Vertex3f (* (cos 2.356194) radius) (* (sin 2.356194) radius) offset)
     212    (gl:Vertex3f (* (cos 1.570796) radius) (* (sin 1.570796) radius) offset)
     213    (gl:Vertex3f (* (cos 0.785398) radius) (* (sin 0.785398) radius) offset)
     214    (gl:Vertex3f (* (cos 0.000000) radius) (* (sin 0.000000) radius) offset)))
    118215
    119216; Draw a grid.
  • gl-display-glx/glx_display.c

    r3343 r3547  
    8282{
    8383  gl_window->autorepeat_flag = 0;
     84}
     85
     86void
     87enable_centered_cursor (
     88#ifndef GLX_DISPLAY_SINGLESTATE
     89  gl_window_t  * gl_window
     90#endif
     91  )
     92{
     93  gl_window->center_cursor_flag = 1;
     94  gl_window->cycling_cursor_flag = 0;
     95}
     96
     97void
     98disable_centered_cursor (
     99#ifndef GLX_DISPLAY_SINGLESTATE
     100  gl_window_t  * gl_window
     101#endif
     102  )
     103{
     104  gl_window->center_cursor_flag = 0;
     105}
     106
     107void
     108enable_cycling_cursor (
     109#ifndef GLX_DISPLAY_SINGLESTATE
     110  gl_window_t  * gl_window
     111#endif
     112  )
     113{
     114  gl_window->cycling_cursor_flag = 1;
     115  gl_window->center_cursor_flag = 0;
     116}
     117
     118void
     119disable_cycling_cursor (
     120#ifndef GLX_DISPLAY_SINGLESTATE
     121  gl_window_t  * gl_window
     122#endif
     123  )
     124{
     125  gl_window->cycling_cursor_flag = 0;
    84126}
    85127
     
    112154int query_extensions_glx (Display * display);
    113155void exit_on_err (char * s);
    114 Cursor CreateNullPointer (void);
    115 void SetNullPointer (void);
    116156
    117157/*
     
    158198  gl_window->double_buffered_flag = double_buffered;
    159199  gl_window->fullscreen_flag      = fullscreen;
     200  gl_window->motion_dx = 0;
     201  gl_window->motion_dy = 0;
     202
    160203
    161204  gl_window->display = XOpenDisplay( NULL );
     
    199242    KeyPressMask        | KeyReleaseMask    |
    200243    ButtonPressMask     | ButtonReleaseMask |
    201     PointerMotionMask;
     244    PointerMotionMask   | LeaveWindowMask   |
     245    EnterWindowMask;
    202246  /* gl_window->attributes.override_redirect = 1; */
    203247
     
    301345}
    302346
     347/* TODO make those function accept a gl_wondow_t *,
     348 * no more an XEvent, like the event_dx function.
     349 */
    303350int event_type( XEvent * e ) { return e->type; }
    304351int event_x( XButtonEvent * e ) { return e->x; }
    305352int event_y( XButtonEvent * e ) { return e->y; }
    306353int event_button( XButtonEvent * e ) { return e->button; }
    307 int event_keycode( XEvent * e ) { return XLookupKeysym( &e->xkey, 0 ); }
     354int event_xkeycode( XEvent * e ) { return XLookupKeysym( &e->xkey, 0 ); }
     355int
     356event_dx (
     357#ifndef GLX_DISPLAY_SINGLESTATE
     358  gl_window_t  * gl_window
     359#endif
     360  )
     361{
     362  return gl_window->motion_dx;
     363}
     364int
     365event_dy (
     366#ifndef GLX_DISPLAY_SINGLESTATE
     367  gl_window_t  * gl_window
     368#endif
     369  )
     370{
     371  return gl_window->motion_dy;
     372}
    308373
    309374/*
     
    318383  )
    319384{
    320   static XEvent e;
    321   static int pending = 0;
    322385  int repeating = 1;
    323 
    324   if ( pending == 0 ) pending = XPending( gl_window->display );
    325   while ( pending > 0 && repeating )
     386  int need_warp = 0;
     387
     388  if ( gl_window->pending == 0 )
     389    gl_window->pending = XPending( gl_window->display );
     390 
     391  while ( gl_window->pending > 0 && repeating )
    326392  {
    327393    repeating = 0;
    328     XNextEvent( gl_window->display, &e );
    329     pending--;
     394    XNextEvent( gl_window->display, &gl_window->e );
     395    gl_window->pending--;
    330396
    331397    /* Handle autorepeat.
    332398     * The mechanic is taken from Quake3.
    333399     * In Quake3, they assume the KeyRelease and
    334      * the followinf KeyPress have the same time.
     400     * the following KeyPress have the same time.
    335401     * Here, I've added a delta of 10 because
    336402     * I experienced different times for
     
    338404     * a delta of 1 millisecond...).
    339405     */
    340     if ( e.type == KeyRelease && !gl_window->autorepeat_flag )
     406    if ( gl_window->e.type == KeyRelease && !gl_window->autorepeat_flag )
    341407    {
    342       if ( pending == 0 ) pending = XPending( gl_window->display );
    343       if ( pending > 0 )
     408      if ( gl_window->pending == 0 )
     409        gl_window->pending = XPending( gl_window->display );
     410      if ( gl_window->pending > 0 )
    344411      {
    345412        XEvent peekevent;
    346413        XPeekEvent( gl_window->display, &peekevent );
    347414        if ((peekevent.type == KeyPress) &&
    348             (peekevent.xkey.keycode == e.xkey.keycode) &&
    349             (peekevent.xkey.time >= e.xkey.time &&
    350              peekevent.xkey.time <= e.xkey.time + 10))
     415            (peekevent.xkey.keycode == gl_window->e.xkey.keycode) &&
     416            (peekevent.xkey.time >= gl_window->e.xkey.time &&
     417             peekevent.xkey.time <= gl_window->e.xkey.time + 10))
    351418        {
    352419          /* it's autorepeating, remove the KeyPress. */
    353           XNextEvent( gl_window->display, &e );
    354           pending--;
     420          XNextEvent( gl_window->display, &gl_window->e );
     421          gl_window->pending--;
    355422          repeating = 1;
    356423        }
     
    359426  }
    360427 
    361   if ( repeating )
    362   {
    363     e.type = LASTEvent + 1; /* means 'no event' */
    364   }
    365 
    366   return (void *) &e;
     428  if ( repeating )  /* No event. */
     429  {
     430    gl_window->e.type = LASTEvent + 1; /* means 'no event' */
     431  }
     432  else              /* We have a meaningful event structure to return. */
     433  {
     434    if ( gl_window->e.type == MotionNotify )
     435    {
     436      int x, y;
     437      x = gl_window->e.xmotion.x;
     438      y = gl_window->e.xmotion.y;
     439
     440      if ( gl_window->center_cursor_flag &&
     441          x == gl_window->width  / 2 &&
     442          y == gl_window->height / 2 )
     443      { /* Cursor goes to center because we've warped it. */
     444        gl_window->last_x = gl_window->width  / 2;
     445        gl_window->last_y = gl_window->height / 2;
     446
     447        gl_window->e.type = LASTEvent + 1; /* means 'no event' */
     448      }
     449      else
     450      {
     451        gl_window->motion_dx = x - gl_window->last_x;
     452        gl_window->motion_dy = y - gl_window->last_y;
     453        gl_window->last_x = x;
     454        gl_window->last_y = y;
     455
     456        if ( gl_window->center_cursor_flag &&
     457            (abs(x - gl_window->width  / 2) > gl_window->width  / 3 ||
     458             abs(y - gl_window->height / 2) > gl_window->height / 3 ) )
     459          warp_mouse( gl_window, gl_window->width / 2, gl_window->height / 2 );
     460      }
     461    }
     462    else if ( gl_window->cycling_cursor_flag && gl_window->e.type == LeaveNotify )
     463    {
     464      int x, y;
     465      x = gl_window->e.xmotion.x;
     466      y = gl_window->e.xmotion.y;
     467     
     468      while ( x >= gl_window->width )
     469        x -= gl_window->width;
     470      while ( y >= gl_window->height )
     471        y -= gl_window->height;
     472      while ( x < 0 )
     473        x += gl_window->width;
     474      while ( y < 0 )
     475        y += gl_window->height;
     476
     477      gl_window->last_x = x;
     478      gl_window->last_y = y;
     479
     480      /* This will generate an EnterNotify, not a MotionNotify. */
     481      warp_mouse( gl_window, x, y );
     482    }
     483  }
     484
     485
     486  return (void *) &gl_window->e;
    367487}
    368488
     
    429549}
    430550
    431 /*
    432 Cursor CreateNullPointer(void)
     551
     552Cursor CreateNullPointer (
     553#ifndef GLX_DISPLAY_SINGLESTATE
     554  gl_window_t  * gl_window
     555#endif
     556  )
    433557{
    434558  Cursor cursor;
     
    438562  XColor color;
    439563
    440   pm = XCreatePixmap(dpy, RootWindow(dpy, scrnum), 1, 1, 1);
     564  pm = XCreatePixmap( gl_window->display, RootWindow(gl_window->display, gl_window->screen), 1, 1, 1);
    441565  val.function = GXclear;
    442   ctx = XCreateGC(dpy, pm, GCFunction, &val);
     566  ctx = XCreateGC(gl_window->display, pm, GCFunction, &val);
    443567
    444568  color.pixel = 0;
    445569  color.red = 0;
    446   color.flags = 04;
    447   cursor = XCreatePixmapCursor(dpy, pm, pm, &color, &color, 0,0);
    448 
    449   XFreePixmap(dpy, pm);
    450   XFreeGC(dpy, ctx);
     570  color.flags = 0; /*04;*/
     571  cursor = XCreatePixmapCursor(gl_window->display, pm, pm, &color, &color, 0,0);
     572
     573  XFreePixmap(gl_window->display, pm);
     574  XFreeGC(gl_window->display, ctx);
    451575
    452576  return cursor;
    453577}
    454578
    455 void SetNullPointer(void)
    456 {
    457   XDefineCursor( dpy, win, CreateNullPointer() );
    458 }*/
     579void disable_cursor (
     580#ifndef GLX_DISPLAY_SINGLESTATE
     581  gl_window_t  * gl_window
     582#endif
     583  )
     584{
     585  XDefineCursor( gl_window->display, gl_window->window, CreateNullPointer(gl_window) );
     586}
    459587
    460588
     
    479607
    480608
     609/* Translate an XKeyPressed or XKeyReleased event to a
     610 * gl-display keycode (i.e. translate the enclosed X keycode
     611 * to a gl-display keycode).
     612 * X keycodes are in [8-255], so gl-display keycodes are.
     613 */
     614
     615unsigned int
     616event_keycode( XKeyEvent * e )
     617{
     618  KeySym keysym;
     619
     620  unsigned int keycode = 0;
     621
     622  keysym = event_xkeycode( (XEvent *) e );
     623
     624  /* printf("keysym : %x\n", keysym); */
     625 
     626  if ( keysym >= 33 && keysym <= 127 )
     627  {
     628    keycode = (unsigned int) keysym;
     629    /* printf("between ! and _ : %x\n", keysym);
     630    printf("between ! and _ : %x\n", keycode); */
     631  }
     632  else
     633  {
     634  switch ( keysym )
     635  {
     636    case XK_KP_Page_Up:
     637    case XK_KP_9:        keycode = K_KP_PAGE_UP; break;
     638    case XK_Page_Up:     keycode = K_PAGE_UP;    break;
     639
     640    case XK_KP_Page_Down:
     641    case XK_KP_3:        keycode = K_KP_PAGE_DOWN; break;
     642    case XK_Page_Down:   keycode = K_PAGE_DOWN;    break;
     643
     644    case XK_KP_Home:     keycode = K_KP_HOME; break;
     645    case XK_KP_7:        keycode = K_KP_HOME; break;
     646    case XK_Home:        keycode = K_HOME;    break;
     647
     648    case XK_KP_End:
     649    case XK_KP_1:        keycode = K_KP_END; break;
     650    case XK_End:         keycode = K_END;    break;
     651
     652    case XK_KP_Left:     keycode = K_KP_LEFT_ARROW; break;
     653    case XK_KP_4:        keycode = K_KP_LEFT_ARROW; break;
     654    case XK_Left:        keycode = K_LEFT_ARROW;    break;
     655
     656    case XK_KP_Right:    keycode = K_KP_RIGHT_ARROW; break;
     657    case XK_KP_6:        keycode = K_KP_RIGHT_ARROW; break;
     658    case XK_Right:       keycode = K_RIGHT_ARROW;    break;
     659
     660    case XK_KP_Down:
     661    case XK_KP_2:        keycode = K_KP_DOWN_ARROW; break;
     662    case XK_Down:        keycode = K_DOWN_ARROW;    break;
     663
     664    case XK_KP_Up:
     665    case XK_KP_8:        keycode = K_KP_UP_ARROW;   break;
     666    case XK_Up:          keycode = K_UP_ARROW; break;
     667
     668    case XK_Escape:      keycode = K_ESCAPE;  break;
     669
     670    case XK_KP_Enter:    keycode = K_KP_ENTER; break;
     671    case XK_Return:      keycode = K_ENTER;    break;
     672
     673    case XK_Tab: keycode = K_TAB;      break;
     674
     675    case XK_F1:  keycode = K_F1;       break;
     676    case XK_F2:  keycode = K_F2;       break;
     677    case XK_F3:  keycode = K_F3;       break;
     678    case XK_F4:  keycode = K_F4;       break;
     679    case XK_F5:  keycode = K_F5;       break;
     680    case XK_F6:  keycode = K_F6;       break;
     681    case XK_F7:  keycode = K_F7;       break;
     682    case XK_F8:  keycode = K_F8;       break;
     683    case XK_F9:  keycode = K_F9;       break;
     684    case XK_F10: keycode = K_F10;      break;
     685    case XK_F11: keycode = K_F11;      break;
     686    case XK_F12: keycode = K_F12;      break;
     687
     688    case XK_BackSpace: keycode = K_BACKSPACE; break;
     689
     690    case XK_KP_Delete:
     691    case XK_KP_Decimal: keycode = K_KP_DELETE; break;
     692    case XK_Delete:     keycode = K_DELETE;    break;
     693
     694    case XK_Pause:      keycode = K_PAUSE;  break;
     695
     696    case XK_Shift_L: keycode = K_LEFT_SHIFT;  break;
     697    case XK_Shift_R: keycode = K_RIGHT_SHIFT; break;
     698
     699    case XK_Control_L: keycode = K_LEFT_CONTROL;  break;
     700    case XK_Control_R: keycode = K_RIGHT_CONTROL; break;
     701
     702    case XK_Alt_L:
     703    case XK_Meta_L: keycode = K_LEFT_ALT;  break;
     704    case XK_Alt_R:
     705    case XK_Meta_R: keycode = K_RIGHT_ALT; break;
     706
     707    case XK_KP_Begin:    keycode = K_KP_5;      break;
     708
     709    case XK_Insert:      keycode = K_INSERT;    break;
     710    case XK_KP_Insert:
     711    case XK_KP_0:        keycode = K_KP_INSERT; break;
     712    case XK_KP_Multiply: keycode = K_KP_STAR;   break;
     713    case XK_KP_Add:      keycode = K_KP_PLUS;   break;
     714    case XK_KP_Subtract: keycode = K_KP_MINUS;  break;
     715    case XK_KP_Divide:   keycode = K_KP_SLASH;  break;
     716
     717    case XK_space:
     718    case XK_KP_Space: keycode = K_SPACE; break;
     719  }
     720
     721  /*
     722    printf("not between ! and _ : %x\n", keysym);
     723    printf("not between ! and _ : %x\n", keycode);
     724    */
     725
     726  } /* else */
     727
     728  return keycode;
     729}
     730
     731/* TODO */
     732/* Translate an XKeyPressed or XKeyReleased event to a
     733 * gl-display keysym (i.e. translate the enclosed X keycode
     734 * to a gl-display keysym).
     735 * Are gl-display keysyms in unicode ?
     736 */
     737unsigned int
     738event_keysym( XKeyEvent * e )
     739{
     740  KeySym keysym;
     741  int found;
     742
     743  found = XLookupString( e, NULL, 0, &keysym, 0 );
     744  if ( found == NoSymbol )
     745    keysym = 0;
     746
     747  /* printf("keysym : %x\n", keysym); */
     748
     749  return (unsigned int) keysym;
     750}
     751/* TODO ask people who use chinese/japanese/... keyboards how to handle them. */
  • gl-display-glx/glx_display.h

    r3343 r3547  
    77#include <X11/keysym.h>
    88#include <X11/extensions/shape.h>
     9
     10#include "keycodes.h"
     11
     12/*
     13typedef enum
     14{
     15  K_BACKSPACE = 8,
     16  K_TAB       = 9,
     17  K_ENTER     = 13,
     18  K_ESCAPE    = 27,
     19
     20  K_SPACE = 32,
     21  K_EXCLAM,
     22  K_DOUBLE_QUOTE,
     23  K_NUMBER_SIGNE,
     24  K_DOLLAR,
     25  K_PERCENT,
     26  K_AMPERSAND,
     27  K_APOSTROPHE,
     28  K_LEFT_PAREN,
     29  K_RIGHT_PAREN,
     30  K_ASTERISK,
     31  K_PLUS,
     32  K_COMMA,
     33  K_MINUS,
     34  K_PERIOD,
     35  K_SLASH,
     36  K_0,
     37  K_1,
     38  K_2,
     39  K_3,
     40  K_4,
     41  K_5,
     42  K_6,
     43  K_7,
     44  K_8,
     45  K_9,
     46  K_COLON,
     47  K_SEMICOLON,
     48  K_LESS,
     49  K_EQUAL,
     50  K_GREATER,
     51  K_QUESTION,
     52  K_AT,
     53  K_A,
     54  K_B,
     55  K_C,
     56  K_D,
     57  K_E,
     58  K_F,
     59  K_G,
     60  K_H,
     61  K_I,
     62  K_J,
     63  K_K,
     64  K_L,
     65  K_M,
     66  K_N,
     67  K_O,
     68  K_P,
     69  K_Q,
     70  K_R,
     71  K_S,
     72  K_T,
     73  K_U,
     74  K_V,
     75  K_W,
     76  K_X,
     77  K_Y,
     78  K_Z,
     79  K_LEFT_BRACKET,
     80  K_BACKSLASH,
     81  K_RIGHT_BRACKET,
     82  K_ASCII_CIRCUM,
     83  K_UNDERSCORE,
     84  K_GRAVE,
     85  K_a,
     86  K_b,
     87  K_c,
     88  K_d,
     89  K_e,
     90  K_f,
     91  K_g,
     92  K_h,
     93  K_i,
     94  K_j,
     95  K_k,
     96  K_l,
     97  K_m,
     98  K_n,
     99  K_o,
     100  K_p,
     101  K_q,
     102  K_r,
     103  K_s,
     104  K_t,
     105  K_u,
     106  K_v,
     107  K_w,
     108  K_x,
     109  K_y,
     110  K_z,
     111  K_LEFT_BRACE,
     112  K_BAR,
     113  K_RIGHT_BRACE,
     114  K_ASCII_TILDE,
     115
     116  K_COMMAND = 128,
     117  K_CAPSLOCK,
     118  K_POWER,
     119  K_PAUSE,
     120
     121  K_UP_ARROW,
     122  K_DOWN_ARROW,
     123  K_LEFT_ARROW,
     124  K_RIGHT_ARROW,
     125
     126  K_LEFT_ALT,
     127  K_RIGHT_ALT,
     128  K_LEFT_CONTROL,
     129  K_RIGHT_CONTROL,
     130  K_LEFT_SHIFT,
     131  K_RIGHT_SHIFT,
     132  K_INSERT,
     133  K_DELETE,
     134  K_PAGE_DOWN,
     135  K_PAGE_UP,
     136  K_HOME,
     137  K_END,
     138
     139  K_F1,
     140  K_F2,
     141  K_F3,
     142  K_F4,
     143  K_F5,
     144  K_F6,
     145  K_F7,
     146  K_F8,
     147  K_F9,
     148  K_F10,
     149  K_F11,
     150  K_F12,
     151  K_F13,
     152  K_F14,
     153  K_F15,
     154
     155  K_KP_HOME,
     156  K_KP_UP_ARROW,
     157  K_KP_PAGE_UP,
     158  K_KP_LEFT_ARROW,
     159  K_KP_5,
     160  K_KP_RIGHT_ARROW,
     161  K_KP_END,
     162  K_KP_DOWN_ARROW,
     163  K_KP_PAGE_DOWN,
     164  K_KP_ENTER,
     165  K_KP_INSERT,
     166  K_KP_DELETE,
     167  K_KP_SLASH,
     168  K_KP_MINUS,
     169  K_KP_PLUS,
     170  K_KP_NUMLOCK,
     171  K_KP_STAR,
     172  K_KP_EQUALS,
     173
     174  K_MOUSE1,
     175  K_MOUSE2,
     176  K_MOUSE3,
     177  K_MOUSE4,
     178  K_MOUSE5,
     179
     180  K_WHEEL_DOWN,
     181  K_WHEEL_UP,
     182
     183  K_LAST_KEY
     184} keycode_t;
     185*/
     186
     187/* TODO change some ints into chars. */
    9188
    10189typedef struct gl_window_s
     
    18197  int          fullscreen_flag;
    19198  int          double_buffered_flag;
    20   int          mouse_flag;
     199  int          mouse_flag; /* used? */
     200  int          cycling_cursor_flag;
     201  int          center_cursor_flag;
    21202  int          autorepeat_flag;
    22203  /* XF86VidModeModeInfo original_mode; *//* i.e. desktop mode */
    23204  int          x;
    24205  int          y;
    25   unsigned int width;
    26   unsigned int height;
     206
     207  /*unsigned*/ int width;
     208  /*unsigned*/ int height;
    27209  unsigned int depth;
    28210  unsigned int screen_width;
    29211  unsigned int screen_height;
     212 
     213  XEvent       e;
     214  int          pending;
     215  /* Variables to hold deltas in x and y coordinates.
     216   * They complement a XMotionEvent structure to support
     217   * relative cursor movements, not only absolute cursor
     218   * position.
     219   */
     220  int          last_x;
     221  int          last_y;
     222  int          motion_dx;
     223  int          motion_dy;
    30224} gl_window_t;
    31225
     
    86280int event_y( XButtonEvent * e );
    87281int event_button( XButtonEvent * e );
    88 int event_keycode( XEvent * e );
     282int event_xkeycode( XEvent * e );
    89283
    90284XEvent *
     
    97291int time_milliseconds( void );
    98292
     293unsigned int event_keycode( XKeyEvent * e );
     294
    99295#endif /* GLX_DISPLAY_H */
    100296
  • gl-display-glx/samples/s01.scm

    r3309 r3547  
    3636    (gl:LoadIdentity)
    3737    (gl:Translatef 0  0 -6)
    38     (unit-square-xy)
     38    (square-xy 1)
    3939    (grid 7 0.2)
    4040    (gl-display:swap *display*)
  • gl-display-glx/samples/s02.scm

    r3309 r3547  
    1111(require 'gl-proj)
    1212
    13 (define *display* (gl-display:create 400 400 'full-screen))
     13(define *display* (gl-display:create 'width 400 'height 400))
    1414;(gl-display:make 1280 800)
    1515(gl-util:initialize)
     
    9999  (gl:Translatef (- *x*) (- *y*) -2)
    100100  (square-xy 20)
    101   (gl:Translatef -50 40 0)
     101  (gl:Translatef 100 100 0)
    102102  (textured-square-xy 100)
    103103  (points_2 *points*)
    104104  (gl-font:print "-- test --")
    105   (gl:Translatef -200 -100 0)
     105  (gl:Translatef 0 0 0)
    106106  (gl:Color3f 0 0 0)
    107107  (gl-font:print *command*)
  • gl-display-glx/samples/s03-repl.scm

    r3343 r3547  
    134134    (gl:Color3f 0.2 0.3 1)
    135135    (gl-proj:orthographic *display*)
    136     (gl:Translatef (* (gl-display:width *display*) -0.4) 0 0)
     136    (gl:Translatef 4 28 0)
    137137    (gl-font:print (string-append "> " (buffer:string)))
    138138    (load-identity)
    139     (gl:Translatef (* (gl-display:width *display*) -0.4) -40 0)
     139    (gl:Translatef 4 8 0)
    140140    (gl-font:print (string-append "; " *output-buffer*)))
    141141  (gl-display:swap *display*))
  • gl-display-glx/scripts/mk-egg

    r3309 r3547  
    11#!/bin/sh
    22tar czf gl-display-glx.egg \
    3  gl-display-glx.html \
    43 gl-display-glx.scm \
    54 glx_display.c \
Note: See TracChangeset for help on using the changeset viewer.