comparison R/rdyncall/demo/blink_gl3.R @ 0:0cfcc391201f

initial from svn dyncall-1745
author Daniel Adler
date Thu, 19 Mar 2015 22:26:28 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0cfcc391201f
1 # Package: rdyncall
2 # File: demo/blink.R
3 # Description: Simple SDL,OpenGL demonstration - a blinking screen
4
5 require(rdyncall)
6 dynport(SDL)
7 dynport(gl3)
8
9 blink <- 0
10 surface <- NULL
11
12 init <- function()
13 {
14 SDL_Init(SDL_INIT_VIDEO)
15 SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 1 )
16 surface <<- SDL_SetVideoMode(640,480,32,SDL_OPENGL+SDL_DOUBLEBUF)
17 blink <<- 0
18 }
19
20
21 update <- function()
22 {
23 glClearColor(0,0,blink,0)
24 glClear(GL_COLOR_BUFFER_BIT)
25 SDL_GL_SwapBuffers()
26 blink <<- ( blink + 0.01 ) %% 1
27 }
28
29 input <- function()
30 {
31 return(TRUE)
32 }
33
34 checkGL <- function()
35 {
36 glerror <- glGetError()
37 if (glerror != 0)
38 {
39 cat("GL Error", glerror, "\n")
40 }
41 return(glerror == 0)
42 }
43
44 mainloop <- function()
45 {
46 sdlevent <- new.struct("SDL_Event")
47 quit <- FALSE
48 while(!quit)
49 {
50 update()
51 while( SDL_PollEvent(sdlevent) )
52 {
53 if (sdlevent$type == SDL_QUIT ) {
54 quit <- TRUE
55 } else if (sdlevent$type == SDL_MOUSEBUTTONDOWN) {
56 cat("button ", sdlevent$button$button ,"\n")
57 }
58 }
59 if ( !checkGL() ) quit <- TRUE
60 # SDL_Delay(30)
61 }
62 }
63
64 quit <- function()
65 {
66 SDL_Quit()
67 }
68
69 run <- function()
70 {
71 init()
72 mainloop()
73 quit()
74 }
75
76 run()