pyopengl 上的 gldrawpixels 没有绘制任何东西?
gldrawpixels on pyopengl not drawing anything?
我创建了要使用 glDrawPixels 绘制的像素缓冲区。代码 运行 正常,pygame window 出现。但是没有什么可画的,只显示了空白 window。即使我改变缓冲区的值,它也不会绘制任何东西。
import pygame
from OpenGL.GL import *
#initiliaze pixel buffers
buffer = bytearray(800 * 600 * 3)
for i in range(800 * 600 * 3):
buffer[i] = 25
def main():
pygame.init()
display = (800,600)
pygame.display.set_mode(display, pygame.DOUBLEBUF| pygame.OPENGL)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
glClear(GL_COLOR_BUFFER_BIT)
glDrawPixels(800, 600, GL_RGB, GL_UNSIGNED_BYTE, buffer)
pygame.time.wait(10)
main()
有什么帮助吗?
您错过了 pygame.display.flip()
更新显示。当显示器是 OPENGL
显示器时,这将执行缓冲区交换:
import pygame
from OpenGL.GL import *
windowsize = (800,600)
# create 800x600 buffer with RED color
buffer = bytearray(windowsize[0] * windowsize[1] * 3)
for i in range(windowsize[0] * windowsize[1]):
buffer[i*3] = 255
buffer[i*3+1] = 0
buffer[i*3+2] = 0
def main():
pygame.init()
# create `OPENGL`, `DOUBLEBUF` display
pygame.display.set_mode(windowsize, pygame.DOUBLEBUF| pygame.OPENGL)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
# set BLACK clear color and clear the color plane
glClearColor(0, 0, 0, 1)
glClear(GL_COLOR_BUFFER_BIT)
# draw buffer to dispaly
glDrawPixels(*windowsize, GL_RGB, GL_UNSIGNED_BYTE, buffer)
# update display
pygame.display.flip() # <----- swap buffers
pygame.time.wait(10)
main()
我创建了要使用 glDrawPixels 绘制的像素缓冲区。代码 运行 正常,pygame window 出现。但是没有什么可画的,只显示了空白 window。即使我改变缓冲区的值,它也不会绘制任何东西。
import pygame
from OpenGL.GL import *
#initiliaze pixel buffers
buffer = bytearray(800 * 600 * 3)
for i in range(800 * 600 * 3):
buffer[i] = 25
def main():
pygame.init()
display = (800,600)
pygame.display.set_mode(display, pygame.DOUBLEBUF| pygame.OPENGL)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
glClear(GL_COLOR_BUFFER_BIT)
glDrawPixels(800, 600, GL_RGB, GL_UNSIGNED_BYTE, buffer)
pygame.time.wait(10)
main()
有什么帮助吗?
您错过了 pygame.display.flip()
更新显示。当显示器是 OPENGL
显示器时,这将执行缓冲区交换:
import pygame
from OpenGL.GL import *
windowsize = (800,600)
# create 800x600 buffer with RED color
buffer = bytearray(windowsize[0] * windowsize[1] * 3)
for i in range(windowsize[0] * windowsize[1]):
buffer[i*3] = 255
buffer[i*3+1] = 0
buffer[i*3+2] = 0
def main():
pygame.init()
# create `OPENGL`, `DOUBLEBUF` display
pygame.display.set_mode(windowsize, pygame.DOUBLEBUF| pygame.OPENGL)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
# set BLACK clear color and clear the color plane
glClearColor(0, 0, 0, 1)
glClear(GL_COLOR_BUFFER_BIT)
# draw buffer to dispaly
glDrawPixels(*windowsize, GL_RGB, GL_UNSIGNED_BYTE, buffer)
# update display
pygame.display.flip() # <----- swap buffers
pygame.time.wait(10)
main()