-
Notifications
You must be signed in to change notification settings - Fork 0
Request: Creating an example with SDL3 #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Update: I was able to get an example by asking LLMs but it would be helpful if you could confirm if this is the correct code and doesn't contain any unnecessary code. |
Your code runs as is except with a warning that I don't think there is anything obviously "unnecessary", although it is perhaps a bit too verbose and have too much error checking code to be considered a good intro / tutorial to pysdl3. Btw, sdl2 and sdl3 (and their python bindings) can co-exist, and in fact with sdl1 too... The beginning of porting from pysdl2 to pysdl3 is simply replacing
with
near the top. Some of the APIs has small renamings and the event structure seems to have changed slightly. It would be interesting to see how much further work needs to be done to convert |
You do know that the context manager stuff is not strictly needed, right? You could replace all the |
If you don't mind, I'd like to include your example as is, if you add some copyright info, and whether you took any existing code from elsewhere, near the top as a comment. |
It might be easier to read as a basic tutorial if you remove most of the error checks, but isn't good as a full example... so it is a matter of opinion / purpose. |
I have ported the sdl2 example to sdl3 in https://github.com/HinTak/skia-python-examples/blob/main/SkiaSDL3Example.py but the old mouse positioning problem seems to be back (#7 see #3 for old fixed issue with sdl2). Your code is committed as Skia-SDL3-example which is perhaps a bit confusing - a better name (and some updated comments and copyrights)? If you want to look into the mouse offset problem (before I get round to it) with sdl3, I'd appreciate. Also please feel free to click sponsor under my profile to buy me a coffee and/or otherwise sponsor the development. |
I have renamed yours to https://github.com/HinTak/skia-python-examples/blob/main/Another-SkiaSDLExample.py and added some basic info at the top for credits. Please feel free to do a pull to update it. I have also fixed #7 and updated the code Please click the sponsor button if you appreciate the work. |
I found and fixed a bunch of small bugs in yours a4bb322 . https://github.com/HinTak/skia-python-examples/blob/main/SkiaSDL3Example.py is probably a more interesting example at this point, as it does something interesting with drawing with mouse as well as windows resizing. And as I said earlier, those context manager stuff isn't strictly-speaking needed in API examples - they allow for object re-uses and resource tidying up, but pretty much everything (surface, glcontext, windows etc) in those examples are one-off and dangling resources of singular objects are cleaned up when the program exits. The examples don't try to continue and re-use objects on failures, so all the |
Thanks for adding the example. I'm seeing an error when I run SkiaSDL3Example.py though. Here's the stack trace: Log
|
Another-SkiaSDLExample_v2.py works as expected, except that we have specified to clear canvas with white color, but I still see black background. Removing the code Are you able to reproduce this in your machine as well? |
I am afraid I am on Linux, and mostly on mesa (which is likely more opengl compliant than either windows or mac's). In general this sort of things depends a lot on the graphic card you have, as well as what graphic card driver you have. Microsoft generally wants their own thing (Direct X...). Mesa is reportedly opengl 4.5 / 4.7 compliant so setting it to 4.x probably will help on Linux. On windows you might need to play with that to get best results. Unfortunately skia actually have graphic card driver and driver version detection code... are you using skia python 87 or 1xx? See As for the erase - I get things on a black background - I am not entirely sure about the alpha channel being 1 means fully opaque or fully transparent? Try 0,0,0,0 perhaps also. Clear and paint has different meanings.... Read the doc. There is usually the concept of a foreground and a background colour, and paint means using the foreground colour, clear means flooding with the background colour (which might be implicit). And it may not necessarily be black - it could be transparent (on a "nothing" background, which defaults to black). I think things are drawn on a transparent background, btw. You can check this by outputting to png and then open the png in a image editor - it will likely tell you the background is transparent, instead of solid (opaque) black. I made some SDL2 runtime effect examples - basically fractal animations - you'd need skia-pythoh 132+ to run them. Anyway, this is about as much time as I want to right now. SDL3 was only out a few months ago. |
For your GLES2 error, try inserting these reporting lines kyamagu/skia-python#214 (comment) after your successful GL initialization program to see what opengl version etc your graphic card driver reports. |
For opengl functionality on windows, it might be a good idea to look into enabling ANGLE - kyamagu/skia-python#218 - this is a skia build option we haven't enabled. |
Thanks for responding back. I'll look into the links you provided. PS: Since you asked, I'm on skia-python=87.8. I actually didn't know that beta version was so ahead 😅 |
I'd be interested to know what opengl vendor and versions your graphic card driver reports. We have not had any info from MS windows users on that so far. So it would be interesting to know. Upstream m87 was end-of-life over 4 years ago. Skia milestone versions are generally the same as chrome versions, and we are at m136 close to m137 now. They are generally about a month apart, so it is over 4 years (50 = 4 x 12 + 2). The "beta" status is not about stability - it is about compatibility: upstream keeps changing, adding and removing APIs, and we are not 100% replacement / upgradable from m87, due to the somewhat large gap between m87 and m116 when skia-python dev stopped. If you are new to skia-python, you probably should start with m1xx, the latest "beta", as we are not sure we'll ever reach 100% upgradable / compatibility with m87. (I.e. some withdrawn m87 functionality/ API may never be re-implemented). The practical impact is small - the lost / withdrawn difference between m87 and m116 is rarely used. In fact there is some recent discussion about simply releasing m13x as next stable despite the small incompatibility / non-uogradability with m87, as it is increasing hard trying to build m87 on newer systems against newer compiler and for newer python versions... I think we'll do that for m138 or m140. |
My bad - @ajitid - the GLES2 error is just that opengl tries to load an extension value if the display has unusual endians for colour characteristics and do the right thing, which is available on Linux and mac only (I.e. everything except windows). The example code has just been updated to skip that on windows. Give the examples a try again. |
Thanks! Just tried SkiaSDL3Example.py and it works now. However when I press Esc to quit the windows closes, but the command in my terminal never exits. Does this happen to you as well? The Python process exits, but the terminal hungs up. I still am on skia-python=87.8 and pysdl3=0.9.7b9, running the progam on Windows. |
No, on Linux you can exit cleanly either by pressing esc or just closing the window (the usual button at the top corner of the window). It is supposed to be responsive to window resizing events, too - I.e it should do the right thing if you resize the window by unmaximize it, etc. But I am on skia-python 136. What sort of terminal - cmd, powershell, etc? I don't think this works under WSL2 at all? I'd think this is a sdl3 problem since that's the newest, but can you try the sdl2 example? Hmm, I think window python used to have python.exe and pythonw.exe, the latter for GUI. Lastly, I think it is possible to run python scripts inside visual studio to try to see where it got stuck. Sorry, I can help much on window-specific stuff - pretty much everything I do is largely or entirely on Linux, and it works on Linux well. I'd think that applies for the upstream c program too. (Although |
There are various tips etc on stackoverflow about sdl not shutting down properly on exit, such as this: https://stackoverflow.com/questions/56158759/why-does-sdl-doesnt-emit-sdl-quit-when-last-windows-closed and perhaps a bit more - just search "sdl hung on exit" on Google. However this sort of issue is highly OS-specific so I can't really help you further. I remember filing an issue at mono / csharp about a csharp based GUI program (ported over from windows dotnet) doesn't want to exit when it is launched in the background on Linux, but I cannot find the reference now. That's a completely different tech (c# mono / dotnet, rather than python) but it looks like mono on Linux depends on SDL2 for its GUI etc so maybe that's related. Anyway, have a look around SDL-related site about "hung on exit" and see if you can improve on it. As I said, in Linux pressing esc or just closing the window works cleanly. I have almost enough to cross-compile the c version of this, actually... but no way to test (I don't use windows), and "almost" is the word: I have the windows version of SDL libraries under Linux but not skia. |
Hi! I'm having trouble understanding how I can use skia-python with pysdl3. Could you please add an example on how Skia can use its GPU backend with SDL3?
The text was updated successfully, but these errors were encountered: