开发者

Draw shape shifting objects on (desktop)screen

开发者 https://www.devze.com 2023-03-28 01:58 出处:网络
I\'m currently developing a program to show and control animated sprites on the desktopscreen. My problem is now to actually draw them onto the screen. The user should still be able to access other ap

I'm currently developing a program to show and control animated sprites on the desktopscreen. My problem is now to actually draw them onto the screen. The user should still be able to access other applications, as long as the sprite does not obstruct it.

My attempts are below and I hope, someone can point me in the right direction. I don't really care which library I need to use, as long as the performance is good enough for something around 20-30 animated sprites.

My attempts so far:

  1. My first attempt was with Qt. I used a QWidget with a QLabel in it to show the pixmap of an object. The pixmap itself had an alpha channel and I used the "setMask(pixmap.mask()" method of QWidget to remove anything I don't want to show. But this method can't be used for rapidly shifting shapes, like moving creatures. If setMask is called all 50-100ms to change the mask to the next movementphase, then the cpu load gets to high with a lot of creatures moving at the same time.

  2. My second attempt was to use one QWidget for all creatures. This way setMask ist called only one time and not once for every creature. It's possible to move mor开发者_StackOverflow中文版e creatures this way, but the screen is flickering like hell when moving the mouse pointer over the creatures.

  3. My third attempt were the XShape functions from Xlib to change the shape of each creature, but the performance is not much better then setMask.

  4. I tried the transparency in Qt but if I use a QWidget over the whole screen the cpu load of X gets really high while moving the mouse. I don't know, if I can do something better here.


Create a QGLWidget and learn to use the OpenGL API to draw sprites within it, even if only using glDrawPixels rather than texture objects.

You certainly won't have any problems drawing a few tens of sprites, and the time spent learning OpenGL will be a good investment if you aspire to do more complex graphical things in future.


Not sure if this is your language but the ESheep is on GitHub, could get you started: https://github.com/Adrianotiger/desktopPet

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号