Last active
August 29, 2015 14:08
-
-
Save pqlaz/f77418a6b92d6b974bc9 to your computer and use it in GitHub Desktop.
bgra texture trouble (kivy 1.9.0-dev)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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