I currently have an application running under Ubuntu 14.04 using SDL 2.03 and have a few questions .
Currently the window / rendering / event handler are running in a thread , not the main program. This works fine as long as the window is initiated (created) in the thread , and the rendering / event handling is also done in the thread , which is what the SDL documentation also states.
My question is if there is one window / rendering / event handler in a thread , and another window / renderer / event handler is created in the main program can two event handlers function properly.
I can easily create another window / renderer / handler in the main program for the new window , but the question is can there be two event handlers in SDL 2.xx ?
It appears (though I can't find any documentation / forums that actually states this) that SDL 2.03 only allows one event handler.
When the event handler (only one handler) is put in a thread , the event can be detected from different windows , those created in the thread and those created in the main thread (program) , by using SDL_GetWindowID() to get the identify of a window (WindowID) and later use it to recognize which window generated the event.
On 02/02/2015 03:54 PM, Brian wrote:
> When the event handler (only one handler) is put in a thread , the event can
> be detected from different windows , those created in the thread and those
> created in the main thread (program) , by using SDL_GetWindowID() to get the
> identify of a window (WindowID) and later use it to recognize which window
> generated the event.
I suppose this will make the user software rather complicated.
The events assiciated with a window obviously are callbacks that run in
the thread that is associated to that window (which does make a lot of
I suppose you use TThread to generate the thread(s).
So you can find out where you are either by the the TThread "Self"
pointer provided by fpc (so most of the association is just automatic),
by the OS thread ID or by the SDL WindowID.
Threading problems will need to be cared for when trying to move any
information from one Thread (=Window) to another.
In Lazarus there always is only one "MainThread", associated to one
"MainWindow". As the LCL library in not thread save in itself, you can't
have multiple "Main" Windows in a program.
Without using the LCL, I suppose you can do such thing, but to generate
a decent GUI, you will need to implement an event queue for each
Window/Thread to allow user code to take advantage of the SDL functions
Threading SDL 2.03 is not particularly difficult if you observe the rules that a texture/renderer must reside in the same thread that created the window and (it appears) there is only one event (which as you mentioned makes sense) , and in my case the event handler is in a thread.
SDL 2.03 has some very nice features which were not available in SDL 1.xx such as TEXTURE.
I noticed quite a few posts on different forums asking how to do animation , and several posts mentioned that an early version of Doom had used SDL 1.xx to blit multiple surfaces to create the animation effects.
One method of extremely fast animation is to use the example here as the basis. Although the example is not animation the underlying use of CPU memory and textures is 100% applicable to animation.