Jump to content
  • Advertisement
Sign in to follow this  
FloreaStefan

[PYGAME - SOLVED] Problem with headless window

This topic is 2630 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am trying to make an application that will run a simulation on a headless server. In short, it does the following: 1. load an image from the database 2. display a text as an overlay on top of the image 3. capture the 'screen' and save the image back to the database The problem is that when saving the image back to the database I loose a lot of colors! But only when running the simulation headless.Here is the part where I initialize pygame and tell to create a headless application: os.environ["SDL_VIDEODRIVER"] = "dummy" pygame.init() pygame.display.set_mode((1,1)) Here is the part where I create the 'screen' buffer GS._SCREEN = pygame.Surface((640, 480)).convert()The main algorithm is something like this:def MainLoop(): GS._SCREEN.fill([255,0,0]) # clear the buffer GS._SCREEN.blit(sprite, (0,0)) # display something on the buffer pygame.image.save(GS._SCREEN, "path/to/directory") #save the image back in the database pygame.display.flip()http://www.box.net/files#/files/0/f/104328302/1/f_968101145 <- This is how the image should look likehttp://www.box.net/files#/files/0/f/104328302/1/f_968100995 <- This is how it actually looks after it is saved. As you can see it has less colors.REMARK: if am not using a headless window, the image is saved CORRECTLY!Here is the whole code:import pygameimport os# initialize headless pygameos.environ["SDL_VIDEODRIVER"] = "dummy"pygame.init()pygame.display.set_mode((1,1))# create image bufferSCREEN = pygame.Surface((640, 480)).convert()# load a simple imagesprite = pygame.image.load("Assets/Sprite/spriteTest.jpg").convert()# display it on the bufferSCREEN.blit(sprite, (0,0))# save the buffer pygame.image.save(SCREEN, "Assets/Output/spriteResult.jpg")Regards,Florea Stefan.

EDIT: It turns out that the error was in the pygame.image.load(). It did not load correctly the images. Perhaps it is a pygame bug.
If I use a different loading mechanism(PIL or OpenCV) everything works as expected.
My guess is that when using a headless application, the mechanims inside pygame.image.load() changes

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!