Changeset c8cc13f in python-game for game.py


Ignore:
Timestamp:
Apr 3, 2017, 1:22:44 AM (8 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
master
Children:
cb405de
Parents:
1af0f6d
Message:

Fix the bug with the incorrect color for the 3d rendering and slightly restructure the rendering code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • game.py

    r1af0f6d rc8cc13f  
    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
     
    1614   # break the 3d rendering and reset those back instead of resetting
    1715   # all attributes
    18    if state:
     16   glPushAttrib(GL_ALL_ATTRIB_BITS)
     17   render3d(surface)
     18   glPopAttrib(GL_ALL_ATTRIB_BITS)
     19
     20   if showOverlay:
    1921      renderOverlay(overlay, font)
     22
    2023      glPushAttrib(GL_ALL_ATTRIB_BITS)
    2124      projectOverlay(surface, overlay)
    22       glPopAttrib(GL_ALL_ATTRIB_BITS)
    23    else:
    24       glPushAttrib(GL_ALL_ATTRIB_BITS)
    25       render3d(surface)
    2625      glPopAttrib(GL_ALL_ATTRIB_BITS)
    2726
     
    3130   #pygame.draw.circle(overlay, (255, 0, 0), (int(w/2), int(h/2)), 540)
    3231   #overlay.set_colorkey((255,0,0))
     32   overlay.fill((0, 0, 0, 255))
    3333
    3434   text = font.render("2D drawing", True, (0, 128, 0))
     
    5252
    5353   glBindTexture(GL_TEXTURE_2D, glGenTextures(1))
    54    # maybe use GL_RGBA here instead
    55    #glPixelStorei(GL_UNPACK_ALIGNMENT,1)
    56    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)
    5755
    5856   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
     
    156154   gameDisplay = pygame.display.set_mode((w, h), pygame.FULLSCREEN|pygame.DOUBLEBUF|pygame.OPENGL)
    157155
    158 overlay = pygame.Surface((w, h))
     156# Look into pygame.HWSURFACE for hardware-accelerated surfaces
     157overlay = pygame.Surface((w, h), pygame.SRCALPHA)
    159158
    160159pygame.display.set_caption('Space Game')
     
    165164
    166165running = True
    167 state = False
     166showOverlay = False
    168167
    169168zNear = 1.0/math.tan(math.radians(45.0/2))
     
    185184            running = False
    186185         elif event.key == pygame.K_SPACE:
    187             state = not state
     186            showOverlay = not showOverlay
    188187
    189       #print(event)
    190 
    191    render(gameDisplay, overlay, font, state)
     188   render(gameDisplay, overlay, font, showOverlay)
    192189
    193190   pygame.display.flip()
Note: See TracChangeset for help on using the changeset viewer.