How do i draw an image from an array in pyglet

Question:

I working on a voxel engine based using raycasting. But i need a way to display my frame who is a nested list like that (100x100x3). The only idea i had was to create an image in pyglet using pyglet.image.create(width,height) and to next modifie it’s data using image.set_data("RGB",width*3,data). But the problem i have is how to organize my data create like that : numpy.zeros([100,100,3]) to be used in set_data(). I have try data.tobytes() or ctypes but i always get an image glitter with random particules.

Asked By: Druide

||

Answers:

See numpy.zeros. numpy.zeros([100,100,3]) generates an array of floats. You should generate an array of uint8:

numpy.zeros([100,100,3])

numpy.zeros([100,100,3], dtype = numpy.uint8)
Answered By: Rabbid76
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.