def run(self):
     # start loop
     while not glfw.glfwWindowShouldClose(self.win) and not self.exitNow:
         # render
         self.renderer.draw()
         # swap buffers
         glfw.glfwSwapBuffers(self.win)
         # wait for events
         glfw.glfwWaitEvents()
     # end
     glfw.glfwTerminate()
Beispiel #2
0
 def run(self):
     # start loop
     while not glfw.glfwWindowShouldClose(self.win) and not self.exitNow:
         # render
         self.renderer.draw()
         # swap buffers
         glfw.glfwSwapBuffers(self.win)
         # wait for events
         glfw.glfwWaitEvents()
     # end
     glfw.glfwTerminate()
Beispiel #3
0
def main():

    # verify input
    if len(sys.argv) == 1:
       # check if the standard input is a tty (not a pipe)
       if sys.stdin.isatty():
          print("Incorrect syntax, use:")
          print('  > ' + sys.argv[0] + " image.png")

          # show a default image if exists
          sys.argv.append('/Users/facciolo/uiskentuie_standing_stone.png')
          try:
             from os import stat
             stat(sys.argv[1])
          except OSError:
             sys.exit(1)
       # otherwise use stdin as input (because it should be a pipe)
       else:
          sys.argv.append('-')

    # pick the first image
    I1 = sys.argv[1]


    # globals
    global D,V,DD,current_image_idx


    tic()
    # read the image
    # Usually this is done with change_image, but this is a special case
    # as we must find out the image size before creating the window 
    D.imageBitmapTiles,D.w,D.h,D.nch,D.v_min,D.v_max = load_image(I1)
    D.filename = I1
    from os import stat, path
    if I1 != '-' and path.exists(I1):
      D.mtime    = (stat(I1).st_mtime)
    V.data_min, V.data_max=  D.v_min,D.v_max 
    V.reset_scale_bias()
    toc('loadImage+data->RGBbitmap')

    
    ## image list
    current_image_idx = 0
    DD[current_image_idx] = D




    tic()
    # Initialize the library
    # for some reason glfwInit changes the current dir, so I change it back!
    from os import getcwd,chdir
    savepath = getcwd()
    if not glfw.glfwInit():
        sys.exit(1)
    chdir(savepath)


    # TODO REMOVE : needed for the text
    import OpenGL.GLUT as glut
    glut.glutInit()


    # Create a windowed mode window and its OpenGL context
    window = glfw.glfwCreateWindow(D.w, D.h, "Vflip! (reloaded)", None, None)


    if not window:
        glfw.glfwTerminate()
        sys.exit(1)

    # Make the window's context current
    glfw.glfwMakeContextCurrent(window)

    # event handlers
    glfw.glfwSetKeyCallback(window, keyboard_callback)
    glfw.glfwSetMouseButtonCallback(window, mouseButtons_callback)
    glfw.glfwSetScrollCallback(window, mouseWheel_callback)
    glfw.glfwSetCursorPosCallback(window, mouseMotion_callback)
    glfw.glfwSetFramebufferSizeCallback(window, resize_callback)
    glfw.glfwSetWindowRefreshCallback(window,display)
#    glfw.glfwSetCharCallback (window, unicode_char_callback)
    toc('glfw init')


    # setup texture 
    tic()
    setupTexturesFromImageTiles(D.imageBitmapTiles,D.w,D.h,D.nch)
    glFinish()  # Flush and wait
    toc('texture setup')

    print (0,D.filename, (D.w,D.h,D.nch), (D.v_min,D.v_max))


##########
######## SETUP FRAGMENT SHADER FOR CONTRAST CHANGE
##########
# http://www.cityinabottle.org/nodebox/shader/
# http://www.seethroughskin.com/blog/?p=771
# http://python-opengl-examples.blogspot.com.es/
# http://www.lighthouse3d.com/tutorials/glsl-core-tutorial/fragment-shader/

    global program, SHADERS, SHADER_PROGRAMS
    for s in SHADERS.keys():
       SHADER_PROGRAMS[s] = compileProgram(
             compileShader(SHADERS[s], GL_FRAGMENT_SHADER),
             );
       glLinkProgram( SHADER_PROGRAMS[s] )

    program = SHADER_PROGRAMS['rgba']
    

    #global program
    # try to activate/enable shader program
    # handle errors wisely
    try:
       glUseProgram(program)   
    except OpenGL.error.GLError:
       print(glGetProgramInfoLog(program))
       raise
    # set the values of the shader uniform variables (global)
    shader_a= glGetUniformLocation(program, "shader_a")
    glUniform1f(shader_a,V.scale_param)
    shader_b= glGetUniformLocation(program, "shader_b")
    glUniform1f(shader_b,V.bias_param)
    shader_c= glGetUniformLocation(program, "shader_c")
    glUniform1i(shader_c,V.inv_param)




#    # first display
#    display(window)
##    glFlush()

    # Loop until the user closes the window
    while not glfw.glfwWindowShouldClose(window):

        # Render here
        if V.redisp:
           # Try to resize the window if needed
           # this process the window resize requests generated by the application
           # the user window resize requests requests go directly to resize_callback
           if V.resize and not (D.w,D.h) == glfw.glfwGetFramebufferSize(window) and not V.window_has_been_resized_by_the_user:
              glfw.glfwSetWindowSize(window,D.w,D.h)
              # I know it's not been the user so I reset the variable to 0
              V.window_has_been_resized_by_the_user=0
              V.resize = 0

           if V.TOGGLE_FIT_TO_WINDOW_SIZE: V.update_zoom_position_to_fit_window()

           V.redisp = display(window)

           # Swap front and back buffers
           glfw.glfwSwapBuffers(window)
           V.mute_wheel=0
           V.mute_sweep=0
           V.mute_keyboard=0


        # Poll for and process events
        #glfw.glfwPollEvents()
        glfw.glfwWaitEvents()

    glfw.glfwTerminate()