annotate R/rdyncall/demo/blink_gl3.R @ 3:f5d4d5c2f750

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