annotate R/rdc/demo/sdl.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 library(rdc)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2 # ----------------------------------------------------------------------------
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 # Platform specific issues
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 if (.Platform$OS.type == "windows") {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 OS <- "windows"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 } else if ( Sys.info()[["sysname"]] == "Darwin" ) {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8 OS <- "darwin"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
9 } else {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 OS <- "unix"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 # ----------------------------------------------------------------------------
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 # dynbind environment
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 .cdecl <- dcNewCallVM(1024)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 .stdcall <- dcNewCallVM(1024)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 dcMode(.stdcall, rdc:::DC_CALL_C_X86_WIN32_STD )
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 # C memory allocation
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 .callC <- .cdecl
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23 .callSDL <- .cdecl
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 .callGL <- .cdecl
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25 .callGLU <- .cdecl
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26 .callR <- .cdecl
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27 if (OS == "windows") {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28 .libC <- "/windows/system32/msvcrt"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29 .libSDL <- "/dll/sdl"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30 .libGL <- "/windows/system32/OPENGL32"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31 .libGLU <- "/windows/system32/GLU32"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32 .libR <- "R"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33 .callGL <- .stdcall
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
34 } else if (OS == "darwin") {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
35 .libCocoa <- "/System/Library/Frameworks/Cocoa.framework/Cocoa"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
36 dyn.load(.libCocoa)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
37 .NSApplicationLoad <- getNativeSymbolInfo("NSApplicationLoad")$address
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
38 NSApplicationLoad <- function() rdcCall(.NSApplicationLoad, ")B" )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
39 # dyn.load("rdc")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
40 .newPool <- getNativeSymbolInfo("newPool")$address
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
41 .releasePool <- getNativeSymbolInfo("releasePool")$address
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
42 releasePool <- function(x)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
43 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
44 rdcCall( .releasePool, "p)v", x )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
45 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
46 newPool <- function()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
47 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
48 x <- rdcCall( .newPool, ")p" )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
49 reg.finalizer( x, releasePool )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
50 return(x)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
51 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
52 .pool <- newPool()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
53 .libC <- "/usr/lib/libc.dylib"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
54 .libSDL <- "/Library/Framworks/SDL.framework/SDL"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
55 .libGL <- "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
56 .libGLU <- "/System/Library/Frameworks/OpenGL.framework/Libraries/libGLU.dylib"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
57 .libR <- Sys.getenv("R_HOME")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
58 .libR <- paste(.libR,"/lib/libR.dylib",sep="")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
59 } else { # unix
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
60 .libC <- "/lib/libc.so.6"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
61 .libSDL <- "/usr/lib/libSDL.so"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
62 .libGL <- "/usr/lib/libGL.so"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
63 .libGLU <- "/usr/lib/libGLU.so"
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
64 .libR <- paste(R.home(),"/lib/libR.so",sep="")
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 #dyn.load(.libC)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
68 #.malloc <- getNativeSymbolInfo("malloc")$address
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
69 #.free <- getNativeSymbolInfo("free")$free
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
70 #malloc <- function(size) rdcCall(.malloc, "i)p", as.integer(size) )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
71 #free <- function(ptr) rdcCall(.free, "p)v", ptr)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
72
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
73 .importsR <- "
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
74 R_chk_calloc(ii)p;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
75 R_chk_realloc(ii)p;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
76 R_chk_free(p)v;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
77 "
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
78
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
79 rdcBind(.libR,.importsR,.callR)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
80
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
81 malloc <- function(size) R_chk_calloc(as.integer(size),1L)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
82 free <- function(ptr) R_chk_free(ptr)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
83
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
84
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
85 # ----------------------------------------------------------------------------
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
86 # SDL library
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
87 dyn.load(.libSDL)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
88
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
89 .SDL_Init <- getNativeSymbolInfo("SDL_Init")$address
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
90 .SDL_Quit <- getNativeSymbolInfo("SDL_Quit")$address
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
91 .SDL_SetVideoMode <- getNativeSymbolInfo("SDL_SetVideoMode")$address
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
92 .SDL_WM_SetCaption <- getNativeSymbolInfo("SDL_WM_SetCaption")$address
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
93 .SDL_GL_SwapBuffers <- getNativeSymbolInfo("SDL_GL_SwapBuffers")$address
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
94 .SDL_PollEvent <- getNativeSymbolInfo("SDL_PollEvent")$address
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
95 .SDL_GetTicks <- getNativeSymbolInfo("SDL_GetTicks")$address
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
96 .SDL_Delay <- getNativeSymbolInfo("SDL_Delay")$address
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
97 # init flags:
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
98 SDL_INIT_TIMER = 0x00000001L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
99 SDL_INIT_AUDIO = 0x00000010L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
100 SDL_INIT_VIDEO = 0x00000020L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
101 SDL_INIT_CDROM = 0x00000100L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
102 SDL_INIT_JOYSTICK = 0x00000200L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
103 SDL_INIT_NOPARACHUTE = 0x00100000L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
104 SDL_INIT_EVENTTHREAD = 0x01000000L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
105 SDL_INIT_EVERYTHING = 0x0000FFFFL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
106 # SDL_Init(flags):
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
107 SDL_Init <- function(flags) rdcCall(.SDL_Init, "i)i", as.integer(flags) )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
108 # SDL_Quit():
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
109 SDL_Quit <- function() rdcCall(.SDL_Quit, ")v" )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
110 # video flags:
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
111 SDL_SWSURFACE = 0x00000000L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
112 SDL_HWSURFACE = 0x00000001L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
113 SDL_ASYNCBLIT = 0x00000004L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
114 SDL_ANYFORMAT = 0x10000000L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
115 SDL_HWPALETTE = 0x20000000L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
116 SDL_DOUBLEBUF = 0x40000000L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
117 SDL_FULLSCREEN = 0x80000000
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
118 SDL_OPENGL = 0x00000002L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
119 SDL_OPENGLBLIT = 0x0000000AL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
120 SDL_RESIZABLE = 0x00000010L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
121 SDL_NOFRAME = 0x00000020L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
122 SDL_HWACCEL = 0x00000100L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
123 SDL_SRCCOLORKEY = 0x00001000L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
124 SDL_RLEACCELOK = 0x00002000L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
125 SDL_RLEACCEL = 0x00004000L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
126 SDL_SRCALPHA = 0x00010000L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
127 SDL_PREALLOC = 0x01000000L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
128 # SDL_SetVideoMode():
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
129 SDL_SetVideoMode <- function(width,height,bpp,flags) rdcCall(.SDL_SetVideoMode,"iiii)p",width,height,bpp,flags)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
130 SDL_WM_SetCaption <- function(title, icon) rdcCall(.SDL_WM_SetCaption,"SS)v",as.character(title), as.character(icon))
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
131 SDL_PollEvent <- function(eventptr) rdcCall(.SDL_PollEvent,"p)i", eventptr)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
132 SDL_GL_SwapBuffers <- function() rdcCall(.SDL_GL_SwapBuffers,")v")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
133 SDL_GetTicks <- function() rdcCall(.SDL_GetTicks,")i")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
134 SDL_Delay <- function(ms) rdcCall(.SDL_Delay,"i)v",ms)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
135
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
136 SDL_NOEVENT = 0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
137 SDL_ACTIVEEVENT = 1
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
138 SDL_KEYDOWN = 2
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
139 SDL_KEYUP = 3
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
140 SDL_MOUSEMOTION = 4
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
141 SDL_MOUSEBUTTONDOWN = 5
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
142 SDL_MOUSEBUTTONUP = 6
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
143 SDL_JOYAXISMOTION = 7
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
144 SDL_JOYBALLMOTION = 8
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
145 SDL_JOYHATMOTION = 9
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
146 SDL_JOYBUTTONDOWN = 10
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
147 SDL_JOYBUTTONUP = 11
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
148 SDL_QUIT = 12
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
149 SDL_SYSWMEVENT = 13
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
150 SDL_EVENT_RESERVEDA = 14
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
151 SDL_EVENT_RESERVEDB = 15
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
152 SDL_VIDEORESIZE = 16
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
153 SDL_VIDEOEXPOSE = 17
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
154 SDL_EVENT_RESERVED2 = 18
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
155 SDL_EVENT_RESERVED3 = 19
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
156 SDL_EVENT_RESERVED4 = 20
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
157 SDL_EVENT_RESERVED5 = 21
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
158 SDL_EVENT_RESERVED6 = 22
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
159 SDL_EVENT_RESERVED7 = 23
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
160 SDL_USEREVENT = 24
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
161 SDL_NUMEVENTS = 32
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
162
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
163
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
164 SDL_EventType <- function(event) offset(event, 0, "integer", 1)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
165
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
166
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
167
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
168 # ----------------------------------------------------------------------------
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
169 # OpenGL bindings
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
170 dyn.load(.libGL)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
171
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
172 .importsGL <- "
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
173 glGetError()i;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
174 glClearColor(ffff)v;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
175 glClear(i)v;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
176 glMatrixMode(i)v;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
177 glLoadIdentity()v;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
178 glBegin(i)v;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
179 glEnd()v;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
180 glVertex3d(ddd)v;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
181 glRotated(dddd)v;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
182 glGenLists(i)i;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
183 glNewList(ii)v;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
184 glEnableClientState(i)v;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
185 glVertexPointer(iiip)v;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
186 glColorPointer(iiip)v;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
187 glDrawElements(iiip)v;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
188 glDisableClientState(i)v;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
189 glEndList()v;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
190 glCallList(i)v;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
191 "
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
192
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
193 if (OS == "windows") {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
194 .callGL <- .stdcall
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
195 .callGLU <- .stdcall
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
196 } else {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
197 .callGL <- .cdecl
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
198 .callGLU <- .cdecl
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 # Import OpenGL symbols
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
202 rdcBind(.libGL,.importsGL, .callGL)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
203
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
204 GL_FALSE = 0x0L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
205 GL_TRUE = 0x1L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
206
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
207 GL_BYTE = 0x1400L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
208 GL_UNSIGNED_BYTE = 0x1401L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
209 GL_SHORT = 0x1402L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
210 GL_UNSIGNED_SHORT = 0x1403L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
211 GL_INT = 0x1404L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
212 GL_UNSIGNED_INT = 0x1405L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
213 GL_FLOAT = 0x1406L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
214 GL_DOUBLE = 0x140AL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
215 GL_2_BYTES = 0x1407L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
216 GL_3_BYTES = 0x1408L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
217 GL_4_BYTES = 0x1409L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
218
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
219
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
220 GL_COMPILE = 0x1300L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
221 GL_COMPILE_AND_EXECUTE = 0x1301L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
222 GL_LIST_BASE = 0x0B32L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
223 GL_LIST_INDEX = 0x0B33L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
224 GL_LIST_MODE = 0x0B30L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
225
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
226 GL_VERTEX_ARRAY = 0x8074L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
227 GL_NORMAL_ARRAY = 0x8075L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
228 GL_COLOR_ARRAY = 0x8076L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
229 GL_INDEX_ARRAY = 0x8077L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
230 GL_TEXTURE_COORD_ARRAY = 0x8078L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
231 GL_EDGE_FLAG_ARRAY = 0x8079L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
232 GL_VERTEX_ARRAY_SIZE = 0x807AL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
233 GL_VERTEX_ARRAY_TYPE = 0x807BL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
234 GL_VERTEX_ARRAY_STRIDE = 0x807CL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
235 GL_NORMAL_ARRAY_TYPE = 0x807EL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
236 GL_NORMAL_ARRAY_STRIDE = 0x807FL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
237 GL_COLOR_ARRAY_SIZE = 0x8081L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
238 GL_COLOR_ARRAY_TYPE = 0x8082L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
239 GL_COLOR_ARRAY_STRIDE = 0x8083L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
240 GL_INDEX_ARRAY_TYPE = 0x8085L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
241 GL_INDEX_ARRAY_STRIDE = 0x8086L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
242 GL_TEXTURE_COORD_ARRAY_SIZE = 0x8088L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
243 GL_TEXTURE_COORD_ARRAY_TYPE = 0x8089L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
244 GL_TEXTURE_COORD_ARRAY_STRIDE = 0x808AL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
245 GL_EDGE_FLAG_ARRAY_STRIDE = 0x808CL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
246 GL_VERTEX_ARRAY_POINTER = 0x808EL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
247 GL_NORMAL_ARRAY_POINTER = 0x808FL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
248 GL_COLOR_ARRAY_POINTER = 0x8090L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
249 GL_INDEX_ARRAY_POINTER = 0x8091L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
250 GL_TEXTURE_COORD_ARRAY_POINTER = 0x8092L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
251 GL_EDGE_FLAG_ARRAY_POINTER = 0x8093L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
252 GL_V2F = 0x2A20L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
253 GL_V3F = 0x2A21L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
254 GL_C4UB_V2F = 0x2A22L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
255 GL_C4UB_V3F = 0x2A23L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
256 GL_C3F_V3F = 0x2A24L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
257 GL_N3F_V3F = 0x2A25L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
258 GL_C4F_N3F_V3F = 0x2A26L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
259 GL_T2F_V3F = 0x2A27L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
260 GL_T4F_V4F = 0x2A28L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
261 GL_T2F_C4UB_V3F = 0x2A29L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
262 GL_T2F_C3F_V3F = 0x2A2AL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
263 GL_T2F_N3F_V3F = 0x2A2BL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
264 GL_T2F_C4F_N3F_V3F = 0x2A2CL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
265 GL_T4F_C4F_N3F_V4F = 0x2A2DL
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
266
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
267
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
268 GL_COLOR_BUFFER_BIT = 0x00004000L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
269
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
270 GL_MODELVIEW = 0x1700L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
271 GL_PROJECTION = 0x1701L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
272 GL_TEXTURE = 0x1702L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
273
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
274 GL_POINTS = 0x0000L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
275 GL_LINES = 0x0001L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
276 GL_LINE_LOOP = 0x0002L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
277 GL_LINE_STRIP = 0x0003L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
278 GL_TRIANGLES = 0x0004L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
279 GL_TRIANGLE_STRIP = 0x0005L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
280 GL_TRIANGLE_FAN = 0x0006L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
281 GL_QUADS = 0x0007L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
282 GL_QUAD_STRIP = 0x0008L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
283 GL_POLYGON = 0x0009L
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
284
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
285 # ----------------------------------------------------------------------------
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
286 # OpenGL utility library
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
287
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
288 .importsGLU <- "
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
289 gluLookAt(ddddddddd)v;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
290 gluPerspective(dddd)v;
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
291 "
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
292 rdcBind(.libGLU,.importsGLU, .callGLU)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
293
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
294 #dyn.load(.libGLU)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
295 #.gluLookAt <- getNativeSymbolInfo("gluLookAt")$address
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
296 #.gluPerspective <- getNativeSymbolInfo("gluPerspective")$address
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
297 #luLookAt <- function(eyeX,eyeY,eyeZ,centerX,centerY,centerZ,upX,upY,upZ)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
298 # rdcCall(.gluLookAt,"ddddddddd)v", eyeX,eyeY,eyeZ,centerX,centerY,centerZ,upX,upY,upZ)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
299 #gluPerspective <- function(fovy,aspect,znear,zfar)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
300 # rdcCall(.gluPerspective,"dddd)v",fovy,aspect,znear,zfar)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
301
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
302 # ----------------------------------------------------------------------------
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
303 # demo
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
304 init <- function()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
305 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
306 if (OS == "darwin")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
307 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
308 NSApplicationLoad()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
309 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
310 err <- SDL_Init(SDL_INIT_VIDEO)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
311 if (err != 0) error("SDL_Init failed")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
312 surface <- SDL_SetVideoMode(512,512,32,SDL_DOUBLEBUF+SDL_OPENGL)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
313 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
314
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
315 makeCubeDisplaylist <- function()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
316 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
317 vertices <- c(
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
318 -1,-1,-1,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
319 1,-1,-1,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
320 -1, 1,-1,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
321 1, 1,-1,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
322 -1,-1, 1,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
323 1,-1, 1,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
324 -1, 1, 1,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
325 1, 1, 1
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
326 )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
327
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
328 colors <- as.raw( col2rgb( rainbow(8) ) )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
329
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
330 triangleIndices <- as.integer(c(
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
331 0, 2, 1,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
332 2, 3, 1,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
333 1, 3, 7,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
334 1, 7, 5,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
335 4, 5, 7,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
336 4, 7, 6,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
337 6, 2, 0,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
338 6, 0, 4,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
339 2, 7, 3,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
340 2, 6, 7,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
341 4, 0, 5,
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
342 0, 1, 5
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
343 ))
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
344
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
345 glEnableClientState(GL_VERTEX_ARRAY)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
346 glVertexPointer(3, GL_DOUBLE, 0, rdcDataPtr(vertices) )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
347
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
348 glEnableClientState(GL_COLOR_ARRAY)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
349 glColorPointer(3, GL_UNSIGNED_BYTE, 0, rdcDataPtr(colors) )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
350
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
351 displaylistId <- glGenLists(1)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
352 glNewList( displaylistId, GL_COMPILE )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
353 glDrawElements(GL_TRIANGLES, 36L, GL_UNSIGNED_INT, rdcDataPtr(triangleIndices))
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
354 glEndList()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
355
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
356 glDisableClientState(GL_VERTEX_ARRAY)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
357 glDisableClientState(GL_COLOR_ARRAY)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
358
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
359 return(displaylistId)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
360 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
361 #buffers <- integer(2)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
362 #glGenBuffersARG(length(buffers), rdcDataPtr(buffers))
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
363 #glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers[[1]] )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
364 #glBufferDataARB(GL_ARRAY_BUFFER_ARB, rdcSizeOf(typeof(vertices)) * length(vertices) , rdcDataPtr(vertices) )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
365
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
366
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
367 mainloop <- function()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
368 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
369 displaylistId <- makeCubeDisplaylist()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
370 eventobj <- malloc(256)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
371 blink <- 0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
372 tbase <- SDL_GetTicks()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
373 quit <- FALSE
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
374 while(!quit)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
375 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
376 tnow <- SDL_GetTicks()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
377 tdemo <- ( tnow - tbase ) / 1000
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
378
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
379 glClearColor(0,0,blink,0)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
380 glClear(GL_COLOR_BUFFER_BIT)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
381
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
382 glMatrixMode(GL_PROJECTION)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
383 glLoadIdentity()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
384 aspect <- 512/512
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
385 gluPerspective(60, aspect, 3, 1000)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
386
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
387 glMatrixMode(GL_MODELVIEW)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
388 glLoadIdentity()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
389 gluLookAt(0,0,5,0,0,0,0,1,0)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
390 glRotated(sin(tdemo)*60.0, 0, 1, 0);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
391 glRotated(cos(tdemo)*90.0, 1, 0, 0);
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
392
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
393 glCallList(displaylistId)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
394
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
395 #glBegin(GL_TRIANGLES)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
396 #glVertex3d(-1,-1,-1)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
397 #glVertex3d( 1,-1,-1)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
398 #glVertex3d( 1, 1,-1)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
399 #glVertex3d(-1,-1,-1)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
400 #glVertex3d( 1, 1,-1)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
401 #glVertex3d(-1, 1,-1)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
402 #glEnd()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
403
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
404 SDL_GL_SwapBuffers()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
405
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
406 SDL_WM_SetCaption(paste("time:", tdemo),0)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
407 blink <- blink + 0.01
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
408 while (blink > 1) blink <- blink - 1
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
409 while( SDL_PollEvent(eventobj) != 0 )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
410 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
411 eventType <- rdcUnpack1(eventobj, 0L, "c")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
412 if (eventType == SDL_QUIT)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
413 quit <- TRUE
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
414 else if (eventType == SDL_MOUSEBUTTONDOWN)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
415 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
416 button <- rdcUnpack1(eventobj, 1L, "c")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
417 cat("button down: ",button,"\n")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
418 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
419 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
420 glerr <- glGetError()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
421 if (glerr != 0)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
422 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
423 cat("GL Error:", glerr)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
424 quit <- 1
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
425 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
426 SDL_Delay(30)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
427 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
428 free(eventobj)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
429 #glDeleteLists(displaylistId, 1)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
430 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
431
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
432 cleanup <- function()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
433 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
434 SDL_Quit()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
435 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
436
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
437 run <- function()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
438 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
439 init()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
440 mainloop()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
441 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
442 # run()
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
443