-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
365e04f
commit 47c4e89
Showing
2 changed files
with
155 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env ol | ||
|
||
(import (lib glfw)) | ||
|
||
(glfwSetErrorCallback | ||
(GLFWerrorfun (error_code description) | ||
(print error_code ": " description))) | ||
|
||
; init | ||
(unless (glfwInit) | ||
(runtime-error "glfw error")) | ||
|
||
(glfwWindowHint GLFW_CONTEXT_VERSION_MAJOR 2) | ||
(glfwWindowHint GLFW_CONTEXT_VERSION_MINOR 0) | ||
(define window (glfwCreateWindow 640 480 "The Title" NULL NULL)) | ||
|
||
; the OpenGL | ||
(glfwMakeContextCurrent window) | ||
(import (OpenGL 1.1)) | ||
|
||
; draw | ||
(let loop () | ||
(unless (glfwWindowShouldClose window) | ||
(glClearColor 0.3 0.3 0.3 1) | ||
(glClear GL_COLOR_BUFFER_BIT) | ||
|
||
(glBegin GL_TRIANGLES) | ||
(glColor3f 1 0 0) | ||
(glVertex2f -0.6 -0.6) | ||
|
||
(glColor3f 0 1 0) | ||
(glVertex2f +0.6 -0.6) | ||
|
||
(glColor3f 0 0 1) | ||
(glVertex2f -0.0 +0.7) | ||
(glEnd) | ||
|
||
(glfwSwapBuffers window) | ||
(glfwPollEvents) (sleep) | ||
(loop))) | ||
|
||
; done | ||
(glfwDestroyWindow window) | ||
(glfwTerminate) |
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 |
---|---|---|
@@ -0,0 +1,111 @@ | ||
(define-library (lib glfw) | ||
(import (otus lisp) | ||
(otus ffi)) | ||
(export | ||
glfwInit | ||
glfwTerminate | ||
GLFWerrorfun |make GLFWerrorfun| | ||
glfwSetErrorCallback | ||
|
||
glfwWindowHint | ||
GLFW_CONTEXT_VERSION_MAJOR | ||
GLFW_CONTEXT_VERSION_MINOR | ||
glfwCreateWindow | ||
glfwDestroyWindow | ||
glfwWindowShouldClose | ||
|
||
glfwPollEvents | ||
|
||
glfwMakeContextCurrent | ||
glfwSwapBuffers | ||
|
||
; (otus ffi) | ||
NULL | ||
) | ||
|
||
(cond-expand | ||
(Windows | ||
(begin | ||
(define libglfw (or (load-dynamic-library "glfw3.dll") | ||
(runtime-error "Can't load libglfw" | ||
"go to https://www.glfw.org/download.html and download one"))))) | ||
(Android | ||
(begin | ||
(define libglfw (or (load-dynamic-library "libglfw.so") | ||
(load-dynamic-library "libglfw.so.3") | ||
(runtime-error "Can't load libglfw" | ||
"try to rebuild apk"))))) | ||
(else | ||
(begin | ||
(define libglfw (or (load-dynamic-library "libglfw.so") | ||
(load-dynamic-library "libglfw.so.3") | ||
(runtime-error "Can't load libglfw" | ||
"try to install 'libglfw3' package, or\n" | ||
" check the libglfw homepage at https://www.glfw.org/download.html"))))) ) | ||
|
||
(begin | ||
(setq GLFW libglfw) | ||
|
||
(setq int fft-int) | ||
(setq int& fft-int&) | ||
(setq void fft-void) | ||
(setq bool fft-bool) | ||
|
||
(setq GLFWmonitor* type-vptr) | ||
(setq GLFWwindow* type-vptr) | ||
|
||
(define glfwInit (GLFW int "glfwInit")) | ||
(define glfwTerminate (GLFW void "glfwTerminate")) | ||
;glfwInitHint | ||
;glfwGetVersion | ||
;glfwGetVersionString | ||
;glfwGetError | ||
|
||
(define (|make GLFWerrorfun| handler) | ||
(make-callback | ||
(vm:pin (cons | ||
(cons type-vptr (list fft-int type-string)) | ||
handler | ||
)))) | ||
(define-syntax GLFWerrorfun | ||
(syntax-rules () | ||
((GLFWerrorfun (code description) . body) | ||
(|make GLFWerrorfun| | ||
(lambda (code description) . body) )))) | ||
|
||
(define GLFWerrorfun* type-callable) | ||
(define glfwSetErrorCallback (GLFW GLFWerrorfun* "glfwSetErrorCallback" GLFWerrorfun*)) | ||
|
||
;glfwGetMonitors | ||
;glfwGetPrimaryMonitor | ||
;glfwGetMonitorPos | ||
;glfwGetMonitorWorkarea | ||
;glfwGetMonitorPhysicalSize | ||
;glfwGetMonitorContentScale | ||
;glfwGetMonitorName | ||
;glfwSetMonitorUserPointer | ||
;glfwGetMonitorUserPointer | ||
;glfwSetMonitorCallback | ||
|
||
;glfwGetVideoModes | ||
;glfwGetVideoMode | ||
;glfwSetGamma | ||
;glfwGetGammaRamp | ||
;glfwSetGammaRamp | ||
|
||
;glfwDefaultWindowHints | ||
(define glfwWindowHint (GLFW void "glfwWindowHint" int int)) | ||
(setq GLFW_CONTEXT_VERSION_MAJOR #x00022002) | ||
(setq GLFW_CONTEXT_VERSION_MINOR #x00022003) | ||
;glfwWindowHintString | ||
(define glfwCreateWindow (GLFW GLFWwindow* "glfwCreateWindow" int int type-string GLFWmonitor* GLFWwindow*)) | ||
(define glfwDestroyWindow (GLFW void "glfwDestroyWindow" GLFWwindow*)) | ||
(define glfwWindowShouldClose (GLFW bool "glfwWindowShouldClose" GLFWwindow*)) | ||
|
||
(define glfwPollEvents (GLFW void "glfwPollEvents")) | ||
|
||
(define glfwMakeContextCurrent (GLFW void "glfwMakeContextCurrent" GLFWwindow*)) | ||
;glfwGetCurrentContext | ||
(define glfwSwapBuffers (GLFW void "glfwSwapBuffers" GLFWwindow*)) | ||
;glfwSwapInterval | ||
)) |