That is the complete script Run sdlbmpevtex’’ after loading it. If you mean the SDL2 dll mappings here they are (it’s not complete just what I have done so far):
NB. SDL utilities for OpenGL require 'dll' void=: 0$'' null=: <0 SDLDLL =: '/usr/local/lib/libSDL2.dylib' NB. SDL Constants SDL_INIT_TIMER=: 16b00000001 SDL_INIT_AUDIO=: 16b00000010 SDL_INIT_VIDEO=: 16b00000020 NB. SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ SDL_INIT_JOYSTICK=: 16b00000200 NB. SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS */ SDL_INIT_HAPTIC=: 16b00001000 SDL_INIT_GAMECONTROLLER=: 16b00002000 NB. SDL_INIT_GAMECONTROLLER implies SDL_INIT_JOYSTICK */ SDL_INIT_EVENTS=: 16b00004000 SDL_INIT_SENSOR=: 16b00008000 SDL_INIT_NOPARACHUTE=: 16b00100000 NB. compatibility; this flag is ignored. */ SDL_INIT_EVERYTHING=: SDL_INIT_TIMER +. SDL_INIT_AUDIO +. SDL_INIT_VIDEO | SDL_INIT_EVENTS +. SDL_INIT_JOYSTICK +. SDL_INIT_HAPTIC +. SDL_INIT_GAMECONTROLLER +. SDL_INIT_SENSOR SDL_WINDOW_OPENGL =: 16b00000002 SDL_WINDOW_RESIZABLE =: 0x00000020 SDL_FIRSTEVENT =: 0 SDL_QUIT =: 16b100 SDL_APP_TERMINATING =: 16b101 SDL_APP_LOWMEMORY =: 16b102 SDL_APP_WILLENTERBACKGROUND =: 16b103 SDL_APP_DIDENTERBACKGROUND =: 16b104 SDL_APP_WILLENTERFOREGROUND =: 16b105 SDL_APP_DIDENTERFOREGROUND =: 16b106 NB. Display events SDL_DISPLAYEVENT=: 16b150 NB. Window events SDL_WINDOWEVENT =: 16b200 SDL_SYSWMEVENT =: 16b201 NB. Keyboard events SDL_KEYDOWN =: 16b300 SDL_KEYUP =: 16b301 SDL_TEXTEDITING =: 16b302 SDL_TEXTINPUT =: 16b303 SDL_KEYMAPCHANGED =: 16b304 NB. Mouse events SDL_MOUSEMOTION =: 16b400 SDL_MOUSEBUTTONDOWN =: 16b401 SDL_MOUSEBUTTONUP =: 16b402 SDL_MOUSEWHEEL =: 16b403 NB. Joystick events SDL_JOYAXISMOTION =: 16b600 SDL_JOYBALLMOTION =: 16b601 SDL_JOYHATMOTION =: 16b602 SDL_JOYBUTTONDOWN =: 16b603 SDL_JOYBUTTONUP =: 16b604 SDL_JOYDEVICEADDED =: 16b605 SDL_JOYDEVICEREMOVED =: 16b606 NB. Controller events SDL_CONTROLLERAXISMOTION =: 16b650 SDL_CONTROLLERBUTTONDOWN =: 16b651 SDL_CONTROLLERBUTTONUP =: 16b652 SDL_CONTROLLERDEVICEADDED =: 16b653 SDL_CONTROLLERDEVICEREMOVED =: 16b654 SDL_CONTROLLERDEVICEREMAPPED =: 16b655 NB. Touch events SDL_FINGERDOWN =: 16b700 SDL_FINGERUP =: 16b701 SDL_FINGERMOTION =: 16b702 NB. Gesture events SDL_DOLLARGESTURE =: 16b800 SDL_DOLLARRECORD =: 16b801 SDL_MULTIGESTURE =: 16b802 NB. Clipboard events SDL_CLIPBOARDUPDATE =: 16b900 NB. Drag and drop events SDL_DROPFILE =: 16b1000 SDL_DROPTEXT =: 16b1001 SDL_DROPBEGIN =: 16b1002 SDL_DROPCOMPLETE =: 16b1003 NB. Audio hotplug events SDL_AUDIODEVICEADDED =: 16b1100 SDL_AUDIODEVICEREMOVED =: 16b1101 NB. Sensor events SDL_SENSORUPDATE =: 16b1200 NB. Render events SDL_RENDER_TARGETS_RESET =: 16b2000 SDL_RENDER_DEVICE_RESET =: 16b2001 NB. These are for your use, and should be allocated with SDL_RegisterEvents() SDL_USEREVENT =: 16b8000 SDL_LASTEVENT =: 16bffff NB. extern DECLSPEC int SDLCALL SDL_Init(Uint32 flags); SDL_Init =: (SDLDLL, ' SDL_Init > i i')&cd NB. extern DECLSPEC int SDLCALL SDL_InitSubSystem(Uint32 flags); SDL_InitSubSystem =: (SDLDLL, ' SDL_InitSubSystem i i')&cd NB. extern DECLSPEC void SDLCALL SDL_QuitSubSystem(Uint32 flags); SDL_QuitSubSystem =: (SDLDLL, ' SDL_QuitSubSystem n i')&cd NB. extern DECLSPEC Uint32 SDLCALL SDL_WasInit(Uint32 flags); SDL_WasInit =: (SDLDLL, ' SDL_WasInit i i')&cd NB. extern DECLSPEC void SDLCALL SDL_Quit(void); SDL_Quit =: (SDLDLL, ' SDL_Quit n')&cd SDL_Delay =: (SDLDLL, ' SDL_Delay n i')&cd SDL_WINDOWPOS_UNDEFINED_MASK =: 16b1fff0000 SDL_WINDOWPOS_UNDEFINED =: SDL_WINDOWPOS_UNDEFINED_MASK +. 0 NB. extern DECLSPEC SDL_Window * SDLCALL SDL_CreateWindow(const char *title, NB. int x, int y, int w, NB. int h, Uint32 flags); SDL_CreateWindow =: (SDLDLL, ' SDL_CreateWindow * &c i i i i i')&cd NB. extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags); SDL_CreateRenderer =: (SDLDLL, ' SDL_CreateRenderer * * i i')&cd SDL_SetRenderDrawColor =: (SDLDLL, ' SDL_SetRenderDrawColor n * i i i i')&cd SDL_RenderCopy =: (SDLDLL, ' SDL_RenderCopy n * * * *')&cd SDL_RenderClear =: (SDLDLL, ' SDL_RenderClear n *')&cd SDL_RenderPresent =: (SDLDLL, ' SDL_RenderPresent n *')&cd SDL_RenderDrawLine =: (SDLDLL, ' SDL_RenderDrawLine n * i i i i')&cd SDL_DestroyRenderer =: (SDLDLL, ' SDL_DestroyRenderer n *')&cd SDL_DestroyWindow =: (SDLDLL, ' SDL_DestroyWindow n *')&cd SDL_DestroyTexture =: (SDLDLL, ' SDL_DestroyTexture n *')&cd SDL_FreeSurface =: (SDLDLL, ' SDL_FreeSurface n *')&cd SDL_CreateTextureFromSurface =: (SDLDLL, ' SDL_CreateTextureFromSurface * * *')&cd SDL_GL_CreateContext =: (SDLDLL, ' SDL_GL_CreateContext * *')&cd SDL_GetWindowSurface =: (SDLDLL, ' SDL_GetWindowSurface * *')&cd SDL_RWFromFile =: (SDLDLL, ' SDL_RWFromFile * *c *c')&cd SDL_LoadBMP_RW =: (SDLDLL, ' SDL_LoadBMP_RW * * i')&cd SDL_BlitSurface =: (SDLDLL, ' SDL_UpperBlit > i * * * *')&cd SDL_GL_SwapWindow =: (SDLDLL, ' SDL_GL_SwapWindow n *')&cd SDL_GL_DeleteContext =: (SDLDLL, ' SDL_GL_DeleteContext n *')&cd SDL_GL_SwapInterval =: (SDLDLL, ' SDL_GL_SwapInterval n i')&cd SDL_UpdateWindowSurface =: (SDLDLL, ' SDL_UpdateWindowSurface * *')&cd SDL_PollEvent =: (SDLDLL, ' SDL_PollEvent > i *')&cd NB. SDL_LoadBMP is a macro to call 2 lower level routines NB. The following will not work: NB. SDL_LoadBMP =: (SDLDLL, ' SDL_LoadBMP * &c')&cd NB. instead, it is recreated in J as a function call: NB. it expects a boxed string fully qualified path and filename NB. this keeps the calling convention of the dll consistent SDL_LoadBMP =: 3 : 0 Rwops =. {. SDL_RWFromFile y,<'rb' SDL_LoadBMP_RW Rwops;1 ) > On Dec 1, 2020, at 10:49 AM, bill lam <bbill....@gmail.com> wrote: > > Can you attach a complete script for demo? Thanks > > On Tue, Dec 1, 2020, 6:42 PM Thomas McGuire <tmcguir...@gmail.com> wrote: > >> Here is my code again so it stays within thread context >> >> NB. sdlbmpevtex.ijs - example of setting up a bitmap displayed in window >> NB. under SDL with QUIT event processing >> >> load '~/j902-user/temp/sdl2.ijs' >> >> NB. SDL_Init <SDL_INIT_VIDEO >> >> >> >> >> sdlbmpevtex =: 3 : 0 >> NB. to handle events SDL needs 56 bytes of space to fit the >> NB. event into. This is passed as a pointer. Defined globally >> NB. needs to be freed when you quit the application >> NB. Event loop variables >> ev =: mema 56 >> >> NB. initialized pointer variables to be used with SDL2 dll >> window =: null >> bmpsurf =: null >> texture =: null >> renderer =: null >> >> NB. calls to setup SDL2 and create a window with bitmap >> SDL_Init <SDL_INIT_EVERYTHING >> >> window =: {. SDL_CreateWindow 'SDL2 from J'; >> SDL_WINDOWPOS_UNDEFINED;SDL_WINDOWPOS_UNDEFINED;660;480;0 >> if. window = null do. >> smoutput 'ERROR: failed to create window' >> return. >> end. >> renderer =: {. SDL_CreateRenderer window; _1; 0 >> if. renderer = null do. >> smoutput 'ERROR: failed to create renderer' >> return. >> end. >> >> SDL_SetRenderDrawColor renderer; 0; 0; 0; 255 >> SDL_RenderClear<renderer >> NB. The SDL2 API call SDL_LoadBMP is a macro of 2 lower level >> NB. calls. It is created as a Jfunction in this >> bmpsurf=: {. SDL_LoadBMP >> <'/Applications/j902/addons/graphics/bmp/toucan.bmp' >> if. bmpsurf = null do. >> smoutput 'ERROR: failed to load bitmap' >> return. >> end. >> >> texture =: {. SDL_CreateTextureFromSurface renderer; <bmpsurf >> if. texture = null do. >> smoutput 'ERROR: failed to create texture' >> return. >> end. >> >> SDL_FreeSurface <bmpsurf >> bmpsurf =: null >> >> NB. Copy the texture to the renderer and present to the window >> SDL_RenderCopy renderer;texture;null;<null >> SDL_RenderPresent<renderer >> >> NB. set timer handler and start timer >> sys_timer_z_ =: sdleventhdlr_base_ >> wd 'timer 1000' >> ) >> >> sdleventhdlr =: 3 : 0 >> NB. Look for a quit event and call sdlfullquit and exit >> NB. Stop the timer while we process (it avoid forever errors) >> wd 'timer 0' >> while. 0 ~: SDL_PollEvent <<ev do. >> evtype =: {. 0 (3!:4) memr ev,0,32 >> NB. smoutput 'evtype = ',":evtype >> if. evtype = SDL_QUIT do. >> NB. quit and return timer stays off >> sdlfullquit'' >> return. >> end. >> end. >> >> NB. restart the timer >> wd 'timer 1000' >> ) >> >> sdlfullquit =: 3 : 0 >> SDL_DestroyTexture<texture >> texture =: null >> SDL_DestroyRenderer<renderer >> renderer =: null >> SDL_DestroyWindow <window >> window =: null >> SDL_Quit '' >> memf ev >> ev =: 0 >> ) >> >> >>> On Dec 1, 2020, at 5:33 AM, emacstheviking <obji...@gmail.com> wrote: >>> >>> For me, I have settled for being able to stop the event loop, edit the >> code >>> then resume the event loop where I left off and that's working well for >> me. >>> >>> basically I have u (for UI!) -routines >>> uprep'' >>> ugo 0 means when SDL_QUIT is received, leave everything up, ugo 1 will >>> call sdl_destroywindow and sdl_quit >>> uend'' >>> >>> and some basic run./stop code: >>> >>> uend=: 3 : 0 >>> sdl_freesurface sfc >>> sdl_destroyrenderer^:(appr>0) appr >>> sdl_destroywindow^:(appw>0) appw >>> sdl_quit'' >>> smoutput 'sdl shut down' >>> 'appw appr'=: 0 0 >>> ) >>> >>> ugo =: 3 : 0 >>> sdlprep SCREEN_X_MAX;SCREEN_Y_MAX >>> urun'' >>> uend^:y '' >>> ) >>> >>> On Tue, 1 Dec 2020 at 07:25, Thomas McGuire <tmcguir...@gmail.com> >> wrote: >>> >>>> I was glad to see some renewed interest in SDL2 and thank you to Raul >>>> Miller for the suggestion of setting timer to run an event loop. I >> haven’t >>>> had the chance to try Bill Lam’s suggestion of creating a tight event >> loop >>>> under Jconsole yet. >>>> >>>> I have attached my code for a simple example that: >>>> opens a window, >>>> displays the toucan.bmp that comes with J, >>>> and then allows you to quit by pressing the close window control on the >>>> displayed window. >>>> >>>> The only gotcha at this point is that a subsequent rerun under Jqt, the >>>> event system in SDL2 doesn’t register any events. So the app will hang >> and >>>> the window stays open. I have to quit Jqt entirely and restart to rerun >> the >>>> application properly. This is minimally annoying from a debugging stand >>>> point. Jqt comes back up quickly enough after a shut down and coding >> using >>>> a dll library can cause its share of hanging the entire Jqt interface >> when >>>> mistakes in the dll wrapper are made. >>>> >>>> I presume I am running into threading/Jqt state issues or perhaps the >> call >>>> to SDL_Quit is not running like I think it is. At any rate for my >> purposes >>>> I am pretty happy with the result. It has been enhancing my >> understanding >>>> of Graphics/Game programming issues while I continue to work in J. >>>> >>>> >>>> ---------------------------------------------------------------------- >>>> For information about J forums see http://www.jsoftware.com/forums.htm >>>> >>> ---------------------------------------------------------------------- >>> For information about J forums see http://www.jsoftware.com/forums.htm >> >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm