I need to draw pixels and then change their sizes, so one display pixel contains 9 program pixels
import random
from pyglet.gl import *
from OpenGL.GLUT import *
win = pyglet.window.Window()
@win.event
def on_draw():
W = 200
H = 200
glClearColor(0, 0, 0, 1)
glClear(GL_COLOR_BUFFER_BIT)
data = [[[0] * 3 for j in range(W)] for i in range(H)]
for y in range (0, H):
for x in range (0, W):
data[y][x][0] = random.randint(0, 255)
data[y][x][1] = random.randint(0, 255)
data[y][x][2] = random.randint(0, 255)
glDrawPixels(W, H, GL_RGB, GL_UNSIGNED_INT, data)
glutSwapBuffers()
pyglet.app.run()
I get this error
glDrawPixels(W, H, GL_RGB, GL_UNSIGNED_INT, data)
ctypes.ArgumentError: argument 5: : wrong type
The data which are passed to glDrawPixels
has to be an array of GLuint
values, rather than a nested list of values.
If you want to define the color channels by integral values in the range [0, 255], then you've to use the data type GLubyte
and the corresponding OpenGL enumerator constant GL_UNSIGNED_BYTE
rather than GL_UNSIGNED_INT
.
eg
data = [random.randint(0, 255) for _ in range (0, H*W*3)]
glDrawPixels(W, H, GL_RGB, GL_UNSIGNED_BYTE, (GLubyte * len(data))(*data))
If you would use GLuint
respectively GL_UNSIGNED_INT
anyway, then the integral color channels have to be in range [0, 2147483647]:
eg
data = [random.randint(0, 2147483647) for _ in range (0, H*W*3)]
glDrawPixels(W, H, GL_RGB, GL_UNSIGNED_INT, (GLuint * len(data))(*data))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.