简体   繁体   English

Pygame 空白白屏

[英]Pygame blank white screen

I'm new to pygame and trying to simulate a table tennis table for a school project starting with just plotting the the vertices and lines.我是 pygame 的新手,并试图从绘制顶点和线开始,为学校项目模拟乒乓球桌。 When I run the code, pycharm only shows me a blank white screen in the pygame window and python doesn't give me any errors, not sure what Iv'e done wrong.当我运行代码时,pycharm 只在 pygame 窗口中向我显示一个空白的白色屏幕,python 没有给我任何错误,不确定我做错了什么。 Any suggestions?有什么建议吗?

import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *

verts = (
    (-1,-1,-1),
    (-1,-1,1),
    (-1,1,-1),
    (-1,1,1),
    (1,-1,-1),
    (1,-1,1),
    (1,1,-1),
    (1,1,1)
    )
edges = (
    (0,1),
    (0,2),
    (0,3),
    (0,4),
    (2,1),
    (2,3),
    (2,7),
    (6,3),
    (6,4),
    (6,7),
    (5,1),
    (5,4),
    (5,7)
    )
areas = (
    (0,1,2,3),
    (3,2,7,6),
    (4,5,1,0),
    (1,5,7,2),
    (4,0,3,6)
    )
def table():
    glBegin(GL_QUADS)

    for surf in areas:
        glColor3fv((0,0,255))
        for vert in surf:
            glVertex3fv(verts[vert])
    glEnd()


def main():
    pygame.init()
    display = (1000,800)
    screen = pygame.display.set_mode(display,DOUBLEBUF|OPENGL)
    gluPerspective(45,(display[0]/display[1]), 0.1,50.0)
    glTranslatef(-20,-10,-50)
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
        glRotatef(0,0,0,0)
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
        table()
        pygame.display.flip()
        pygame.time.wait(60)
        red = [255,0,0]
        screen.fill(red)
        display.fill[red]

main()

Your code indentation look bad.你的代码缩进看起来很糟糕。 Python indentation is fundamental to run a code. Python 缩进是运行代码的基础。

In your code, some function names and functions seem strange too.在您的代码中,一些函数名称和函数看起来也很奇怪。 Like call Table() for call table() (python is case sensitive) for example.就像 call Table() for call table() (python 区分大小写)例如。

Change the last three lines of def main(): from:def main():的最后三行更改为:

red = [255,0,0]
screen.fill(red)
display.fill[red]

To two lines:到两行:

glClearColor(0.7, 0, 0, 1)
glClear(GL_COLOR_BUFFER_BIT)

I don't know what you are facing, but I have run plenty of games and pygame worked very well.我不知道你面对的是什么,但我已经运行了很多游戏并且 pygame 运行得很好。

Recently my Mac did an update and screwed with python.最近我的 Mac 做了一个更新并搞砸了 python。 I pip installed pygame again, and tried running a game I created that worked very well before.我再次 pip 安装了 pygame,并尝试运行我之前创建的运行良好的游戏。 The screen was all white.屏幕全白了。 Music was working fine and the game was actually working because I could hear the sounds I attached to button presses.音乐运行良好,游戏实际上运行良好,因为我可以听到我附加到按钮按下的声音。

No logging errors show up in the terminal to explain this.终端中没有显示日志错误来解释这一点。 You would think that the game is running fine.你会认为游戏运行良好。

If your problem is like mine, somebody probably screwed up a release.如果您的问题和我的一样,那么可能是有人搞砸了发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM