[英]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: 參數 5: : 錯誤類型
傳遞給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))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.