Changes in / [7145e24:cb405de] in python-game


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • game.py

    r7145e24 rcb405de  
    88[w, h] = [0, 0]
    99
    10 def render(surface, overlay, font, state):
    11    #surface.fill((0, 0, 0))
    12 
     10def render(surface, overlay, font, showOverlay):
    1311   #glEnable (GL_BLEND); glBlendFunc (GL_ONE, GL_ONE);
    1412
    15    if state:
     13   # I should really figure out which attributes in the 2D rendering
     14   # break the 3d rendering and reset those back instead of resetting
     15   # all attributes
     16   glPushAttrib(GL_ALL_ATTRIB_BITS)
     17   render3d(surface)
     18   glPopAttrib(GL_ALL_ATTRIB_BITS)
     19
     20   if showOverlay:
    1621      renderOverlay(overlay, font)
     22
     23      glPushAttrib(GL_ALL_ATTRIB_BITS)
    1724      projectOverlay(surface, overlay)
    18    else:
    19       render3d(surface)
     25      glPopAttrib(GL_ALL_ATTRIB_BITS)
    2026
    2127
     
    2430   #pygame.draw.circle(overlay, (255, 0, 0), (int(w/2), int(h/2)), 540)
    2531   #overlay.set_colorkey((255,0,0))
     32   overlay.fill((0, 0, 0, 255))
    2633
    2734   text = font.render("2D drawing", True, (0, 128, 0))
     
    3340   
    3441   glPushMatrix()
     42
     43   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
     44
    3545   glTranslatef(0.0,0.0,-zNear)
    3646
     
    4252
    4353   glBindTexture(GL_TEXTURE_2D, glGenTextures(1))
    44    # maybe use GL_RGBA here instead
    45    #glPixelStorei(GL_UNPACK_ALIGNMENT,1)
    46    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData)
     54   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData)
    4755
    4856   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
     
    146154   gameDisplay = pygame.display.set_mode((w, h), pygame.FULLSCREEN|pygame.DOUBLEBUF|pygame.OPENGL)
    147155
    148 overlay = pygame.Surface((w, h))
     156# Look into pygame.HWSURFACE for hardware-accelerated surfaces
     157overlay = pygame.Surface((w, h), pygame.SRCALPHA)
    149158
    150159pygame.display.set_caption('Space Game')
     
    155164
    156165running = True
    157 state = False
     166showOverlay = False
    158167
    159168zNear = 1.0/math.tan(math.radians(45.0/2))
     
    175184            running = False
    176185         elif event.key == pygame.K_SPACE:
    177             state = not state
     186            showOverlay = not showOverlay
    178187
    179       #print(event)
    180 
    181    render(gameDisplay, overlay, font, state)
     188   render(gameDisplay, overlay, font, showOverlay)
    182189
    183190   pygame.display.flip()
Note: See TracChangeset for help on using the changeset viewer.