BGL question

(Manuel) #1

How I can translate this C expression in python ?

GLubyte fly[] = {0x00, 0x00, 0x00, ...

I’ve searched in BGL with the Doc Browser script,
but I don’t see GLubyte name…
because it’s a type and not a function, I think
BGL contain it, but I don’t know how I can use it…

(eeshlo) #2

Use Buffer(GL_BYTE, size), then fill the buffer with the values. GL_BYTE is handled as GL_UNSIGNED_BYTE in Blender. Although GL_UNSIGNED_BYTE is also valid, and is in BGL, I get an error when using that.


from Blender.BGL import *

# create buffer
fly = Buffer(GL_BYTE, size)
# fill the buffer with the values
# you can use hexadecimal notation in python like in C
fly[:] = [0x00, 0x00, 0x00, ...., 0x08]

(Manuel) #3

You are really a [C, python, math] guru! :smiley:

(Manuel) #4

Ok…this run without error :smiley:
I’ve used GL_BYTE because, like you, GL_UNSIGNED_BYTE
return an error…

Using GL_BYTE and not GL_UNSIGNED_BYTE can
make the script unstable? Ehm…excuse my ignorance
what is the difference between BYTE and UNSIGNED BYTE?
Why the script run fine with BYTE if in the Red Book I’ve read
the correct argument is GLubyte (GLubyte is for unsigned byte, right?)

Excuse my stupid question, but is a real effort for me to read
a english documentation, and can get a mistake in some phrases…

(eeshlo) #5

The difference between GL_BYTE and GL_UNSIGNED_BYTE is how the byte is interpreted, signed or unsigned. A signed byte is any number from -128 and 127 (note the range -> 256, 8 bits), ie. you can use negative numbers, whereas a unsigned byte is any number from 0 to 255, ie. you cannot use negative numbers. Blender handles GL_BYTE as if it was GL_UNSIGNED_BYTE (which is indeed the same as GLubyte), so it works as it should for whatever you want to do.
The difference is just how the system interpretes the number using something called ‘two’s-complement’, but just forget about that…

(Manuel) #6

Thanks… this is a good and simple explanation !! :smiley: :smiley: :smiley: