Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8484373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:21:49+00:00 2026-06-10T20:21:49+00:00

I currently have some code that draws using pycairo and renders to an SDL

  • 0

I currently have some code that draws using pycairo and renders to an SDL surface by way of PyGame. This works nicely on Linux and Windows but the Mac is giving me headaches. Everything just comes out blue or pink The byte order seems to be BGRA instead of ARGB and I have tried using pygame.Surface.set_masks and set_shifts to no avail. This is only broken on the mac (osx 10.6):

import cairo
import pygame

width = 300
height = 200

pygame.init()
pygame.fastevent.init()
clock = pygame.time.Clock()
sdl_surface = pygame.display.set_mode((width, height))

c_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
ctx = cairo.Context(c_surface)

while True:
    pygame.fastevent.get()
    clock.tick(30)
    ctx.rectangle(10, 10, 50, 50)
    ctx.set_source_rgba(0.0, 0.0, 0.0, 1.0)
    ctx.fill_preserve()

    dest = pygame.surfarray.pixels2d(sdl_surface)
    dest.data[:] = c_surface.get_data()
    pygame.display.flip()

I can fix it with array slicing or using PIL but this kills my frame rate. Is there a way to do this in-place or with settings?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:21:50+00:00Added an answer on June 10, 2026 at 8:21 pm

    After a lot of hair tearing I have a workaround that does not hurt my frame rate too much by simply reversing the array:

    import cairo
    import pygame
    
    width = 300
    height = 200
    
    pygame.init()
    pygame.fastevent.init()
    clock = pygame.time.Clock()
    sdl_surface = pygame.display.set_mode((width, height))
    
    c_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
    ctx = cairo.Context(c_surface)
    
    while True:
        pygame.fastevent.get()
        clock.tick(30)
        ctx.rectangle(10, 10, 50, 50)
        ctx.set_source_rgba(1.0, 0.0, 0.0, 1.0)
        ctx.fill_preserve()
    
        dest = pygame.surfarray.pixels2d(sdl_surface)
        dest.data[:] = c_surface.get_data()[::-1]
        tmp = pygame.transform.flip(sdl_surface, True, True)
        sdl_surface.fill((0,0,0))    #workaround to clear the display
        del dest     #this is needed to unlock the display surface
        sdl_surface.blit(tmp, (0,0))
        pygame.display.flip()
    

    The fact that I have to delete the array and blit from a temporary Surface does not seem right but it was the only way to flip the display. If anyone has a cleaner suggestion here, please comment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that currently checks for minimum and maximum lentgh. I want
I have some python code that currently performs expensive computation by performing the computation
I'm using Zend_Search_Lucene, the PHP port of Java Lucene. I currently have some code
I have some code which I'm currently using to change the static-IP of a
I currently using android NDK to write some native code in C. I have
So I'm working on some HTML5 code using HAML and SASS. I currently have
I have some code that gets the current logged in user. userID = request.session.get(_auth_user_id)
I currently have some code which when you press the submit button, a marker
Currently, I have some code as follows template<typename Type> Type* getValue(std::string name, bool tryUseGetter
I am currently messing around with some code for an advertising network, i have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.