This is what I have done on linux jconsole.
It needs an additional Enter key to show the 3 spaces prompt, I don't know
why yet.
On Fri, Dec 4, 2020 at 9:07 AM bill lam <[email protected]> wrote:
> I had only tested it on jconsole, I think it is better to check for event
> using SDL_WaitEvent
>
> On Fri, Dec 4, 2020, 2:16 AM Thomas McGuire <[email protected]> wrote:
>
>> Thanks Bill it worked like a charm I changed
>> SDL_CreateWindow =: (SDLDLL, ' SDL_CreateWindow * &c i i i i i')&cd
>>
>> To:
>> SDL_CreateWindow =: (SDLDLL, ' SDL_CreateWindow * *c i i i i i')&cd
>>
>> And the garbage in the SDL2 created window title is gone. I don’t know
>> why I put the ‘&' in there, as most of the calls in the DLL wrapper use
>> regular pointers.
>>
>> ———————
>>
>> Michael Day wrote:
>> " think you've already said you can't close the graphic yet”
>>
>> That latest script I sent with the timer routine picks up the
>> SDL_QuitEvent at least under MacOS. The window will disappear. The problem
>> now is I have to close and reopen the entire J session to make it work
>> again. If I call the function to display the window, the birdie appears but
>> no events get picked up and the window will stay open. Kill J and restart,
>> the window appears and will disappear when you press the built in quit
>> button on the window header.
>>
>> Tom McGuire
>>
>>
>> > On Dec 3, 2020, at 11:43 AM, bill lam <[email protected]> wrote:
>> >
>> > Garbage because the string is not null terminated. Use *c instead &c
>> unless
>> > you know what you are doing.
>> >
>> > On Thu, Dec 3, 2020 at 8:53 PM 'Michael Day' via Programming <
>> > [email protected]> wrote:
>> >
>> >> Thanks - I've been trying to get this to work in J902 under Windows.
>> >> Partial success
>> >> at last today with these latest text-files.
>> >>
>> >> Please note that each text script has two gratuitous extra lines,
>> those in
>> >> the J-forum message footer:
>> >>
>> <<----------------------------------------------------------------------
>> >> For information about J forums see http://www.jsoftware.com/forums.htm
>> >>
>> >>
>> >> I needed to change these OS- or installation-dependent definitions:
>> >>
>> >> NB. in your sdl2.txt, renamed to ...ijs ...
>> >> NB. SDLDLL =: '/usr/local/lib/libSDL2.dylib'
>> >> SDLDLL =: 'c:/sdl2/sdl2.dll'
>> >>
>> >> NB. and in your sdlbmpevtex.txt renamed to ...ijs ...
>> >> NB. WAS :- load '~/j902-user/temp/sdl2.ijs'
>> >> load '~user/sdl2.ijs'
>> >> ....
>> >> NB. WAS:- bmpsurf=: {. SDL_LoadBMP
>> >> <'/Applications/j902/addons/graphics/bmp/toucan.bmp'
>> >> bmpfile=. fullname_j_'~addons/graphics/bmp/toucan.bmp'
>> >> bmpsurf=: {. SDL_LoadBMP < bmpfile
>> >>
>> >> I eventually saw the birdie once I'd got that last path correct after
>> >> some earlier mistakes.
>> >>
>> >> I think you've already said you can't close the graphic yet. I don't
>> >> know about linux or unix, but
>> >> in this Windows OS, the only way to close it appears to use "End Task"
>> >> in Windows Task Manager;
>> >> Task Manager shows the graphic/s as subtask/s - closing this/one of
>> >> these closes the whole J session.
>> >>
>> >> My latest Toucan has garbage in its title: "SDL2 from J�����⎕
>> {club}∨"
>> >> (approximately)
>> >> suggesting there might be some problem with the &c argument to
>> >> SDL_CreateWindow. The added
>> >> characters seem to be arbitrary, as might be expected if the length is
>> >> wrong.
>> >>
>> >> But the Toucan appeared! I'm old enough to remember the Guinness (I
>> >> think) ad's slogan, along the
>> >> lines of "Toucan do what toucan do."
>> >>
>> >> Cheers,
>> >>
>> >> Mike
>> >>
>> >>
>> >> On 03/12/2020 01:04, Thomas McGuire wrote:
>> >>
>> >>
>> >> --
>> >> This email has been checked for viruses by Avast antivirus software.
>> >> https://www.avast.com/antivirus
>> >>
>> >> ----------------------------------------------------------------------
>> >> 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
>>
>
NB. sdlbmpevtex.ijs - example of setting up a bitmap displayed in window
NB. under SDL with QUIT event processing
load '~/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 <jpath '~/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
sdleventhdlr''
)
sdleventhdlr =: 3 : 0
done=. 0
while. (-.done) *. 0~:SDL_WaitEvent <<ev do.
evtype =: {. 0 (3!:4) memr ev,0,32
echo evtype
select. evtype
case. SDL_QUIT do.
done=. 1
end.
end.
sdlfullquit''
)
sdlfullquit =: 3 : 0
SDL_DestroyTexture<texture
texture =: null
SDL_DestroyRenderer<renderer
renderer =: null
SDL_DestroyWindow <window
window =: null
SDL_Quit ''
memf ev
ev =: 0
)
sdlbmpevtex''
NB. SDL utilities for OpenGL
require 'dll'
void=: 0$''
null=: <0
NB. SDLDLL =: '/usr/local/lib/libSDL2.dylib'
SDLDLL =: 'libSDL2-2.0.so.0'
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_WaitEvent =: (SDLDLL, ' SDL_WaitEvent > i *')&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
)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm