annotate R/rdyncall/demo/randomfield.R @ 29:6cc2b7fc7ea2

bigger pydc update: - cleanups and refactoring - python 2 fixes in var conversions (especially w/ respect to int vs long) - fix to pydc.free() which didn't work at all - fix to return python bool as actual bool - test lib covering all conversions (manual verification, though :-/)
author Tassilo Philipp
date Wed, 08 Apr 2020 22:17:43 +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/randomfield.R
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 # Description: Scientific Computations using OpenGL: Rendering 512x512 random field by blending 5000 point sprites (dynport demo)
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 # ----------------------------------------------------------------------------
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
9 # Parameters:
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11 # framebuffer size
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 fb.size <- 512
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 # texture size
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15 tex.size <- 512
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 # texture setup
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 genTex.circle <- function(n)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23 m <- matrix(data=FALSE,nr=n,nc=n)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 r <- n/2
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25 for(i in 1:n)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27 for(j in 1:n)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29 m[[i,j]] <- ifelse((i-r)^2+(j-r)^2 > r^2,0L,255L)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32 return(m)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
34
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
35 genTex.bnorm <- function(n)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
36 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
37 x <- seq(-3,3,len=n)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
38 y <- dnorm(x)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
39 return( outer(y,y) )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
40 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
41
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
42 # ----------------------------------------------------------------------------
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
43 # draw circle using OpenGL Vertex Arrays
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
44
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
45 drawTexCirclesVertexArray <- function(x,y,r)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
46 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
47 n <- max( length(x), length(y), length(r) )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
48 x1 <- x-r
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
49 x2 <- x+r
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
50 y1 <- y-r
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
51 y2 <- y+r
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
52
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
53 vertexArray <- as.vector(rbind(x1,y1,x2, y1, x2, y2, x1, y2))
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
54 texCoordArray <- rep( as.double(c(0,0,1,0,1,1,0,1)), n )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
55
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
56 glEnableClientState(GL_VERTEX_ARRAY)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
57 glEnableClientState(GL_TEXTURE_COORD_ARRAY)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
58 glVertexPointer(2,GL_DOUBLE,0,vertexArray)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
59 glTexCoordPointer(2,GL_DOUBLE,0,texCoordArray)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
60
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
61 glDrawArrays(GL_QUADS, 0, n*4)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
62
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
63 glDisableClientState(GL_VERTEX_ARRAY)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
64 glDisableClientState(GL_TEXTURE_COORD_ARRAY)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
65 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
66
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
67 #drawPointSprite <- function()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
68 #{
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
69 # glEnable(GL_POINT_SPRITE)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
70 # glTexEnvi(GL_POINT_SPRITE,GL_COORD_REPLACE,GL_TRUE)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
71 # glPointParameter(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
72 # glPointSize
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 # ----------------------------------------------------------------------------
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
76 # initialize SDL, OpenGL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
77
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
78 max.tex.size <- integer(1)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
79 max.tex.units <- integer(1)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
80 tex.ids <- integer(1)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
81 init <- function()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
82 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
83 # initialize SDL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
84
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
85 SDL_Init(SDL_INIT_VIDEO)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
86 surface <<- SDL_SetVideoMode(fb.size,fb.size,32,SDL_OPENGL+SDL_DOUBLEBUF)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
87
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
88 # initialize OpenGL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
89
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
90 glGetIntegerv(GL_MAX_TEXTURE_SIZE, max.tex.size)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
91 glGetIntegerv(GL_MAX_TEXTURE_UNITS, max.tex.units)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
92
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
93 glClearColor(0,0,0,0)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
94 glColor4f(0.1,0.1,0.1,0)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
95
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
96 # img <- genTex.circle(tex.size)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
97 # texdata <- as.raw(img)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
98
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
99 img <- genTex.bnorm(tex.size)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
100 m <- max(img)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
101 texdata <- as.raw( ( img/m ) * 255 )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
102
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
103
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
104 glGenTextures( length(tex.ids),tex.ids)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
105 glBindTexture(GL_TEXTURE_2D, tex.ids[[1]])
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
106 glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
107 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, tex.size, tex.size, 0, GL_ALPHA, GL_UNSIGNED_BYTE, texdata)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
108 # glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, tex.size, tex.size, 0, GL_ALPHA, GL_DOUBLE, as.vector(img))
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
109
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
110 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_BORDER)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
111 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_BORDER)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
113 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
114
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
115 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
116 glEnable(GL_TEXTURE_2D)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
117
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
118 # blending setup
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
119
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
120 glBlendFunc(GL_SRC_ALPHA, GL_ONE)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
121 glEnable(GL_BLEND)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
122 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
123
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
124 cleanup <- function()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
125 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
126 glDeleteTextures( length(tex.ids), tex.ids)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
127 SDL_Quit()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
128 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
129
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
130 pixels <- NULL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
131
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
132 main <- function()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
133 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
134 cat("Click on window to import current random field and plot in R.\nClose window to quit mainloop.\n")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
135 N <- 5000
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
136 colorunit <- 0.02
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
137 glColor3d( colorunit,colorunit,colorunit )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
138 tbase <- SDL_GetTicks()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
139 frames <- 0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
140
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
141 x <- runif(N,-1.1,1.1)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
142 y <- runif(N,-1.1,1.1)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
143 r <- runif(N,0.1,0.2)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
144 event <- new.struct("SDL_Event")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
145
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
146 # disable interactive plot device.
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
147 oldpars <- par(ask=FALSE,mfrow=c(1,1))
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
148
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
149 quit <- FALSE
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
150 while(!quit)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
151 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
152 glClear(GL_COLOR_BUFFER_BIT)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
153 drawTexCirclesVertexArray(x,y,r)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
154 x <- runif(N,-1.1,1.1)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
155 y <- runif(N,-1.1,1.1)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
156 r <- runif(N,0.1,0.2)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
157 glFinish()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
158 SDL_GL_SwapBuffers()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
159 tnow <- SDL_GetTicks()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
160 if ((tnow - tbase) > 1000)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
161 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
162 tbase <- tnow
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
163 SDL_WM_SetCaption(paste("FPS:", frames),NULL)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
164 frames <- 0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
165 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
166 while( SDL_PollEvent(event) != 0 )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
167 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
168 type <- event$type
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
169 if (type == SDL_MOUSEBUTTONDOWN) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
170 cat("Read pixels via OpenGL into an R integer matrix..")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
171 pixels <<- readpixels()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
172 cat("done.\nPlot image results with R plotting device. This may take a while - please be patient..")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
173 image(pixels)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
174 cat("done.\nContinue..\n")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
175 } else if (type == SDL_QUIT) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
176 cat("Read pixels via OpenGL into an R integer matrix 'pixels'..")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
177 pixels <<- readpixels()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
178 cat("done.\nRe-run by 'run()'\n")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
179 quit <- TRUE
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
180 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
181 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
182 frames <- frames + 1
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
183 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
184 par(oldpars)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
185 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
186
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
187 readpixels <- function()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
188 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
189 array <- matrix(NA_integer_,fb.size,fb.size)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
190 glPixelStorei(GL_PACK_ALIGNMENT,1)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
191 glReadPixels(0,0,fb.size,fb.size, GL_LUMINANCE, GL_INT, array)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
192 return(array)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
193 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
194
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
195 run <- function()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
196 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
197 init()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
198 main()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
199 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
200
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
201 run()