コード例 #1
0
def init():
    width = 640
    height = 640
    glfw.Init()
    glfw.OpenWindow(width, height, 8, 8, 8, 0, 24, 0, glfw.WINDOW)
    glfw.SetWindowTitle("glfw line")
    glfw.SetWindowSizeCallback(Reshape)
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LEQUAL);
    
    glfw.SetMouseButtonCallback(MouseHandler)
    glfw.SetKeyCallback(KeyboardHandler)
    glfw.SetWindowCloseCallback(WindowCLose)
    
    global heightmap, terrain_size
    tmpheightmap = open("heightmap.raw", 'rb').read()
    for c in tmpheightmap:
        heightmap.append(ord(c))
    print heightmap
    terrain_size = int(sqrt(len(heightmap)))
    print terrain_size
    
    if(glFogCoordfEXT):  # test
        print 'ok'
コード例 #2
0
ファイル: HeadRender.py プロジェクト: nekrovikisik/pyOpenGL
def init(textureImg):
    width = 640
    height = 640
    glfw.Init()
    glfw.OpenWindow(width, height, 8, 8, 8, 0, 24, 0, glfw.WINDOW)
    glfw.SetWindowTitle("glfw mesh")
    glfw.SetWindowSizeCallback(Reshape)
    glfw.SetMouseButtonCallback(MouseHandler)
    glfw.SetKeyCallback(KeyboardHandler)
    glfw.SetWindowCloseCallback(WindowCLose)

    glClearColor(1.0, 1.0, 1.0, 1.0)
    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LEQUAL)

    glEnable(GL_TEXTURE_2D)

    # texture one
    textureHandle = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, textureHandle)
    # filter for min and mag texture
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)

    # specify the texture
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, textureImg.size[0],
                 textureImg.size[1], 0, GL_RGB, GL_UNSIGNED_BYTE,
                 PIL2array(textureImg))
    return textureHandle
コード例 #3
0
ファイル: Template.py プロジェクト: nekrovikisik/pyOpenGL
def init():
    width = 640
    height = 640
    glfw.Init()
    glfw.OpenWindow(width, height, 8, 8, 8, 0, 24, 0, glfw.WINDOW)
    glfw.SetWindowTitle("glfw line")
    glfw.SetWindowSizeCallback(Reshape)
    glfw.SetMouseButtonCallback(MouseHandler)
    glfw.SetKeyCallback(KeyboardHandler)
    glfw.SetWindowCloseCallback(WindowCLose)

    glClearColor(0.0, 0.0, 0.0, 0.0)
    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LEQUAL)
コード例 #4
0
ファイル: LoadTGA.py プロジェクト: nekrovikisik/pyOpenGL
def init():
    width = 1024
    height = 768
    glfw.Init()
    glfw.OpenWindow(width, height, 8, 8, 8, 0, 24, 0, glfw.WINDOW)
    glfw.SetWindowTitle("glfw line")
    glfw.SetWindowSizeCallback(Reshape)
    glClearColor(0.0, 0.0, 0.0, 0.0)
    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LEQUAL)

    glfw.SetMouseButtonCallback(MouseHandler)
    glfw.SetKeyCallback(KeyboardHandler)
    glfw.SetWindowCloseCallback(WindowCLose)

    global m_tga
    m_tga.load("rock.tga")
    m_tga_un.load("opengl_logo_un.tga")
コード例 #5
0
ファイル: Renderer.py プロジェクト: rbgross/pyTANG
    def initialize(self):
        glfw.Init()
        glfw.OpenWindowHint(glfw.FSAA_SAMPLES, 4)
        glfw.OpenWindowHint(glfw.OPENGL_VERSION_MAJOR, 3)
        glfw.OpenWindowHint(glfw.OPENGL_VERSION_MINOR, 2)  # 3.2
        glfw.OpenWindowHint(glfw.OPENGL_PROFILE,
                            glfw.OPENGL_CORE_PROFILE)  # 3.2
        glfw.OpenWindowHint(glfw.OPENGL_FORWARD_COMPAT, GL_TRUE)  # 3.2
        glfw.OpenWindowHint(glfw.WINDOW_NO_RESIZE, GL_TRUE)

        try:  # in case we fail to init this version
            glfw.OpenWindow(self.windowWidth, self.windowHeight, 0, 0, 0, 0,
                            24, 8, glfw.WINDOW)
        except Exception as e:
            self.logger.warn("Failed to initialize OpenGL: {}".format(str(e)))
            self.logger.warn("Trying lower version...")
            glfw.OpenWindowHint(glfw.OPENGL_VERSION_MINOR, 0)  # 3.0
            glfw.OpenWindowHint(glfw.OPENGL_PROFILE, 0)  # 3.0
            glfw.OpenWindowHint(glfw.OPENGL_FORWARD_COMPAT, GL_FALSE)  # 3.0
            glfw.OpenWindow(self.windowWidth, self.windowHeight, 0, 0, 0, 0,
                            24, 8, glfw.WINDOW)
            self.logger.warn("OpenGL fallback to lower version worked")

        glfw.SetWindowTitle("TANG")
        glfw.SetWindowCloseCallback(self.onWindowClose)

        glEnable(GL_DEPTH_TEST)
        glEnable(GL_CULL_FACE)

        # Find out OpenGL version, and store for future use
        self.context.GL_version_string = glGetString(GL_VERSION).split(
            ' '
        )[0]  # must have version at the beginning, e.g. "3.0 Mesa 9.x.x" to extract "3.0"
        self.context.GL_version_major, self.context.GL_version_minor = list(
            int(x) for x in self.context.GL_version_string.split('.'))[
                0:2]  # must have only MAJOR.MINOR
        self.logger.info("OpenGL version {}.{}".format(
            self.context.GL_version_major, self.context.GL_version_minor))
        self.context.GLSL_version_string = glGetString(
            GL_SHADING_LANGUAGE_VERSION).split(' ')[0].replace(
                '.', '')  # "1.50" => "150"
        self.logger.info("GLSL version {}".format(
            self.context.GLSL_version_string))
コード例 #6
0
def init():
    width = 1024
    height = 768
    glfw.Init()
    glfw.OpenWindow(width, height, 8, 8, 8, 0, 24, 0, glfw.WINDOW)
    glfw.SetWindowTitle("glfw line")
    glfw.SetWindowSizeCallback(Reshape)
    glfw.SetMouseButtonCallback(MouseHandler)
    glfw.SetKeyCallback(KeyboardHandler)
    glfw.SetWindowCloseCallback(WindowCLose)

    glClearColor(0.0, 0.0, 0.0, 0.0)
    glEnable(GL_TEXTURE_2D)

    global texture1, texture2, textureOne, textureTwo
    if (not texture1.load("opengl_logo.tga")):
        exit(0)
    if (not texture2.load("checkerboard.tga")):
        exit(0)

    print texture1.m_width, texture1.m_height

    # texture one
    textureOne = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, textureOne)
    # filter for min and mag texture
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)

    # specify the texture
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture1.m_width, texture1.m_height,
                 0, GL_RGB, GL_UNSIGNED_BYTE, texture1.m_imageData)

    # texure two
    textureTwo = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, textureTwo)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture2.m_width, texture2.m_height,
                 0, GL_RGB, GL_UNSIGNED_BYTE, texture2.m_imageData)
コード例 #7
0
    def __init__(self, scene):
        """Sets up the core functionality we need
        to begin rendering.
        This includes the OpenGL configuration, the
        window, the viewport, the event handler
        and update loop registration.
        """
        super(Application, self).__init__(scene)

        glfw.Init()

        if self.scene.core_profile:
            glfw.OpenWindowHint(glfw.OPENGL_VERSION_MAJOR, 3)
            glfw.OpenWindowHint(glfw.OPENGL_VERSION_MINOR, 2)
            glfw.OpenWindowHint(glfw.OPENGL_FORWARD_COMPAT, GL.GL_TRUE)
            glfw.OpenWindowHint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)

        # create our window
        glfw.OpenWindow(1024, 768, 8, 8, 8, 8, 24, 0, glfw.WINDOW)

        # set the window caption
        glfw.SetWindowTitle("PyGLy - PyGLFW - " + scene.name)

        # print some opengl information
        pygly.gl.print_gl_info()

        # create the scene now that we've got our window open
        self.scene.initialise()

        self.running = False

        # listen for resize events and close window events
        # do this AFTER initialising the scene
        # as the window size callback will trigger once set
        glfw.SetWindowSizeCallback(self.on_window_resized)
        glfw.SetWindowCloseCallback(self.on_window_closed)
        glfw.SetKeyCallback(self.on_key_event)
コード例 #8
0
ファイル: test.py プロジェクト: shdwdln/pyglfw
glfw.OpenWindow(800, 600, 0, 0, 0, 8, 0, 0, glfw.WINDOW)

print("OpenGL version: %d.%d.%d\n" % glfw.GetGLVersion())

glfw.ext.set_icons([(icon_data, icon_width, icon_height)])
glfw.SetWindowTitle("pyglfw test")
glfw.Disable(glfw.AUTO_POLL_EVENTS)
glfw.Enable(glfw.KEY_REPEAT)

center_x = glfw.GetDesktopMode().Width / 2 - glfw.GetWindowSize()[0] / 2
center_y = glfw.GetDesktopMode().Height / 2 - glfw.GetWindowSize()[1] / 2

glfw.SetWindowPos(center_x, center_y)

glfw.SetWindowSizeCallback(on_resize)
glfw.SetWindowCloseCallback(on_close)
glfw.SetWindowRefreshCallback(on_refresh)
glfw.SetKeyCallback(on_key)
glfw.SetCharCallback(on_char)
glfw.SetMouseButtonCallback(on_button)
glfw.SetMousePosCallback(on_pos)
glfw.SetMouseWheelCallback(on_scroll)

while glfw.GetWindowParam(glfw.OPENED):
    glfw.PollEvents()

    if glfw.GetKey(glfw.KEY_ESC):
        break

    glClear(GL_COLOR_BUFFER_BIT)
    glfw.SwapBuffers()