This is the code that works for anyone interested.
#!/usr/bin/env python
import cairo
import pygame
import array
import math
import sys
import direct.directbase.DirectStart
from pandac.PandaModules import *
props = WindowProperties()
props.setSize(512,512)
base.win.requestProperties(props)
screen = loader.loadModel('./plane.egg.pz')
screen.setScale(2)
Width, Height = 512, 512
cairoTexture = Texture()
cairoTexture.setFormat(cairoTexture.FRgba8)
cairoTexture.setup2dTexture(Width, Height, Texture.CMDefault, Texture.FRgba)
screen.setTexture(cairoTexture)
screen.reparentTo(render2d)
def draw(surface):
x,y, radius = (250,250, 200)
ctx = cairo.Context(surface)
ctx.set_line_width(15)
ctx.arc(x, y, radius, 0, 2.0 * math.pi)
ctx.set_source_rgb(0.8, 0.8, 0.8)
ctx.fill_preserve()
ctx.set_source_rgb(1, 1, 1)
ctx.stroke()
surface = cairo.ImageSurface.create(
cairo.FORMAT_ARGB32,
Width,
Height)
def drawall(task):
draw(surface)
cairoTexture.setRamImage(surface.get_data())
return task.cont
taskMgr.add(drawall, 'draw')
run()
And if you want transparency around the circle:
#!/usr/bin/env python
import cairo
import pygame
import array
import math
import sys
import direct.directbase.DirectStart
from pandac.PandaModules import *
props = WindowProperties()
props.setSize(1024,768)
base.setBackgroundColor(0,1,1,1)
base.cam.setPos(0,-20,0)
base.win.requestProperties(props)
screen = loader.loadModel('./plane.egg.pz')
screen.setTransparency(TransparencyAttrib.MAlpha)
screen.setTwoSided(True)
screen.setScale(2)
Width, Height = 512, 512
cairoTexture = Texture()
cairoTexture.setFormat(cairoTexture.FRgba8)
cairoTexture.setup2dTexture(Width, Height, Texture.CMDefault, Texture.FRgba32)
screen.setTexture(cairoTexture)
screen.reparentTo(render)
def draw(surface):
x,y, radius = (250,250, 200)
ctx = cairo.Context(surface)
ctx.set_operator(cairo.OPERATOR_CLEAR)
ctx.rectangle(0.0, 0.0, Width, Height)
ctx.fill()
ctx.set_operator(cairo.OPERATOR_OVER)
ctx.set_line_width(15)
ctx.arc(x, y, radius, 0, 2.0 * math.pi)
ctx.set_source_rgba(0.8, 0.8, 0.8)
ctx.fill_preserve()
ctx.set_source_rgba(1, 1, 1)
ctx.stroke()
surface = cairo.ImageSurface (
cairo.FORMAT_ARGB32,
Width,
Height)
def drawall(task):
draw(surface)
cairoTexture.setRamImage(surface.get_data())
return task.cont
taskMgr.add(drawall, 'draw')
run()
EDIT: Removed some unnecessary bits to make it less confusing/more efficient.