def init(self): self.angle = 10 self.framerate = 20 self.vertex_shader = glesutils.VertexShader(vertex_glsl) self.fragment_shader = glesutils.FragmentShader(fragment_glsl) self.program1 = glesutils.Program(self.vertex_shader, self.fragment_shader) self.program1.use() glClearDepthf(1.0) glDepthFunc(GL_LESS) glEnable(GL_DEPTH_TEST) glFrontFace(GL_CW) glClearColor(0.5, 0.5, 0.5, 1) self.program1.uniform.light_dir.value = ((0, 1, -1)) self.verteces_buffer = array_spec.create_buffer(vertex_attrib=vertices) for face in faces: face["element_buffer"] = glesutils.ElementBuffer(face["vertex_index"]) self.outer_matrix = transforms.compose(transforms.rotation_degrees(20, "z"), transforms.rotation_degrees(20, "y"), transforms.rotation_degrees(20, "x"), transforms.scaling(1.2)) self.points_matrix = transforms.compose(transforms.stretching(0.1, 1, 1.5), transforms.translation(-0.5, -0.5, -0.5))
def init(self): vertices, indices = make_sphere(3) print(len(indices)) self.drawing = array_spec.make_drawing(vertex_attrib=vertices, elements=indices) vertex_shader = glesutils.VertexShader(vertex_glsl) fragment_shader = glesutils.FragmentShader(fragment_glsl) program = glesutils.Program(vertex_shader, fragment_shader) self.program = program program.use() glClearDepthf(1.0) glDepthFunc(GL_LESS) glEnable(GL_DEPTH_TEST) glEnable(GL_CULL_FACE) glFrontFace(GL_CW) glClearColor(1, 0, 0, 1) # program.uniform.mvp_mat.load(transforms.rotation_degrees(45, "z")) program.uniform.mvp_mat.value = transforms.identity program.uniform.light_dir.value = (0, 1, -1) program.uniform.texture.value = 0 img = pygame.image.load("world_cube_net.png") self.texture = glesutils.Texture.from_surface(glesutils.split_cube_map(img), cubemap=True) self.texture.bind(0) print(glGetString(GL_VENDOR)) print(glGetString(GL_VERSION)) print(glGetString(GL_EXTENSIONS))
def init(self): vertex_shader = glesutils.VertexShader(vertex_glsl) fragment_shader = glesutils.FragmentShader(fragment_glsl) program = glesutils.Program(vertex_shader, fragment_shader) self.program = program program.use() glClearDepthf(1.0) glDepthFunc(GL_LESS) glEnable(GL_DEPTH_TEST) glEnable(GL_CULL_FACE) glFrontFace(GL_CW) glClearColor(1, 0, 0, 1) program.uniform.mvp_mat.value = transforms.identity program.uniform.light_dir.value = normalize((0, 1, -1)) program.uniform.texture.value = 0 self.vbo = array_spec.create_buffer(vertex_attrib=vertices) self.elem_vbo = glesutils.ElementBuffer(indices) img = pygame.image.load("cubenormal.png") self.texture = glesutils.Texture.from_surface( glesutils.split_cube_map(img), cubemap=True) self.texture.bind(0) print(glGetString(GL_VENDOR)) print(glGetString(GL_VERSION)) print(glGetString(GL_EXTENSIONS)) print("Total VBO size: %gKb" % ((self.vbo.byte_size + self.elem_vbo.byte_size) / 1024.0))
def init(self): self.angle_x = 5 self.angle_y = 10 self.angle_z = 5 self.framerate = 20 self.counter = 0 self.vertex_shader = glesutils.VertexShader(vertex_glsl) self.fragment_shader = glesutils.FragmentShader(fragment_glsl) self.program1 = glesutils.Program(self.vertex_shader, self.fragment_shader) self.program1.use() glClearDepthf(1.0) glDepthFunc(GL_LESS) glEnable(GL_DEPTH_TEST) glClearColor(0.0, 0.0, 0.0, 1) self.program1.uniform.light_dir.value = ((0, 1, -1)) self.verteces_buffer = array_spec.create_buffer(vertex_attrib=vertices) self.points_buffer = array_spec.create_buffer( vertex_attrib=vertices_points) self.elements_outer = glesutils.ElementBuffer(indices_outer) self.elements_points = glesutils.ElementBuffer(indices_points) self.blank_matrix = transforms.translation(0.0, 0.0, 0.0) self.position_matrix = [] for i in range(0, 20): self.position_matrix.append( transforms.translation((i / 10) - 0.95, 0.0, 0.0)) self.sound_matrix = [] for i in range(0, 20): self.sound_matrix.append(transforms.translation(0.0, 0.0, 0.0)) self.program1.uniform.scaling_matrix.value = transforms.scaling(0.1) self.program1.uniform.eye_matrix.value = transforms.compose( transforms.rotation_degrees(self.angle_z, "z"), transforms.rotation_degrees(self.angle_x, "y"), transforms.rotation_degrees(self.angle_x, "x"), transforms.translation(0.0, -0.9, 0.0)) self.counter = 0
def init(self): """All setup which requires the OpenGL context to be active.""" # compile vertex and fragment shaders vertex_shader = glesutils.VertexShader(vertex_glsl) fragment_shader = glesutils.FragmentShader(fragment_glsl) # link them together into a program program = glesutils.Program(vertex_shader, fragment_shader) # set the background to RGBA = (1, 0, 0, 1) (solid red) glClearColor(1, 0, 0, 1) # set up pre-multiplied alpha glEnable(GL_BLEND) glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA) # load uniforms self.mvp_mat = program.uniform.mvp_mat self.mvp_mat.value = transforms.rotation_degrees(self.angle, "z") # bind uniform named "texture" to texture unit 1 # normally, when using only one texture, 0 would be more logical, # but this is just for demo purposes program.uniform.texture.value = 1 # bind texture to texture unit 1 # data for the three vertices positions = ((0, 0), (0, 1), (1, 1), (1, 0)) elements = (0, 1, 2, 0, 2, 3) # create an array buffer from the spec # note: all buffer objects are automatically bound on creation self.drawing = array_spec.make_drawing(vertex_attrib=positions, elements=elements) texture_data = glesutils.TextureData.from_file("apple.png") self.texture = glesutils.Texture.from_data(texture_data) print("Texture size: %dx%d" % (texture_data.width, texture_data.height)) # use the program, bind the texture program.use() self.texture.bind(program.uniform.texture.value) # print some OpenGL implementation information version = glesutils.get_version() for k in version.__dict__: print("%s: %s" % (k, getattr(version, k)))
def init(self): """All setup which requires the OpenGL context to be active.""" # compile vertex and fragment shaders vertex_shader = glesutils.VertexShader(vertex_glsl) fragment_shader = glesutils.FragmentShader(fragment_glsl) # link them together into a program program1 = glesutils.Program(vertex_shader, fragment_shader) program2 = glesutils.Program(vertex_shader, fragment_shader) # use the program program1.use() program1.uniform.color.value = (1, 0, 0, 1) program2.use() program2.uniform.color.value = (0, 1, 0, 1) self.program1 = program1 self.program2 = program2 glClearColor(0, 0, 0, 1) self.drawing1 = array_spec.make_drawing(vertex_attrib=[(0, 0), (0, 1), (1, 0)]) self.drawing2 = array_spec.make_drawing(vertex_attrib=[(0, 0), (0, -1), (-1, 0)])
def start(self): dt = str(datetime.datetime.now()) script_path = os.path.dirname(os.path.realpath(__file__)) self.pic_log = open("%s/pictures_%s.txt" % (script_path, dt), 'w') #pygame.mouse.set_visible(False) # compile vertex and fragment shaders vertex_shader = glesutils.VertexShader(vertex_glsl) fragment_shader = glesutils.FragmentShader(fragment_glsl) # link them together into a program self.program = glesutils.Program(vertex_shader, fragment_shader) # set the background to RGBA = (1, 0, 0, 1) glClearColor(green[0] / 255.0, green[1] / 255.0, green[2] / 255.0, 1) # set up pre-multiplied alpha glEnable(GL_BLEND) glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA) # load uniforms self.mvp_mat = self.program.uniform.mvp_mat # bind uniform named "texture" to texture unit 1 # normally, when using only one texture, 0 would be more logical, # but this is just for demo purposes self.program.uniform.texture.value = 1 # bind texture to texture unit 1 positions = ((0, 0), (0, 1), (1, 1), (1, 0)) elements = (0, 1, 2, 0, 2, 3) # create an array buffer from the spec # note: all buffer objects are automatically bound on creation self.drawing = array_spec.make_drawing(vertex_attrib=positions, elements=elements) ### cache text overlays ### gap above and beloy images self.gap = gap = int((self.height - (self.width / 1.5)) / 4) font_file = "%s/font.ttf" % os.path.dirname(os.path.realpath(__file__)) numfont = pygame.font.Font(font_file, 200) info_font = pygame.font.Font(font_file, 60) med_info_font = pygame.font.Font(font_file, 54) ### count down numbers self.cd = [] for i in range(4): surf = numfont.render("%d" % (i), 0, green, pink) texture = Texture(surf, self) self.cd.append(texture) ### cache info texts s_left_button = med_info_font.render("LEFT BUTTON TAKES 1 PHOTO", 0, pink, green) self.text_left_button = Texture(s_left_button, self) s_right_button = med_info_font.render("RIGHT BUTTON TAKES 4 PHOTOS", 0, pink, green) self.text_right_button = Texture(s_right_button, self) s_text_look = info_font.render("* LOOK AT CAMERA *", 0, pink, green) self.text_look = Texture(s_text_look, self) self.text_look.set_target_size(s_text_look.get_width(), s_text_look.get_height()) s_text_wake = info_font.render("* PRESS BUTTON TO WAKE *", 0, pink, green) self.text_wake = Texture(s_text_wake, self) surf_text_press_button = info_font.render("* PRESS BUTTON TO EXIT *", 0, green, pink) self.text_press_button = Texture(surf_text_press_button, self) small_info_font = pygame.font.Font(font_file, 25) surf_text_website = small_info_font.render( "PHOTOS ONLINE @ HTTP://EMMAISGOINGTOMARRY.ME BY 1ST OF JULY", 0, green, pink) self.text_website = Texture(surf_text_website, self) surf_text_taking = info_font.render("TAKING PHOTOS", 0, green, pink) self.text_taking = Texture(surf_text_taking, self) ### create Snappy object with preview disabled self.snappy = Snappy() self.snappy.disable_preview() self.snappy.start() ### enable the preview self.snappy.enable_preview() self.last_action = time.time()
def init(self): """All setup which requires the OpenGL context to be active.""" self.currentScenario = 0 self.animation = [] self.okpressed = 0 self.kopressed = 0 self.preload = False # compile vertex and fragment shaders vertex_shader = glesutils.VertexShader(vertex_glsl) fragment_shader = glesutils.FragmentShader(fragment_glsl) # link them together into a program program = glesutils.Program(vertex_shader, fragment_shader) # set the background to RGBA = (1, 0, 0, 1) (solid red) glClearColor(1, 0, 0, 0) # set up pre-multiplied alpha glEnable(GL_BLEND) glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA) #glDisable(GL_DEPTH_TEST) # load uniforms self.mvp_mat = program.uniform.mvp_mat self.mvp_mat.value = transforms.rotation_degrees(0, "z") # bind uniform named "texture" to texture unit 1 # normally, when using only one texture, 0 would be more logical, # but this is just for demo purposes program.uniform.texture.value = 0 # bind texture to texture unit 1 program.uniform.alpha.value = 1.0 self.actual_w_to_h_ratio = float(self.width) / float(self.height) print("WtoH ratio", self.actual_w_to_h_ratio) # data for the three vertices y_min = 0.70 positions = ((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)) elements = (0, 1, 2, 0, 2, 3) # create an array buffer from the spec # note: all buffer objects are automatically bound on creation self.drawing = array_spec.make_drawing(vertex_attrib=positions, elements=elements) # use the program, bind the texture program.use() self.program = program # print some OpenGL implementation information version = glesutils.get_version() for k in version.__dict__: print("%s: %s" % (k, getattr(version, k))) self.base_matrix = transforms.scaling(2) self.base_matrix = transforms.compose( transforms.translation([-1, -1, 0]), self.base_matrix) self.base_matrix = transforms.compose( transforms.rotation_degrees(180, "z"), self.base_matrix) self.translation = transforms.translation([0, 0, 0]) self.mvp = transforms.compose(self.translation, self.base_matrix) #for s in Scenarios: # s.loadTexture() print "Before Preloading" Scenarios.preload() print "Pre-loaded" self.fact = Stamp("fact", self) self.fiction = Stamp("fiction", self) self.currentStamp = None