Example #1
0
    def __init__(self):

        self.dir = Dir.empty
        self.run = True
        self.snake = Player()

        if not glfw.init():
            return
        self.window = glfw.create_window(400, 300, "Hello, World!", None, None)
        if not self.window:
            glfw.terminate()
            return
        glfw.make_context_current(self.window)
        glfw.set_key_callback(self.window, self.key_callback)

        while self.run and not glfw.window_should_close(self.window):

            # Update player's position
            self.snake.play(self.dir)
            sleep(0.075)

            self.draw()
            glfw.swap_buffers(self.window)
            glfw.poll_events()

            if self.snake.alive is False:
                sleep(1.075)
                self.run = False
                
        glfw.terminate()
Example #2
0
def main():
    global angles, angley, anglez, scale, carcass, sphere
    if not glfw.init():
        return
    window = glfw.create_window(640, 640, "Lab2", None, None)
    if not window:
        glfw.terminate()
        return
    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)
    glfw.set_framebuffer_size_callback(window, resize_callback)
    glfw.set_window_pos_callback(window, drag_callback)
    l_cube = Cube(0, 0, 0, 1)
    # r_cube = Cube(0, 0, 0, 1)
    sphere.recount(parts)
    while not glfw.window_should_close(window):
        glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_LESS)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        set_projection()
        glLoadIdentity()
        sphere.draw(scale, angles, [0.3, 0.0, 0.4], carcass)
        # r_cube.draw(scale, angles, [0.3, 0.2, 0.4], carcass)
        l_cube.draw(0.5, [0, 0, 0], [-0.5, 0.0, -0.25], False)
        glfw.swap_buffers(window)
        glfw.poll_events()
    glfw.destroy_window(window)
    glfw.terminate()
Example #3
0
    def __init__(self, width=640, height=480, fullscreen=False, aspect=None):
        self.gl = gl
        if not glfw.init():
            raise Exception("GLFW init failed")

        glfw.window_hint(glfw.CLIENT_API, glfw.OPENGL_ES_API)
        glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 2)
        glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 0)
        glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 0)
        glfw.window_hint(glfw.DOUBLEBUFFER, True)
        glfw.window_hint(glfw.DEPTH_BITS, 24)
        glfw.window_hint(glfw.ALPHA_BITS, 0)
        if platform.system() == "Linux":
            try:
                glfw.window_hint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API)
            except:
                pass

        monitor = glfw.get_primary_monitor() if fullscreen else None
        self.window = glfw.create_window(width, height, "BlitzLoop Karaoke",
                                         monitor, None)
        self.x = 0
        self.y = 0
        glfw.make_context_current(self.window)
        BaseDisplay.__init__(self, width, height, fullscreen, aspect)
        self._on_reshape(self.window, width, height)
        if fullscreen:
            self.saved_size = (0, 0, width, height)
            glfw.set_input_mode(self.window, glfw.CURSOR, glfw.CURSOR_HIDDEN)

        glfw.set_key_callback(self.window, self._on_keyboard)
        glfw.set_window_pos_callback(self.window, self._on_move)
        glfw.set_window_size_callback(self.window, self._on_reshape)

        self._initialize()
def main():
    global vertices, window_height, window_width, to_redraw

    if not glfw.init():
        return

    window = glfw.create_window(400, 400, "Lab4", None, None)
    if not window:
        glfw.terminate()
        return

    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)
    glfw.set_framebuffer_size_callback(window, resize_callback)

    glfw.set_mouse_button_callback(window, mouse_button_callback)
    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LESS)
    glClearColor(0, 0, 0, 0)

    while not glfw.window_should_close(window):
        # print(vertices)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        draw()

        glfw.swap_buffers(window)
        glfw.poll_events()

    glfw.destroy_window(window)
    glfw.terminate()
Example #5
0
def main():
    # Initialize the library
    if not glfw.init():
        return
    # Create a windowed mode window and its OpenGL context
    window = glfw.create_window(window_width, window_height, "Hello World", None, None)
    if not window:
        glfw.terminate()
        return

    # Make the window's context current
    glfw.make_context_current(window)
    glfw.set_window_size_callback(window, on_window_size)
    glfw.set_key_callback(window, key_callback)

    initGL(window)
    # Loop until the user closes the window
    while not glfw.window_should_close(window):
        # Render here, e.g. using pyOpenGL
        display()

        # Swap front and back buffers
        glfw.swap_buffers(window)

        # Poll for and process events
        glfw.poll_events()

    glfw.terminate()
Example #6
0
    def __init__(self, objects=[], options={}):
        super().__init__()

        self.parseOptions(options)

        self.cameraCursor = [0.0, 0.0]
        self.cameraMove = False
        self.cameraRotate = False
        self.redisplay = True
        self.titleText = 'OpenGL 4.1 render'

        glfw.init()

        try:
            self.window = glfw.create_window(*self.viewport, self.titleText, None, None)
            glfw.make_context_current(self.window)
        except:
            print('Window initialization failed')
            glfw.terminate()
            exit()

        self.initGraphics()
        self.updateMatrix(self.viewport)

        glfw.set_key_callback(self.window, self.handleKeyEvent)
        glfw.set_mouse_button_callback(self.window, self.handleMouseButtonEvent)
        glfw.set_cursor_pos_callback(self.window, self.handleCursorMoveEvent)
        glfw.set_scroll_callback(self.window, self.handleScrollEvent)
        glfw.set_window_refresh_callback(self.window, self.handleResizeEvent)

        self.objects = set()
        self.appendRenderObjects(self.makeRenderObjects(objects))
Example #7
0
 def run(self):
     # Initialize the library
     if not glfw.init():
         return
     # Create a windowed mode window and its OpenGL context
     self.window = glfw.create_window(640, 480, "Hello World", None, None)
     if not self.window:
         glfw.terminate()
         return
 
     renderer = RiftGLRendererCompatibility()
     # Paint a triangle in the center of the screen
     renderer.append(TriangleDrawerCompatibility())
 
     # Make the window's context current
     glfw.make_context_current(self.window)
 
     # Initialize Oculus Rift
     renderer.init_gl()
     renderer.rift.recenter_pose()
     
     glfw.set_key_callback(self.window, self.key_callback)
 
     # Loop until the user closes the window
     while not glfw.window_should_close(self.window):
         # Render here, e.g. using pyOpenGL
         renderer.display_rift_gl()
 
         # Swap front and back buffers
         glfw.swap_buffers(self.window)
 
         # Poll for and process events
         glfw.poll_events()
 
     glfw.terminate()
Example #8
0
def main():
    global R, T
    if not glfw.init(): return
    window = glfw.create_window(480, 480, "2015004584", None, None)

    if not window:
        glfw.terminate()
        return

    glfw.set_key_callback(window, key_callback)
    glfw.make_context_current(window)
    glfw.swap_interval(0)

    while not glfw.window_should_close(window):
        glfw.poll_events()

        clear()
        axis()

        glMultMatrixf(R.T)
        glMultMatrixf(T.T)
        render()

        glfw.swap_buffers(window)

    glfw.terminate()
Example #9
0
    def init(self):
        if not glfw.init():
            raise Exception('glfw failed to initialize')

        glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3)
        glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 2)
        glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, GL.GL_TRUE)
        glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)

        self.window = glfw.create_window(
            self.initial_width, self.initial_height,
            self.title, None, None
        )
        if not self.window:
            glfw.terminate()
            raise Exception('glfw failed to create a window')

        glfw.make_context_current(self.window)
        glfw.set_framebuffer_size_callback(self.window, self._reshape_callback)
        glfw.set_key_callback(self.window, self._key_callback)
        glfw.set_mouse_button_callback(self.window, self._mouse_button_callback)

        GL.glEnable(GL.GL_CULL_FACE)
        GL.glCullFace(GL.GL_BACK)
        GL.glFrontFace(GL.GL_CW)

        GL.glEnable(GL.GL_DEPTH_TEST)
        GL.glDepthMask(GL.GL_TRUE)
        GL.glDepthFunc(GL.GL_LEQUAL)
        GL.glDepthRange(0.0, 1.0)
        GL.glEnable(depth_clamp.GL_DEPTH_CLAMP)
Example #10
0
 def initGL(self):
     if not glfw.init():
         sys.exit(1)
     self.window = glfw.create_window(640, 480, "Hello", None, None)
     print self.window
     glfw.make_context_current(self.window)
     glfw.swap_interval(1)
     glfw.set_key_callback(self.window, self.key_callback)
     glClearColor(0.5, 0.5, 0.5, 1)
Example #11
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        if not glfw.init():
            raise ValueError("Failed to initialize glfw")

        # Configure the OpenGL context
        glfw.window_hint(glfw.CONTEXT_CREATION_API, glfw.NATIVE_CONTEXT_API)
        glfw.window_hint(glfw.CLIENT_API, glfw.OPENGL_API)
        glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, self.gl_version[0])
        glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, self.gl_version[1])
        glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
        glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, True)
        glfw.window_hint(glfw.RESIZABLE, self.resizable)
        glfw.window_hint(glfw.DOUBLEBUFFER, True)
        glfw.window_hint(glfw.DEPTH_BITS, 24)
        glfw.window_hint(glfw.SAMPLES, self.samples)

        monitor = None
        if self.fullscreen:
            # Use the primary monitors current resolution
            monitor = glfw.get_primary_monitor()
            mode = glfw.get_video_mode(monitor)
            self.width, self.height = mode.size.width, mode.size.height

            # Make sure video mode switching will not happen by
            # matching the desktops current video mode
            glfw.window_hint(glfw.RED_BITS, mode.bits.red)
            glfw.window_hint(glfw.GREEN_BITS, mode.bits.green)
            glfw.window_hint(glfw.BLUE_BITS, mode.bits.blue)
            glfw.window_hint(glfw.REFRESH_RATE, mode.refresh_rate)

        self.window = glfw.create_window(self.width, self.height, self.title, monitor, None)

        if not self.window:
            glfw.terminate()
            raise ValueError("Failed to create window")

        if not self.cursor:
            glfw.set_input_mode(self.window, glfw.CURSOR, glfw.CURSOR_DISABLED)

        self.buffer_width, self.buffer_height = glfw.get_framebuffer_size(self.window)
        glfw.make_context_current(self.window)

        if self.vsync:
            glfw.swap_interval(1)

        glfw.set_key_callback(self.window, self.key_event_callback)
        glfw.set_cursor_pos_callback(self.window, self.mouse_event_callback)
        glfw.set_mouse_button_callback(self.window, self.mouse_button_callback)
        glfw.set_window_size_callback(self.window, self.window_resize_callback)

        self.ctx = moderngl.create_context(require=self.gl_version_code)
        self.print_context_info()
        self.set_default_viewport()
Example #12
0
 def __init__(self, name, width, height, fullscreen=False):
     if not glfw.init():
         raise GlfwError("Could not initialize GLFW")
     monitor = glfw.get_primary_monitor() if fullscreen else None
     self.win = glfw.create_window(width, height, name, monitor, None)
     if not self.win:
         glfw.terminate()
         raise GlfwError("Could not create GLFW window")
     glfw.make_context_current(self.win)
     glfw.set_key_callback(self.win, self.key_cb)
     self.key_callbacks = []
Example #13
0
def createWindow(keyboardCallBackFunction=None):
    # Create a windowed mode window and its OpenGL context
    window = glfw.create_window(640, 480, "Hello World", None, None)
    if not window:
        glfw.terminate()
        print("fail Window")
        return
    # Make the window's context current
    glfw.make_context_current(window)

    if not keyboardCallBackFunction == None:
        # keyboard callback function
        glfw.set_key_callback(window, keyboardCallBackFunction)
    return window
Example #14
0
def main():
    if not glfw.init():
        return
    window = glfw.create_window(640, 480, "Lab2", None, None)
    if not window:
        glfw.terminate()
        return
    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)
    while not glfw.window_should_close(window) and not ex:
        draw()
        glfw.swap_buffers(window)
        glfw.poll_events()
    glfw.terminate()
def main():
	global current_vao
	global vaos

	if not opengl_init():
		return

	glfw.set_input_mode(window,glfw.STICKY_KEYS,GL_TRUE) 
	glfw.set_key_callback(window,key_event)
	# Set opengl clear color to something other than red (color used by the fragment shader)
	glClearColor(0,0,0.4,0)
	
	# Create vertex array object (VAO) 1: Full Triangle
	vao = glGenVertexArrays(1)
	glBindVertexArray(vao)
	init_object(vertex_data)
	glBindVertexArray(0)

	# Create vertex array object (VAO) 2: 1/2 Triangle
	vao2 = glGenVertexArrays(1)
	glBindVertexArray(vao2)
	init_object(vertex_data2)
	glBindVertexArray(0)

	program_id = common.LoadShaders( "SimpleVertexShader.vertexshader", "SimpleFragmentShader.fragmentshader" )
	vertex_buffer = glGenBuffers(1)

	current_vao = 0
	vaos = [vao,vao2]
	glewInit()


	while glfw.get_key(window,glfw.KEY_ESCAPE) != glfw.PRESS and not glfw.window_should_close(window):
		glClear(GL_COLOR_BUFFER_BIT)

		glUseProgram(program_id)	
		glBindVertexArray(vaos[current_vao])

		# Draw the triangle !
		glDrawArrays (GL_TRIANGLES, 0, 3)#3 indices starting at 0 -> 1 triangle

		glBindVertexArray(0)

		# Swap front and back buffers
		glfw.swap_buffers(window)

		# Poll for and process events
		glfw.poll_events()

	glfw.terminate()
Example #16
0
File: Lab1.py Project: ROOOOO/Study
def main():
    global delta
    global angle
    # Initialize the library
    if not glfw.init():
        return
    # Create a windowed mode window and its OpenGL context
    window = glfw.create_window(640, 640, "Lab1", None, None)
    if not window:
        glfw.terminate()
        return
    # Make the window's context current
    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)
    # Loop until the user closes the window
    while not glfw.window_should_close(window):
        # Render here, e.g. using pyOpenGL

        glClear(GL_COLOR_BUFFER_BIT)
        glLoadIdentity()
        glClearColor(1.0, 1.0, 1.0, 1.0)
        glPushMatrix()

        glRotatef(angle, 0, 0, 1)

        glBegin(GL_QUADS)

        glColor3f(0.0,0.0,0.0)
        glVertex3f( 0.5, 0.5, 0.0)
        glColor3f(1.0,0.0,0.0)
        glVertex3f(-0.5, 0.5, 0.0)
        glColor3f(0.0,0.0,1.0)
        glVertex3f(-0.5, -0.5, 0.0)
        glColor3f(1.0,0.0,1.0)
        glVertex3f( 0.5, -0.5, 0.0)


        glEnd()

        glPopMatrix()
        angle += delta

        # Swap front and back buffers
        glfw.swap_buffers(window)
        # Poll for and process events
        glfw.poll_events()
    glfw.destroy_window(window)
    glfw.terminate()
Example #17
0
def main():
   if not glfw.init(): return
   window = glfw.create_window(640,640,'2015004584', None,None)
   if not window: 
      glfw.terminate()
      return
   
   glfw.make_context_current(window)
   glfw.set_key_callback(window, key_callback)
   
   while not glfw.window_should_close(window): 
      glfw.poll_events()
      render(gCamAng)
      glfw.swap_buffers(window)
   
   glfw.terminate()
Example #18
0
    def setup(self):
        # get glfw started
        glfw.init()
        self.window = glfw.create_window(self.width, self.height, "Python NanoVG Demo", None, None)
        glfw.set_window_pos(self.window, 0, 0)

        # Register callbacks window
        glfw.set_window_size_callback(self.window, self.on_resize)
        glfw.set_window_close_callback(self.window, self.on_close)
        glfw.set_key_callback(self.window, self.on_key)
        glfw.set_mouse_button_callback(self.window, self.on_button)

        self.basic_gl_setup()

        # glfwSwapInterval(0)
        glfw.make_context_current(self.window)
Example #19
0
def main():
    if not glfw.init(): return
    window = glfw.create_window(480, 480, "Hello World", None, None)

    if not window:
        glfw.terminate()
        return

    glfw.set_key_callback(window, key_callback)
    glfw.make_context_current(window)

    while not glfw.window_should_close(window):
        glfw.poll_events()
        render()
        glfw.swap_buffers(window)

    glfw.terminate()
Example #20
0
    def __init__(self, sim):
        super().__init__(sim)

        self._gui_lock = Lock()
        self._button_left_pressed = False
        self._button_right_pressed = False
        self._last_mouse_x = 0
        self._last_mouse_y = 0

        framebuffer_width, _ = glfw.get_framebuffer_size(self.window)
        window_width, _ = glfw.get_window_size(self.window)
        self._scale = framebuffer_width * 1.0 / window_width

        glfw.set_cursor_pos_callback(self.window, self._cursor_pos_callback)
        glfw.set_mouse_button_callback(
            self.window, self._mouse_button_callback)
        glfw.set_scroll_callback(self.window, self._scroll_callback)
        glfw.set_key_callback(self.window, self.key_callback)
Example #21
0
def main():
   global glVertexArray, glIndexArray
   if not glfw.init():
      return
   window = glfw.create_window(640,640,'2015004584', None,None)
   if not window:
      glfw.terminate()
      return
   glfw.make_context_current(window)
   glfw.set_key_callback(window, key_callback)
   glfw.set_framebuffer_size_callback(window, windows_callback)

   glVertexArray, glIndexArray = createUnitCube_glDrawArrays()
   while not glfw.window_should_close(window):
      glfw.poll_events()
      render()
      glfw.swap_buffers(window)
   
   glfw.terminate()
Example #22
0
def main():

    glfw.init()

    window = glfw.create_window( 640, 480, "glfw triangle", None, None )
    
    glfw.make_context_current( window )
    glfw.swap_interval( 1 )
    glfw.set_key_callback( window, on_key )

    while not glfw.window_should_close( window ):

        # set up model view
        width, height = glfw.get_framebuffer_size( window )
        ratio = width / float(height)
        gl.glViewport( 0, 0, width, height )
        gl.glClear( gl.GL_COLOR_BUFFER_BIT )
        gl.glMatrixMode( gl.GL_PROJECTION )
        gl.glLoadIdentity()
        gl.glOrtho( -ratio, ratio, -1.0, 1.0, 1.0, -1.0 )
        gl.glMatrixMode( gl.GL_MODELVIEW )
        gl.glLoadIdentity()
        gl.glRotatef( float(glfw.get_time()) * 50.0, 0.0, 0.0, 1.0 )

        # draw triangle
        gl.glBegin(gl.GL_TRIANGLES);
        gl.glColor3f( 1.0, 0.0, 0.0 )
        gl.glVertex3f( -0.6, -0.4, 0.0 )
        gl.glColor3f( 0.0, 1.0, 0.0 )
        gl.glVertex3f( 0.6, -0.4, 0.0 )
        gl.glColor3f( 0.0, 0.0, 1.0 )
        gl.glVertex3f( 0.0, 0.6, 0.0 )
        gl.glEnd()

        # swap buffers
        glfw.swap_buffers(window)

        # poll for events
        glfw.poll_events()
    
    glfw.destroy_window(window)
    glfw.terminate()
def init_window():
    # Initialize the library
    if not glfw.init():
        return None

    glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3)
    glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3)
    glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
    glfw.window_hint(glfw.RESIZABLE, False)

    # Create a windowed mode window and its OpenGL context
    window = glfw.create_window(WINDOW_WIDTH, WINDOW_HEIGHT, "OpenGL Example", None, None)
    if not window:
        glfw.terminate()
        return None

    # Make the window's context current
    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_cb)
    return window
Example #24
0
def main():

    if not glfw.init(): return
    window = HOS(640, 640, '2015004584')
    if not window.context:
        glfw.terminate()
        return

    glfw.make_context_current(window.context)

    glfw.set_key_callback(window.context, window._callback_key)
    glfw.set_drop_callback(window.context, window._callback_drop)

    glfw.swap_interval(1)

    while not glfw.window_should_close(window.context):
        glfw.poll_events()
        window.render()
        glfw.swap_buffers(window.context)

    glfw.terminate()
def main():
    global gVertexArraySeparate
    if not glfw.init():
        return
    window = glfw.create_window(640, 640, '3D Obj File Viewer', None, None)
    if not window:
        glfw.terminate()
        return
    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)
    glfw.set_framebuffer_size_callback(window, framebuffer_size_callback)
    glfw.set_drop_callback(window, dropCallback)
    glfw.swap_interval(1)
    count = 0
    while not glfw.window_should_close(window):
        glfw.poll_events()
        count += 1
        ang = count % 360
        render(ang)
        count += 1
        glfw.swap_buffers(window)
    glfw.terminate()
Example #26
0
def main():
    global gVertexArrayIndexed, gIndexArray, gNArray

    if not glfw.init():
        return
    window = glfw.create_window(480, 480, '학번-8-2', None, None)
    if not window:
        glfw.terminate()
        return
    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)
    glfw.swap_interval(1)

    gVertexArrayIndexed, gIndexArray, gNArray = createVertexAndIndexArrayIndexed(
    )

    while not glfw.window_should_close(window):
        glfw.poll_events()
        render()
        glfw.swap_buffers(window)

    glfw.terminate()
Example #27
0
def main():
    global gVertexArraySeperate_main, gNormalArray_main, gVertexArrayIndexed_main
    global gVertexArraySeperate_sub1, gNormalArray_sub1, gVertexArrayIndexed_sub1
    global gVertexArraySeperate_sub2, gNormalArray_sub2, gVertexArrayIndexed_sub2
    global gVertexArraySeperate_hie, gNormalArray_hie, gVertexArrayIndexed_hie
    global gVertexArraySeperate_hie1, gNormalArray_hie1, gVertexArrayIndexed_hie1
    global gVertexArraySeperate_hie2, gNormalArray_hie2, gVertexArrayIndexed_hie2
    global gVertexArraySeperate_curve, gNormalArray_curve, gVertexArrayIndexed_curve
    global gVertexArraySeperate_hie3, gNormalArray_hie3, gVertexArrayIndexed_hie3

    if not glfw.init():
        return
    window = glfw.create_window(800,800,'2016025105', None,None)
    if not window:
        glfw.terminate()
        return
    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)
    glfw.set_cursor_pos_callback(window, cursor_callback)
    glfw.set_mouse_button_callback(window, button_callback)
    glfw.set_scroll_callback(window, scroll_callback)

    gVertexArraySeperate_main, gNormalArray_main, gVertexArrayIndexed_main = load_file("./cat.obj")
    gVertexArraySeperate_sub1, gNormalArray_sub1, gVertexArrayIndexed_sub1 = load_file("./cube2.obj")
    gVertexArraySeperate_sub2, gNormalArray_sub2, gVertexArrayIndexed_sub2 = load_file("./cube1.obj")
    gVertexArraySeperate_hie, gNormalArray_hie, gVertexArrayIndexed_hie = load_file("./sphere.obj")
    gVertexArraySeperate_hie1, gNormalArray_hie1, gVertexArrayIndexed_hie1 = load_file("./sphere.obj")
    gVertexArraySeperate_hie2, gNormalArray_hie2, gVertexArrayIndexed_hie2 = load_file("./sphere.obj")
    gVertexArraySeperate_curve, gNormalArray_curve, gVertexArrayIndexed_curve = load_file("./sphere.obj")
    gVertexArraySeperate_hie3, gNormalArray_hie3, gVertexArrayIndexed_hie3 = load_file("./sphere.obj")

    glfw.swap_interval(1)

    while not glfw.window_should_close(window):
        glfw.poll_events()
        render()
        glfw.swap_buffers(window)

    glfw.terminate()
def main():
    global gVertexArraySeparate

    if not glfw.init():
        return
    window = glfw.create_window(480, 480, 'color(light,object) changing cube',
                                None, None)
    if not window:
        glfw.terminate()
        return
    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)
    glfw.swap_interval(1)

    gVertexArraySeparate = createVertexArraySeparate()

    while not glfw.window_should_close(window):
        glfw.poll_events()
        render()
        glfw.swap_buffers(window)

    glfw.terminate()
def main():
    global gVertexArrayIndexed, gIndexArray

    if not glfw.init():
        return

    window = glfw.create_window(480,480,'CG_weekly_practice_07_2016024875', None,None)
    if not window:
        glfw.terminate()
        return

    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)

    gVertexArrayIndexed, gIndexArray = createVertexAndIndexArray()

    while not glfw.window_should_close(window):
        glfw.poll_events()
        render()
        glfw.swap_buffers(window)

    glfw.terminate()
Example #30
0
def main():
    if not glfw.init():
        return

    window = glfw.create_window(640, 640, '2014004893', None, None)
    if not window:
        glfw.terminate()
        return

    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)
    glfw.set_drop_callback(window, drop_callback)
    glfw.swap_interval(1)

    glEnableClientState(GL_VERTEX_ARRAY)
    glEnableClientState(GL_NORMAL_ARRAY)
    while not glfw.window_should_close(window):
        glfw.poll_events()
        render()
        glfw.swap_buffers(window)

    glfw.terminate()
Example #31
0
def main():
        
        if not glfw.init():
                return
        window = glfw.create_window(640,640,'2014005014',None,None)
        if not window:
                glfw.terminate()
                return
        glfw.make_context_current(window)
        glfw.set_key_callback(window, key_callback)
        glfw.set_drop_callback(window, drop_callback)
        glfw.swap_interval(1)
        
        count = 0
        while not glfw.window_should_close(window):
                glfw.poll_events()
                ang = count % 360
                render(ang)
                count += 1
                glfw.swap_buffers(window)
                
        glfw.terminate()
Example #32
0
def main():
    if not glfw.init():
        return
    window = glfw.create_window(640, 640, '2015005078-class2', None, None)
    if not window:
        glfw.terminate()
        return

    glfw.set_cursor_pos_callback(window, cursor_callback)
    glfw.set_mouse_button_callback(window, button_callback)
    glfw.set_scroll_callback(window, scroll_callback)
    glfw.set_drop_callback(window, drop_callback)
    glfw.set_key_callback(window, key_callback)

    glfw.make_context_current(window)

    while not glfw.window_should_close(window):
        glfw.poll_events()
        render()
        glfw.swap_buffers(window)

    glfw.terminate()
def main():
	if not glfw.init():
		return

	display = glfw.create_window(WIDTH, HEIGHT, "Ofir's OpenGL Graphics", None, None)

	if not display:
		glfw.terminate()
		return

	glfw.set_key_callback(display, key_handler)

	glfw.set_input_mode(display, glfw.CURSOR, glfw.CURSOR_HIDDEN)
	glfw.set_cursor_pos_callback(display, mouse_move_handler)

	glfw.set_mouse_button_callback(display, key_click_handler)

	glfw.make_context_current(display)

	gluPerspective(45, (WIDTH / HEIGHT), 0.1, 50.0)

	glTranslatef(0.0, 0.0, -10.0)

	pyramid = Pyramid(0, 1, 0, 3)
	# cube2.toggle_rainbow()
	pyramid.set_color((1, 1, 1, 1))
	# cube2.set_color((0, 1, 0, 1))
	while not glfw.window_should_close(display):
		glfw.poll_events()

		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

		# glRotatef(2, 1, 2, 1)
		pyramid.fill()

		glfw.swap_buffers(display)
		time.sleep(1 / FPS)

	glfw.terminate()
Example #34
0
def main():
    if not glfw.init():
        return
    
    window = glfw.create_window(480,480, "학번-3-2", None, None)
    if not window:
        glfw.terminate()
        return

    glfw.set_key_callback(window, key_callback)   

    glfw.make_context_current(window)
    
    
    while not glfw.window_should_close(window):
        glfw.poll_events()

        render(T)
        
        glfw.swap_buffers(window)
    
    glfw.terminate()
Example #35
0
def main():
    if not glfw.init():
        return

    window = glfw.create_window(480, 480, "2015004493-4-2", None, None)
    if not window:
        glfw.terminate()
        return
    global gComposedM

    glfw.set_key_callback(window, key_callback)

    glfw.make_context_current(window)

    while not glfw.window_should_close(window):
        glfw.poll_events()

        render(gComposedM, gCamAng)

        glfw.swap_buffers(window)

    glfw.terminate()
Example #36
0
    def __init__(self):

        cwd = os.getcwd()
        if not glfw.init():
            return
        os.chdir(cwd)
        glfw.window_hint(glfw.DEPTH_BITS, 32)
        self.frame_rate = 100

        self.mousePos = (0, 0)
        self.width, self.height = 1000, 800
        self.aspect = self.width / float(self.height)
        self.window = glfw.create_window(self.width, self.height,
                                         "Base Spline", None, None)
        if not self.window:
            glfw.terminate()
            return
        glfw.make_context_current(self.window)

        glViewport(0, 0, self.width, self.height)
        glEnable(GL_DEPTH_TEST)
        glClearColor(1.0, 1.0, 1.0, 1.0)
        glMatrixMode(GL_PROJECTION)
        #glLoadIdentity()
        glOrtho(0, self.width, 0, self.height, -2, 2)
        glMatrixMode(GL_MODELVIEW)

        # set window callbacks
        glfw.set_mouse_button_callback(self.window, self.onMouseButton)
        glfw.set_key_callback(self.window, self.onKeyboard)
        glfw.set_window_size_callback(self.window, self.onSize)
        glfw.set_cursor_pos_callback(self.window, self.mouse_moved)

        self.scene = Scene(self.width, self.height)
        self.exitNow = False
        self.animation = True
        self.changeWeights = False
        self.selectedPoint = None
        self.index = 0
Example #37
0
def main():
    v = np.linspace(0, 360, 13)[:-1]
    points = np.array((np.cos(v * np.pi / 180), np.sin(v * np.pi / 180))).T

    if not glfw.init():
        return

    window = glfw.create_window(300, 300, "CG_weekly_practice_03-1_", None, None)

    if not window:
        glfw.terminate()
        return

    glfw.set_key_callback(window, key_callback)
    glfw.make_context_current(window)
    glfw.swap_interval(1)
    while not glfw.window_should_close(window):
        glfw.poll_events()
        render(points)
        glfw.swap_buffers(window)

    glfw.terminate()
Example #38
0
def main():
    global window

    if not glfw.init():
        return

    glfw.window_hint(glfw.DOUBLEBUFFER, glfw.TRUE)
    window = glfw.create_window(window_width, window_height, "maikura-modoki",
                                None, None)

    if not window:
        glfw.terminate()
        return

    glfw.set_window_size_callback(window, window_size_callback)
    glfw.set_window_refresh_callback(window, window_refresh_callback)
    glfw.set_key_callback(window, key_callback)
    glfw.set_cursor_pos_callback(window, cursor_pos_callback)
    glfw.set_mouse_button_callback(window, mouse_button_callback)
    glfw.make_context_current(window)

    glClearColor(0.5, 0.8, 1.0, 1.0)
    glEnable(GL_DEPTH_TEST)
    glEnable(GL_CULL_FACE)
    glCullFace(GL_BACK)
    glEnable(GL_LIGHTING)
    glEnable(GL_LIGHT0)
    glEnable(GL_LIGHT1)

    init()

    set_view(window_width, window_height)
    display()

    while not glfw.window_should_close(window):
        glfw.wait_events_timeout(1e-3)
        update()

    glfw.terminate()
Example #39
0
    def __init__(self):
        # save current working directory
        cwd = os.getcwd()
        # Initialize the library
        if not glfw.init():
            return
        # restore cwd
        os.chdir(cwd)
        # window hints
        glfw.window_hint(glfw.DEPTH_BITS, 32)
        glfw.window_hint(glfw.RESIZABLE, GL_FALSE)
        # make a window
        self.width, self.height = 800, 600
        self.aspect = self.width / float(self.height)
        self.window = glfw.create_window(self.width, self.height, "Splines",
                                         None, None)
        if not self.window:
            glfw.terminate()
            return
        # Make the window's context current

        glfw.make_context_current(self.window)
        # initialize GL
        glViewport(0, 0, self.width, self.height)
        glClearColor(1.0, 1.0, 1.0, 1.0)
        glMatrixMode(GL_PROJECTION)
        glOrtho(0, self.width, 0, self.height, -1, 1)
        glMatrixMode(GL_MODELVIEW)

        # set window callbacks
        glfw.set_mouse_button_callback(self.window, self.onMouseButton)
        glfw.set_key_callback(self.window, self.onKeyboard)
        glfw.set_cursor_pos_callback(self.window, self.onMouseMoved)

        # create 3D
        self.scene = Scene(self.width, self.height)

        # exit flag
        self.exitNow = False
Example #40
0
def main():
    if not glfw.init():
        return
    window = glfw.create_window(1000, 1000, "2018008395", None, None)
    if not window:
        glfw.terminate()
        return

    glfw.set_mouse_button_callback(window, button_callback)
    glfw.set_cursor_pos_callback(window, cursor_callback)
    glfw.set_scroll_callback(window, scroll_callback)
    glfw.set_drop_callback(window, drop_callback)
    glfw.set_key_callback(window, key_callback)

    glfw.make_context_current(window)
    glfw.swap_interval(1)

    while not glfw.window_should_close(window):
        glfw.poll_events()
        render()
        glfw.swap_buffers(window)
    glfw.terminate()
Example #41
0
    def __init__(self, window):
        super().__init__()
        self.window = window
        self.gl = mg.create_context(require=460)
        self.compile()

        def on_mod(e):
            self._need_compile = True

        handler = FileSystemEventHandler()
        handler.on_modified = on_mod
        observer = Observer()
        observer.schedule(handler, "./gl", True)
        observer.start()

        self.is_drag = 0
        self.pos = ivec2(0, 0)
        self._should_capture_buffers = False

        glfw.set_cursor_pos_callback(window, self.on_cursor_pos)
        glfw.set_mouse_button_callback(window, self.on_mouse_button)
        glfw.set_key_callback(window, self.on_key)
Example #42
0
def main():
    if not glfw.init():
        raise Exception("glfw nt initialized")

    window=glfw.create_window(700,700, "B117049- Quadratic Function",None,None)

    if not window:
        glfw.terminate()
        raise Exception("glfw window not created")

    w,h = glfw.get_framebuffer_size(window)
    print("width: {}, height:{}".format(w,h))

    glfw.set_window_pos(window, 400,45)

    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)

    glfw.set_window_size_callback(window, reshape_callback)

    gluOrtho2D(-300.0, 300.0,-9050.0,90000.0)
    setpixel(0,0,[1,0,1])

    while not glfw.window_should_close(window):
        glClear(GL_COLOR_BUFFER_BIT)
        glClearColor(1,1,1,1.0)
        drawAxes()

        prev_x = -299
        prev_y= parabola(prev_x)

        for i in range(-299, 299,1):
            y=parabola(i)
            setpixel(i,y,(1,0,0))
         
        glfw.swap_buffers(window)
        glfw.poll_events()

    glfw.terminate()
Example #43
0
def main():
    
    global gCamAng
    if not glfw.init():
        return

    window = glfw.create_window(640,640,"OHT",None,None)
    if not window:
        glfw.terminate()
        return

    glfw.make_context_current(window)
    glfw.set_key_callback(window,key_callback)
    glfw.swap_interval(1)

    while not glfw.window_should_close(window):
        glfw.poll_events()
        
        render(gCamAng)

        glfw.swap_buffers(window)
    glfw.terminate()
Example #44
0
 def __init__(
     self,
     width: int,
     height: int,
     title: str = '',
     object_context: Optional['ObjectContext'] = None,
     msaa: int = 1,
     hidden: bool = False,
 ):
     initialise_glfw()
     glfw.window_hint(glfw.SAMPLES, msaa)
     glfw.window_hint(glfw.VISIBLE, not hidden)
     if object_context is None:
         share = None
         object_context = ObjectContext(self)
     else:
         share = object_context._get_glfw_window()
     self._glfw_window = glfw.create_window(width, height, title, None,
                                            share)
     if share is not None:
         object_context.attach(self)
     self.object_context = object_context
     self._bound = {}
     self.activate()
     self._defaults = {}
     for kind, default_class in self._default_classes.items():
         self._defaults[kind] = default_class()
     # Input
     self.keyboard = Keyboard()
     self.mouse = Mouse()
     # Callbacks
     self.on_resize: Optional[Callable[[int, int], None]] = None
     glfw.set_framebuffer_size_callback(self._glfw_window,
                                        self._framebuffer_size_callback)
     glfw.set_key_callback(self._glfw_window, self._key_callback)
     glfw.set_mouse_button_callback(self._glfw_window,
                                    self._mouse_button_callback)
     glfw.set_cursor_pos_callback(self._glfw_window,
                                  self._cursor_pos_callback)
Example #45
0
    def __init__(self):

        # save current working directory
        cwd = os.getcwd()

        # initialize glfw - this changes cwd
        glfw.init()

        # restore cwd
        os.chdir(cwd)

        # version hints
        glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3)
        glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3)
        glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, GL_TRUE)
        glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)

        # make a window
        self.width, self.height = 640, 480
        self.aspect = self.width/float(self.height)
        self.win = glfw.create_window(self.width, self.height, "test")
        # make context current
        glfw.make_context_current(self.win)

        # initialize GL
        glViewport(0, 0, self.width, self.height)
        glEnable(GL_DEPTH_TEST)
        glClearColor(0.5, 0.5, 0.5,1.0)

        # set window callbacks
        glfw.set_mouse_button_callback(self.win, self.onMouseButton)
        glfw.set_key_callback(self.win, self.onKeyboard)
        glfw.set_window_size_callback(self.win, self.onSize)        

        # create 3D
        self.scene = Scene()

        # exit flag
        self.exitNow = False
Example #46
0
def main():
    global OnlyVertex, OnlyIndex, OnlyNormal

    if not glfw.init():
        return
    window = glfw.create_window(1000, 1000, "2016025687", None, None)

    if not window:
        glfw.terminate()
        return

    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)
    glfw.swap_interval(1)
    init_obj(gPath)

    while not glfw.window_should_close(window):
        glfw.poll_events()
        render()
        glfw.swap_buffers(window)

    glfw.terminate()
Example #47
0
 def __init__(self, renderer, title="GLFW test"):
     "Creates an OpenGL context and a window, and acquires OpenGL resources"
     self.renderer = renderer
     self.title = title
     self._is_initialized = False # keep track of whether self.init_gl() has been called
     
     if not glfw.init():
         raise Exception("GLFW Initialization error")
     # Get OpenGL 4.1 context
     glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 4)
     glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 1)
     glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
     # Double buffered screen mirror stalls VR headset rendering,
     # So use single-buffering
     glfw.window_hint(glfw.DOUBLEBUFFER, False)
     self.window = glfw.create_window(self.renderer.window_size[0], self.renderer.window_size[1], self.title, None, None)
     if self.window is None:
         glfw.terminate()
         raise Exception("GLFW window creation error")
     glfw.set_key_callback(self.window, self.key_callback)
     glfw.make_context_current(self.window)
     glfw.swap_interval(0)
Example #48
0
def main():
    global gVertexArraySeparate
    if not glfw.init():
        return
    window = glfw.create_window(720, 720, '2015005141', None, None)
    if not window:
        glfw.terminate()
        return
    glfw.make_context_current(window)

    gVertexArraySeparate = createVertexArraySeparate()
    glfw.set_key_callback(window, key_callback)
    glfw.swap_interval(1)

    while not glfw.window_should_close(window):
        glfw.poll_events()
        render(gCamAng)
        glfw.swap_interval(1)

        glfw.swap_buffers(window)

    glfw.terminate()
Example #49
0
 def init_gl(self):
     if self._is_initialized:
         return # only initialize once
     if not glfw.init():
         raise Exception("GLFW Initialization error")
     # Get OpenGL 4.1 context
     glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 4)
     glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 1)
     glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
     # Double buffered screen mirror stalls VR headset rendering,
     # So use single-buffering
     glfw.window_hint(glfw.DOUBLEBUFFER, False)
     glfw.swap_interval(0)
     self.window = glfw.create_window(self.renderer.window_size[0], self.renderer.window_size[1], self.title, None, None)
     if self.window is None:
         glfw.terminate()
         raise Exception("GLFW window creation error")
     glfw.set_key_callback(self.window, self.key_callback)
     glfw.make_context_current(self.window)
     if self.renderer is not None:
         self.renderer.init_gl()
     self._is_initialized = True
Example #50
0
def main():
    if not glfw.init():
        raise Exception("glfw nt initialized")

    window=glfw.create_window(640,480, "DDA Line Drawing",None,None)

    if not window:
        glfw.terminate()
        raise Exception("glfw window not created")

    w,h = glfw.get_framebuffer_size(window)
    print("width: {}, height:{}".format(w,h))

    glfw.set_window_pos(window, 400,200)

    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)

    glfw.set_window_size_callback(window, reshape_callback)

    gluOrtho2D(-200.0, 200.0,-200.0,200.0)

    while not glfw.window_should_close(window):

        glClear(GL_COLOR_BUFFER_BIT)
        glClearColor(0.0,0.76,0.56,1.0)

        DDALine(-150,-150,150,150, [1,0,1])#L2  pink correct
        DDALine(-150,-50,150,50,[1,1,0])#L1   yellow correct
        DDALine(-50,-150,50,150, [1,0,0]) #L3  red correct
        DDALine(-50,150,50,-150, [0,1,0])#L4   green corect
        DDALine(-150,150,150,-150,[0,0,1])#L5  blue correct
        DDALine(-150,50,150,-50,[0,1,1]) #L6   cyan/ sky blue correct
        

        glfw.swap_buffers(window)
        glfw.poll_events()

    glfw.terminate()
Example #51
0
def init(light_source_position):
    if not glfw.init():
        print("GLFW not initialized")
        return

    window = glfw.create_window(640, 640, "Realistic", None, None)
    if not window:
        print("Window not created")
        glfw.terminate()
        return

    glfw.make_context_current(window)

    GL.glEnable(GL.GL_DEPTH_TEST)
    GL.glDepthFunc(GL.GL_LESS)

    GL.glEnable(GL.GL_NORMALIZE)
    # источник света
    GL.glEnable(GL.GL_LIGHTING)
    GL.glEnable(GL.GL_LIGHT0)
    GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, light_source_position)
    # параметры глобальной модели
    GL.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT,
                      Globals.current_ambient_color())
    GL.glLightModelfv(GL.GL_LIGHT_MODEL_LOCAL_VIEWER,
                      Globals.light_model_two_side)
    GL.glLightModelfv(GL.GL_LIGHT_MODEL_TWO_SIDE, Globals.light_model_two_side)

    glfw.set_key_callback(window, key_callback)
    glfw.set_framebuffer_size_callback(window, resize_callback)

    # параметры текстуры
    GL.glEnable(GL.GL_TEXTURE_2D)
    GL.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE)
    load_image("tree-tex.bmp")
    setup_texture()

    return window
Example #52
0
    def __init__(self, width=640, height=480):

        # version hints: create GL window with >= OpenGL 3.3 and core profile
        glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3)
        glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3)
        glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, GL.GL_TRUE)
        glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
        glfw.window_hint(glfw.RESIZABLE, False)
        self.win = glfw.create_window(width, height, 'Viewer', None, None)

        # make win's OpenGL context current; no OpenGL calls can happen before
        glfw.make_context_current(self.win)

        # register event handlers
        glfw.set_key_callback(self.win, self.on_key)

        # useful message to check OpenGL renderer characteristics
        print(
            'OpenGL',
            GL.glGetString(GL.GL_VERSION).decode() + ', GLSL',
            GL.glGetString(GL.GL_SHADING_LANGUAGE_VERSION).decode() +
            ', Renderer',
            GL.glGetString(GL.GL_RENDERER).decode())

        # initialize GL by setting viewport and default render characteristics
        GL.glClearColor(0.1, 0.1, 0.1, 0.1)
        GL.glEnable(GL.GL_DEPTH_TEST)  # depth test now enabled (TP2)
        GL.glEnable(GL.GL_CULL_FACE)  # backface culling enabled (TP2)

        # compile and initialize shader programs once globally
        self.color_shader = Shader(COLOR_VERT, COLOR_FRAG)

        # initially empty list of object to draw
        self.drawables = []
        self.trackball = GLFWTrackball(self.win)

        # cyclic iterator to easily toggle polygon rendering modes
        self.fill_modes = cycle([GL.GL_LINE, GL.GL_POINT, GL.GL_FILL])
Example #53
0
def main():
    if not glfw.init():
        raise Exception("glfw nt initialized")

    window = glfw.create_window(900, 600, "B117049- Sine 0.3x Wave", None,
                                None)

    if not window:
        glfw.terminate()
        raise Exception("glfw window not created")

    w, h = glfw.get_framebuffer_size(window)
    print("width: {}, height:{}".format(w, h))

    glfw.set_window_pos(window, 350, 85)

    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)

    glfw.set_window_size_callback(window, reshape_callback)

    gluOrtho2D(-400, 3600 / 2, -450, 450)

    while not glfw.window_should_close(window):

        glClear(GL_COLOR_BUFFER_BIT)
        glClearColor(1, 1, 1, 1.0)
        drawAxes()

        for i in range(-400, 1800, 1):
            x = float(i)
            y = 100.0 * math.sin(i * (6.284 / 360.0)) / 3
            setpixel(x, y, (1, 0, 0))

        glfw.swap_buffers(window)
        glfw.poll_events()

    glfw.terminate()
Example #54
0
    def main(self):
        self.drag_offset = ivec2(0.0, 0.0)
        self.drag_start_winpos = ivec2(0.0, 0.0)
        self.is_drag = False

        glfw.init()
        glfw.window_hint(glfw.FLOATING, glfw.TRUE)
        glfw.window_hint(glfw.DECORATED, glfw.FALSE)
        glfw.window_hint(glfw.TRANSPARENT_FRAMEBUFFER, glfw.TRUE)

        self.width, self.height = 512, 512
        self.window = glfw.create_window(self.width, self.height, "render_0",
                                         None, None)

        x, y, w, h = glfw.get_monitor_workarea(glfw.get_primary_monitor())
        glfw.set_window_pos(self.window, (w - self.width) >> 1,
                            (h - self.height) >> 1)
        glfw.make_context_current(self.window)

        glfw.set_mouse_button_callback(self.window, self.on_mouse_button)
        glfw.set_cursor_pos_callback(self.window, self.on_cursor_pos)
        glfw.set_key_callback(self.window, self.on_key)

        self.init_gl()

        handler = FileSystemEventHandler()
        handler.on_modified = self.on_modified
        observer = Observer()
        observer.schedule(handler, "./gl/", True)
        observer.start()

        while not glfw.window_should_close(self.window):
            if self.should_recomile:
                self.compile_vao()

            self.paint_gl()
            glfw.swap_buffers(self.window)
            glfw.poll_events()
Example #55
0
def main():
    global gVertexArraySeparate
    global gVertexArrayIndexed, gIndexArray
    if not glfw.init():
        return
    window = glfw.create_window(640, 640, '2014004411', None, None)
    if not window:
        glfw.terminate()
        return
    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)
    glfw.swap_interval(1)
    gVertexArraySeparate = createVertexArraySeparate()
    gVertexArrayIndexed, gIndexArray = createVertexAndIndexArrayIndexed()
    count = 0

    while not glfw.window_should_close(window):
        glfw.poll_events()
        ang = count % 360
        render(ang)
        count += 1
        glfw.swap_buffers(window)
    glfw.terminate()
Example #56
0
def main():
    if not glfw.init(): return
    window = glfw.create_window(480, 480, "2015004584", None, None)

    if not window:
        glfw.terminate()
        return

    glfw.set_key_callback(window, key_callback)
    glfw.make_context_current(window)
    glfw.swap_interval(1)

    while not glfw.window_should_close(window):
        glfw.poll_events()

        clear()
        axis()

        render()

        glfw.swap_buffers(window)

    glfw.terminate()
Example #57
0
def main():
	global gComposedM
	
	if not glfw.init():
		return
		
	window = glfw.create_window(480, 480, "GG_weekly_practice_04_2016024875", None, None)
	if not window:
		glfw.terminate()
		return
		
	glfw.set_key_callback(window, key_callback)
	glfw.make_context_current(window)
	glfw.swap_interval(1)
	
	while not glfw.window_should_close(window):
		glfw.poll_events()
	
		render(gComposedM)
		
		glfw.swap_buffers(window)
		
	glfw.terminate()
Example #58
0
def main():
   global gVertexArraySeparate
   global gVertexArrayIndexed, gIndexArray
   if not glfw.init(): return
   window = glfw.create_window(640,640,'2015004584', None,None)
   if not window:
      glfw.terminate()
      return
   glfw.make_context_current(window)
   glfw.set_key_callback(window, key_callback)
   glfw.swap_interval(1)

   gVertexArraySeparate = createVertexArraySeparate()
   gVertexArrayIndexed, gIndexArray = createVertexAndIndexArrayIndexed()

   count = 0
   while not glfw.window_should_close(window):
      glfw.poll_events()
      ang = count % 360
      render(ang)
      count += 1
      glfw.swap_buffers(window)
   glfw.terminate()
Example #59
0
def init():
    if not glfw.init():
        print("GLFW not initialized")
        return

    window = glfw.create_window(640, 640, "Cubes", None, None)
    if not window:
        print("Window not created")
        glfw.terminate()
        return

    glfw.make_context_current(window)

    GL.glEnable(GL.GL_DEPTH_TEST)
    GL.glDepthFunc(GL.GL_LESS)

    glfw.set_key_callback(window, key_callback)
    glfw.set_framebuffer_size_callback(window, resize_callback)

    # подключение шейдеров
    program = load_shaders()

    return window, program
Example #60
0
    def __init__(self, win, *args, **kwargs):
        """Set up the backend window according the params of the PsychoPy win

        Before PsychoPy 1.90.0 this code was executed in Window._setupPygame()

        Parameters
        ----------
        win : psychopy.visual.Window instance
            PsychoPy Window (usually not fully created yet).
        share : psychopy.visual.Window instance
            PsychoPy Window to share a context with
        bpc : array_like
            Bits per color (R, G, B).
        refreshHz : int
            Refresh rate in Hertz.
        depthBits : int,
            Framebuffer (back buffer) depth bits.
        swapInterval : int
            Swap interval for the current OpenGL context.
        stencilBits : int
            Framebuffer (back buffer) stencil bits.
        winTitle : str
            Optional window title string.
        *args
            Additional position arguments.
        **kwargs
            Additional keyword arguments.

        """
        BaseBackend.__init__(self, win)

        # window to share a context with
        shareWin = kwargs.get('share', None)
        if shareWin is not None:
            if shareWin.winType == 'glfw':
                shareContext = shareWin.winHandle
            else:
                logging.warning(
                    'Cannot share a context with a non-GLFW window. Disabling.')
                shareContext = None
        else:
            shareContext = None

        if sys.platform=='darwin' and not win.useRetina and pyglet.version >= "1.3":
            raise ValueError("As of PsychoPy 1.85.3 OSX windows should all be "
                             "set to useRetina=True (or remove the argument). "
                             "Pyglet 1.3 appears to be forcing "
                             "us to use retina on any retina-capable screen "
                             "so setting to False has no effect.")

        # window framebuffer configuration
        win.bpc = kwargs.get('bpc', (8, 8, 8))  # nearly all displays use 8 bpc
        win.refreshHz = int(kwargs.get('refreshHz', 60))
        win.depthBits = int(kwargs.get('depthBits', 8))
        win.stencilBits = int(kwargs.get('stencilBits', 8))
        # win.swapInterval = int(kwargs.get('swapInterval', 1))  # vsync ON if 1

        # get monitors, with GLFW the primary display is ALWAYS at index 0
        allScrs = glfw.get_monitors()
        if len(allScrs) < int(win.screen) + 1:
            logging.warn("Requested an unavailable screen number - "
                         "using first available.")
            win.screen = 0

        thisScreen = allScrs[win.screen]
        if win.autoLog:
            logging.info('configured GLFW screen %i' % win.screen)

        # find a matching video mode (can we even support this configuration?)
        isVidmodeSupported = False
        for vidmode in glfw.get_video_modes(thisScreen):
            size, bpc, hz = vidmode
            if win._isFullScr:  # size and refresh rate are ignored if windowed
                hasSize = size == tuple(win.size)
                hasHz = hz == win.refreshHz
            else:
                hasSize = hasHz = True
            hasBpc = bpc == tuple(win.bpc)
            if hasSize and hasBpc and hasHz:
                isVidmodeSupported = True
                break

        nativeVidmode = glfw.get_video_mode(thisScreen)
        if not isVidmodeSupported:
            # the requested video mode is not supported, use current

            logging.warning(
                ("The specified video mode is not supported by this display, "
                 "using native mode ..."))
            logging.warning(
                ("Overriding user video settings: size {} -> {}, bpc {} -> "
                 "{}, refreshHz {} -> {}".format(
                    tuple(win.size),
                    nativeVidmode[0],
                    tuple(win.bpc),
                    nativeVidmode[1],
                    win.refreshHz,
                    nativeVidmode[2])))

            # change the window settings
            win.size, win.bpc, win.refreshHz = nativeVidmode

        if win._isFullScr:
            useDisplay = thisScreen
        else:
            useDisplay = None

        # configure stereo
        useStereo = 0
        if win.stereo:
            # provide warning if stereo buffers are requested but unavailable
            if not glfw.extension_supported('GL_STEREO'):
                logging.warning(
                    'A stereo window was requested but the graphics '
                    'card does not appear to support GL_STEREO')
                win.stereo = False
            else:
                useStereo = 1

        # setup multisampling
        # This enables multisampling on the window backbuffer, not on other
        # framebuffers.
        msaaSamples = 0
        if win.multiSample:
            maxSamples = (GL.GLint)()
            GL.glGetIntegerv(GL.GL_MAX_SAMPLES, maxSamples)
            if (win.numSamples & (win.numSamples - 1)) != 0:
                # power of two?
                logging.warning(
                    'Invalid number of MSAA samples provided, must be '
                    'power of two. Disabling.')
            elif 0 > win.numSamples > maxSamples.value:
                # check if within range
                logging.warning(
                    'Invalid number of MSAA samples provided, outside of valid '
                    'range. Disabling.')
            else:
                msaaSamples = win.numSamples
        win.multiSample = msaaSamples > 0

        # disable stencil buffer
        if not win.allowStencil:
            win.stencilBits = 0

        # set buffer configuration hints
        glfw.window_hint(glfw.RED_BITS, win.bpc[0])
        glfw.window_hint(glfw.GREEN_BITS, win.bpc[1])
        glfw.window_hint(glfw.BLUE_BITS, win.bpc[2])
        glfw.window_hint(glfw.REFRESH_RATE, win.refreshHz)
        glfw.window_hint(glfw.STEREO, useStereo)
        glfw.window_hint(glfw.SAMPLES, msaaSamples)
        glfw.window_hint(glfw.STENCIL_BITS, win.stencilBits)
        glfw.window_hint(glfw.DEPTH_BITS, win.depthBits)
        glfw.window_hint(glfw.AUTO_ICONIFY, 0)

        # window appearance and behaviour hints
        if not win.allowGUI:
            glfw.window_hint(glfw.DECORATED, 0)

        # create the window
        self.winHandle = glfw.create_window(
            width=win.size[0],
            height=win.size[1],
            title=str(kwargs.get('winTitle', "PsychoPy (GLFW)")),
            monitor=useDisplay,
            share=shareContext)

        # The window's user pointer maps the Python Window object to its GLFW
        # representation.
        glfw.set_window_user_pointer(self.winHandle, win)
        glfw.make_context_current(self.winHandle)  # ready to use

        # set the position of the window if not fullscreen
        if not win._isFullScr:
            # if no window position is specified, centre it on-screen
            if win.pos is None:
                size, bpc, hz = nativeVidmode
                win.pos = [(size[0] - win.size[0]) / 2.0,
                           (size[1] - win.size[1]) / 2.0]

            # get the virtual position of the monitor, apply offset to the
            # window position
            px, py = glfw.get_monitor_pos(thisScreen)
            glfw.set_window_pos(self.winHandle,
                                int(win.pos[0] + px),
                                int(win.pos[1] + py))

        elif win._isFullScr and win.pos is not None:
            logging.warn("Ignoring window 'pos' in fullscreen mode.")

        # set the window icon
        glfw.set_window_icon(self.winHandle, 1, _WINDOW_ICON_)

        # set the window size to the framebuffer size
        win.size = np.array(glfw.get_framebuffer_size(self.winHandle))

        if win.useFBO:  # check for necessary extensions
            if not glfw.extension_supported('GL_EXT_framebuffer_object'):
                msg = ("Trying to use a framebuffer object but "
                       "GL_EXT_framebuffer_object is not supported. Disabled")
                logging.warn(msg)
                win.useFBO = False
            if not glfw.extension_supported('GL_ARB_texture_float'):
                msg = ("Trying to use a framebuffer object but "
                       "GL_ARB_texture_float is not supported. Disabling")
                logging.warn(msg)
                win.useFBO = False

        # Assign event callbacks, these are dispatched when 'poll_events' is
        # called.
        glfw.set_mouse_button_callback(self.winHandle, event._onGLFWMouseButton)
        glfw.set_scroll_callback(self.winHandle, event._onGLFWMouseScroll)
        glfw.set_key_callback(self.winHandle, event._onGLFWKey)
        glfw.set_char_mods_callback(self.winHandle, event._onGLFWText)

        # set swap interval to manual setting, independent of waitBlanking
        self.setSwapInterval(int(kwargs.get('swapInterval', 1)))

        # give the window class GLFW specific methods
        win.setMouseType = self.setMouseType
        if not win.allowGUI:
            self.setMouseVisibility(False)