Changeset a7d1e5e in python-game for game.py


Ignore:
Timestamp:
Apr 4, 2017, 1:36:04 AM (8 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
master
Children:
a7f54e3, c56629f
Parents:
3511899 (diff), cb405de (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of http://medievaltech.com/git/python-game

File:
1 edited

Legend:

Unmodified
Added
Removed
  • game.py

    r3511899 ra7d1e5e  
    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.