demalexx
demalexx

Reputation: 4751

Convert unicode string to array of bytes

I'm using OpenGL and I need to pass to a function array of bytes.

glCallLists(len('text'), GL_UNSIGNED_BYTES, 'text');

This way it's working fine. But I need to pass unicode text. I think that it should work like this:

text = u'unicode text'
glCallLists(len(text), GL_UNSIGNED_SHORT, convert_to_array_of_words(text));

Here I use GL_UNSIGNED_SHORT that says I'll give array where each element takes 2 bytes, and somehow convert unicode text to array of words.

So, how can I convert unicode string to "raw" array of chars' numbers?

Upvotes: 0

Views: 3143

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798676

The UTF encoding that takes up 2 bytes per character is UTF-16:

print repr(u'あいうえお'.encode('utf-16be'))
print repr(u'あいうえお'.encode('utf-16le'))

Upvotes: 2

Related Questions