annotate R/rdyncall/demo/blink.R @ 37:8c8f848131c6

- version bump - better doc - made calling convention mode reset by default, as only way to specify convention used is via signature string
author Tassilo Philipp
date Mon, 13 Apr 2020 20:08:54 +0200
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 dynport(SDL)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 dynport(GL)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8 blink <- 0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
9 surface <- NULL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11 init <- function()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 SDL_Init(SDL_INIT_VIDEO)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 surface <<- SDL_SetVideoMode(640,480,32,SDL_OPENGL+SDL_DOUBLEBUF)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15 blink <<- 0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 update <- function()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 glFinish()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 glClearColor(0,0,blink,0)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23 glClear(GL_COLOR_BUFFER_BIT)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 SDL_GL_SwapBuffers()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25 glFlush()
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 }
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 quit <- function()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
64 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
65 SDL_Quit()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
66 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
67
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
68 run <- function()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
69 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
70 init()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
71 mainloop()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
72 quit()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
73 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
74
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
75 run()