Guest User

halonot

a guest
Feb 7th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.83 KB | None | 0 0
  1. import pygame
  2. from classes.Star import Star
  3. from pygame.locals import *
  4. from OpenGL.GL import *
  5. from OpenGL.GLU import *
  6. from PIL import Image as Image
  7. import numpy
  8. stars = []
  9.  
  10.  
  11. def loadcatalogues():
  12.     with open("data/stars.speck") as starfile:
  13.         for starline in starfile:
  14.             stardata = starline.split()
  15.             hipnum = " ".join(stardata[16:])
  16.             tempstar = Star(stardata[0],stardata[1],stardata[2],stardata[3],stardata[4],stardata[5],stardata[6],stardata[7],stardata[8],stardata[9],stardata[10],stardata[11],stardata[12],stardata[13],stardata[14],stardata[15],hipnum)
  17.             stars.append(tempstar)
  18.  
  19.  
  20. def read_texture(filename):
  21.     img = Image.open(filename)
  22.     img_data = numpy.array(list(img.getdata()), numpy.int8)
  23.     textID = glGenTextures(1)
  24.     glBindTexture(GL_TEXTURE_2D, textID)
  25.     glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
  26.     #glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
  27.     #glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
  28.     #glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
  29.     #glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
  30.     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
  31.     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
  32.     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
  33.     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.size[0], img.size[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, img_data)
  34.     return textID
  35.  
  36. def main():
  37.     t = -1
  38.     loadcatalogues();
  39.     pygame.init()
  40.     display = (1920,1080)
  41.     pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
  42.     gluPerspective(45, (display[0]/display[1]), 0.1, 50.0)
  43.     glTranslatef(0.0,0.0, -2)
  44.     start = read_texture("data/halo.png")
  45.     glEnable(GL_TEXTURE_2D)
  46.     glEnable(GL_BLEND)
  47.     while True:
  48.         for event in pygame.event.get():
  49.             if event.type == pygame.QUIT:
  50.                 pygame.quit()
  51.                 quit()
  52.  
  53.         glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
  54.         #glTranslatef(0.0,0.0, t)
  55.         glBindTexture(GL_TEXTURE_2D, start)
  56.         #glTranslatef(0.0,0.0, 0.0)
  57.         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
  58.  
  59.         # Joonista asju
  60.         for star in stars:
  61.             glColor3f(star.starRGBColor()[0],star.starRGBColor()[1],star.starRGBColor()[2])
  62.             glPushMatrix()
  63.             glBegin(GL_QUADS)
  64.             glTexCoord2f(0, 0)
  65.             glVertex3f(star.x,star.y,star.z)
  66.             glTexCoord2f(0, 1)
  67.             glVertex3f(star.x,star.y+.5,star.z)
  68.             glTexCoord2f(1, 1)
  69.             glVertex3f(star.x+.5,star.y+.5,star.z)
  70.             glTexCoord2f(1, 0)
  71.             glVertex3f(star.x+.5,star.y, star.z)
  72.             glEnd()
  73.             glPopMatrix()
  74.  
  75.         pygame.display.flip()
  76.         #t+= 0.025
  77.  
  78. if __name__ == '__main__':
  79.     main()
Advertisement
Add Comment
Please, Sign In to add comment