Skip to content

Instantly share code, notes, and snippets.

@pqlaz
Last active August 29, 2015 14:08
Show Gist options
  • Save pqlaz/f77418a6b92d6b974bc9 to your computer and use it in GitHub Desktop.
Save pqlaz/f77418a6b92d6b974bc9 to your computer and use it in GitHub Desktop.
bgra texture trouble (kivy 1.9.0-dev)
import os
os.environ['KIVY_GLES_LIMITS'] = '0'
from cairo import Context, ImageSurface, FORMAT_ARGB32, FONT_SLANT_NORMAL, FONT_WEIGHT_NORMAL
from kivy.app import App
from kivy.core.image import ImageData
from kivy.graphics import Color, Rectangle
from kivy.graphics.opengl_utils import gl_has_texture_format, gl_get_texture_formats, gl_has_texture_native_format
from kivy.graphics.texture import Texture
from kivy.uix.widget import Widget
class MyWidget(Widget):
def __init__(self, **kwargs):
super(MyWidget, self).__init__(**kwargs)
print '*' * 40
print '\n'.join(repr((x, gl_has_texture_format(x))) for x in gl_get_texture_formats())
print 'gl_has_texture_native_format("bgra"): {0}'.format(gl_has_texture_native_format('bgra'))
print '*' * 40
width, height = 320, 240
surface = ImageSurface(FORMAT_ARGB32, width, height)
context = Context(surface)
context.set_source_rgb(1, .2, .2)
context.select_font_face("Sans", FONT_SLANT_NORMAL, FONT_WEIGHT_NORMAL)
context.set_font_size(40)
context.move_to(50, 120)
context.show_text('Hello, world!')
data = bytes(surface.get_data())
# data = surface.get_data()
img_data = ImageData(width, height, 'bgra', data)
# img_data = ImageData(width, height, 'rgba', data)
texture = Texture.create_from_data(img_data)
texture.flip_vertical()
with self.canvas:
Color(.5, .5, .5)
Rectangle(size=(640, 480))
Color(1., 1., 1.)
Rectangle(pos=(160, 120), size=(width, height), texture=texture)
app = App()
app.root = MyWidget()
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment