Mikowww
Mikowww

Reputation: 61

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

Upvotes: 1

Views: 4030

Answers (3)

Michael Tamillow
Michael Tamillow

Reputation: 425

I don't know what you are facing, but I have run plenty of games and pygame worked very well.

Recently my Mac did an update and screwed with python. I pip installed pygame again, and tried running a game I created that worked very well before. 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.

Upvotes: 0

SF12 Study
SF12 Study

Reputation: 385

Change the last three lines of def main(): from:

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

To two lines:

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

Upvotes: 1

Psycho Mantys
Psycho Mantys

Reputation: 33

Your code indentation look bad. Python indentation is fundamental to run a code.

In your code, some function names and functions seem strange too. Like call Table() for call table()(python is case sensitive) for example.

Upvotes: 1

Related Questions