如何使用opengl/pyglet在python中绘制/使用像素并更改这些像素的大小?
我需要画像素,然后改变它们的大小,所以一个显示像素包含9个程序像素如何使用opengl/pyglet在python中绘制/使用像素并更改这些像素的大小?,python,opengl,pyglet,Python,Opengl,Pyglet,我需要画像素,然后改变它们的大小,所以一个显示像素包含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
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\u RGB、GL\u UNSIGNED\u INT、data)
ctypes.ArgumentError:参数5::错误类型
传递给
glDrawPixels
的数据必须是GLuint
值的数组,而不是嵌套的值列表。如果要通过[0255]范围内的整数值定义颜色通道,则必须使用数据类型
GLubyte
和相应的OpenGL枚举器常量GL\u UNSIGNED\u BYTE
,而不是GL\u UNSIGNED\u INT
e、 g
data=[random.randint(0,255)表示范围(0,H*W*3)]
GLDRAW像素(W、H、GL_RGB、GL_无符号字节,(GLubyte*len(数据))(*data))
如果要分别使用GLuint
GL\u UNSIGNED\u INT
,则积分颜色通道必须在范围[0,2147483647]内:
e、 g
data=[random.randint(02147483647)表示uu在范围(0,H*W*3)内]
glDrawPixels(W、H、GL_RGB、GL_UNSIGNED_INT,(GLuint*len(数据))(*data))