我如何 draw/work 与 python 中的像素与 opengl/pyglet 并更改此像素的大小?

How can I draw/work with pixels in python with opengl/pyglet and change sizes of this pixels?

我需要绘制像素然后改变它们的大小,所以一个显示像素包含9个程序像素

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()

我收到这个错误

glDrawPixels(W, H, GL_RGB, GL_UNSIGNED_INT, data)
ctypes.ArgumentError: argument 5: : wrong type

传递给 glDrawPixels 的数据必须是 GLuint 个值的数组,而不是嵌套的值列表。
如果您想通过 [0, 255] 范围内的整数值定义颜色通道,则必须使用数据类型 GLubyte 和相应的 OpenGL 枚举常量 GL_UNSIGNED_BYTE 而不是 GL_UNSIGNED_INT.

例如

data = [random.randint(0, 255) for _ in range (0, H*W*3)]
glDrawPixels(W, H, GL_RGB, GL_UNSIGNED_BYTE, (GLubyte * len(data))(*data))

如果您要分别使用 GLuint GL_UNSIGNED_INT,则整体颜色通道必须在 [0, 2147483647]:

范围内

例如

data = [random.randint(0, 2147483647) for _ in range (0, H*W*3)]
glDrawPixels(W, H, GL_RGB, GL_UNSIGNED_INT, (GLuint * len(data))(*data))