示例#1
0
    def __init__(self, app_id, fullscreen=False):
        glut.glutInit()
        glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA)

        if fullscreen:
            glut.glutGameModeString('1920x1080:32@60')
            glut.glutEnterGameMode()
        else:
            glut.glutInitWindowPosition(100, 100)
            glut.glutInitWindowSize(1024, 768)
            glut.glutCreateWindow('steampak demo')

        glut.glutDisplayFunc(self.redraw)
        glut.glutIdleFunc(self.redraw)
        glut.glutKeyboardFunc(self.keypress)

        self.api = SteamApi(LIBRARY_PATH, app_id=app_id)
示例#2
0
文件: glbase.py 项目: ivorjawa/BoarGL
def init_gl(argv, win_name="BoarGL Application"):
    # Glut init
    # --------------------------------------
    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE |
                             glut.GLUT_RGBA |
                             glut.GLUT_DEPTH  |
                             glut.GLUT_3_2_CORE_PROFILE)

    if "-w" in argv:
        print "creating window"
        glut.glutCreateWindow(win_name)
    else:
        print "going fullscreen"
        glut.glutGameModeString("2880x1800:32@60")
        # The application will enter fullscreen
        glut.glutEnterGameMode()

    print gl.glGetString(gl.GL_RENDERER)
    print gl.glGetString(gl.GL_VERSION)

    # OpenGL initalization
    gl.glClearColor(0, 0, 0, 1)

    # hide mouse cursor
    glut.glutSetCursor(glut.GLUT_CURSOR_NONE)

    gl.glEnable(gl.GL_BLEND)
    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

    gl.glEnable(gl.GL_CULL_FACE);
    gl.glCullFace(gl.GL_BACK);
    gl.glFrontFace(gl.GL_CCW);

    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glDepthMask(gl.GL_TRUE);
    gl.glDepthFunc(gl.GL_LEQUAL);
    gl.glDepthRange(0.0, 1.0);

    gl.GL_TEXTURE_WRAP_S = gl.GL_CLAMP_TO_EDGE
    gl.GL_TEXTURE_WRAP_T = gl.GL_CLAMP_TO_EDGE

    gl.glPolygonOffset(1, 1)
    gl.glEnable(gl.GL_LINE_SMOOTH)
    gl.glLineWidth(0.75)
示例#3
0
文件: main.py 项目: toru-ver4/sip
    gl.glVertex3d(1.0, -1.0, 0.0)  # Top Left
    gl.glTexCoord2f(1.0, 0.0)
    gl.glVertex3d(1.0, 1.0, 0.0)  # Top Right
    gl.glTexCoord2f(0.0, 0.0)
    gl.glVertex3d(-1.0, 1.0, 0.0)  # Bottom Right
    gl.glEnd()
    gl.glDisable(gl.GL_TEXTURE_2D)
    # gl.glFinish()
    gl.glFlush()


if __name__ == '__main__':
    game_mode = True
    glut.glutInit(sys.argv)
    g_window_width, g_window_height = get_winodw_resolution()
    glut.glutInitWindowSize(g_window_width, g_window_height)
    glut.glutInitDisplayString(b"red=10 green=10 blue=10 alpha=2")
    # glut.glutInitDisplayMode(glut.GLUT_RGBA | glut.GLUT_DEPTH)
    glut.glutInitDisplayMode(glut.GLUT_RGBA)
    if game_mode:
        mode_string = "{}x{}:32@60".format(g_window_width, g_window_height)
        glut.glutGameModeString(mode_string)
        glut.glutEnterGameMode()
    else:
        glut.glutCreateWindow(b"30bit demo")
    glut.glutDisplayFunc(display)
    glut.glutReshapeFunc(resize)
    glut.glutKeyboardFunc(keyboard)
    init()
    glut.glutMainLoop()
示例#4
0
def tiny_glut(args):
    global vertex_code, fragment_code
    scale = 0.01

    def display():
        CAMERA.render()
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        nonlocal scale
        scale_location = gl.glGetUniformLocation(program, "gScale")
        assert scale_location != 0xffffffff
        world_location = gl.glGetUniformLocation(program, "gWorld")
        assert world_location != 0xffffffff

        scale += 0.01

        pipeline = Pipeline(
            rotation=[0.0, 30 * scale, 0.0],
            # scaling=[math.sin(scale)] * 3,
            translation=[0, 0, 6],
            projection=ProjParams(WINDOW_WIDTH, WINDOW_HEIGHT, 1.0, 100.0,
                                  60.0))
        pipeline.set_camera(CAMERA)

        gl.glUniformMatrix4fv(world_location, 1, gl.GL_TRUE,
                              pipeline.get_wvp())
        gl.glDrawElements(gl.GL_TRIANGLES, 18, gl.GL_UNSIGNED_INT,
                          ctypes.c_void_p(0))
        glut.glutSwapBuffers()
        # glut.glutPostRedisplay()

    def mouse(x, y):
        CAMERA.mouse(x, y)

    def keyboard(key, x, y):
        if key == glut.GLUT_KEY_F1:
            sys.exit(0)
        elif key == glut.GLUT_KEY_HOME:
            CAMERA.setup()
        else:
            CAMERA.keyboard(key)

    glut.glutInit(args)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA
                             | glut.GLUT_3_2_CORE_PROFILE)
    glut.glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT)
    glut.glutInitWindowPosition(400, 100)
    # glut.glutCreateWindow("Camera Tutorial")
    glut.glutGameModeString("1920x1200@32")
    glut.glutEnterGameMode()

    # callbacks initialization
    glut.glutDisplayFunc(display)
    glut.glutIdleFunc(display)
    # glut.glutKeyboardFunc(keyboard)
    glut.glutPassiveMotionFunc(mouse)
    glut.glutSpecialFunc(keyboard)

    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glDepthFunc(gl.GL_LESS)
    gl.glClearColor(0, 0, 0, 0)

    vertices = np.array([-1, -1, 0, 0, -1, -1, 1, -1, 0, 0, -1, 1, 0, 1, 0],
                        dtype=np.float32)

    indexes = np.array([0, 1, 2, 1, 2, 3, 0, 1, 4, 1, 2, 4, 2, 3, 4, 3, 0, 4],
                       dtype=np.uint32)

    vertex_shader = gl.glCreateShader(gl.GL_VERTEX_SHADER)
    gl.glShaderSource(vertex_shader, vertex_code)
    gl.glCompileShader(vertex_shader)

    if not gl.glGetShaderiv(vertex_shader, gl.GL_COMPILE_STATUS):
        info = gl.glGetShaderInfoLog(vertex_shader)
        print("vertex shader error occurred")
        print(bytes.decode(info))
        return

    fragment_shader = gl.glCreateShader(gl.GL_FRAGMENT_SHADER)
    gl.glShaderSource(fragment_shader, fragment_code)
    gl.glCompileShader(fragment_shader)

    if not gl.glGetShaderiv(fragment_shader, gl.GL_COMPILE_STATUS):
        info = gl.glGetShaderInfoLog(fragment_shader)
        print("fragment shader error occurred")
        print(bytes.decode(info))
        return

    program = gl.glCreateProgram()
    gl.glAttachShader(program, vertex_shader)
    gl.glAttachShader(program, fragment_shader)
    gl.glLinkProgram(program)
    gl.glUseProgram(program)

    vao = gl.glGenVertexArrays(1)
    gl.glBindVertexArray(vao)

    vbo = gl.glGenBuffers(1)
    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, vbo)
    gl.glBufferData(gl.GL_ARRAY_BUFFER, vertices.nbytes, vertices,
                    gl.GL_STATIC_DRAW)
    gl.glEnableVertexAttribArray(0)
    gl.glVertexAttribPointer(0, 3, gl.GL_FLOAT, gl.GL_FALSE, 0,
                             ctypes.c_void_p(0))

    ibo = gl.glGenBuffers(1)
    gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, ibo)
    gl.glBufferData(gl.GL_ELEMENT_ARRAY_BUFFER, indexes.nbytes, indexes,
                    gl.GL_STATIC_DRAW)
    glut.glutMainLoop()
示例#5
0
def tiny_glut(args):
    global vertex_code, fragment_code
    scale = 0.01

    def display():
        CAMERA.render()
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        nonlocal scale
        scale_location = gl.glGetUniformLocation(program, "gScale")
        assert scale_location != 0xffffffff
        world_location = gl.glGetUniformLocation(program, "gWorld")
        assert world_location != 0xffffffff

        scale += 0.01

        pipeline = Pipeline(rotation=[0.0, 30*scale, 0.0],
                            # scaling=[math.sin(scale)] * 3,
                            translation=[0, 0, 6],
                            projection=ProjParams(WINDOW_WIDTH, WINDOW_HEIGHT, 1.0, 100.0, 60.0))
        pipeline.set_camera(CAMERA)

        gl.glUniformMatrix4fv(world_location, 1, gl.GL_TRUE, pipeline.get_wvp())
        gl.glDrawElements(gl.GL_TRIANGLES, 18, gl.GL_UNSIGNED_INT, ctypes.c_void_p(0))
        glut.glutSwapBuffers()
        # glut.glutPostRedisplay()

    def mouse(x, y):
        CAMERA.mouse(x, y)

    def keyboard(key, x, y):
        if key == glut.GLUT_KEY_F1:
            sys.exit(0)
        elif key == glut.GLUT_KEY_HOME:
            CAMERA.setup()
        else:
            CAMERA.keyboard(key)

    glut.glutInit(args)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_3_2_CORE_PROFILE)
    glut.glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT)
    glut.glutInitWindowPosition(400, 100)
    # glut.glutCreateWindow("Camera Tutorial")
    glut.glutGameModeString("1920x1200@32")
    glut.glutEnterGameMode()

    # callbacks initialization
    glut.glutDisplayFunc(display)
    glut.glutIdleFunc(display)
    # glut.glutKeyboardFunc(keyboard)
    glut.glutPassiveMotionFunc(mouse)
    glut.glutSpecialFunc(keyboard)

    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glDepthFunc(gl.GL_LESS)
    gl.glClearColor(0, 0, 0, 0)

    vertices = np.array([
        -1, -1, 0,
        0, -1, -1,
        1, -1, 0,
        0, -1, 1,
        0, 1, 0
    ], dtype=np.float32)

    indexes = np.array([
        0, 1, 2,
        1, 2, 3,
        0, 1, 4,
        1, 2, 4,
        2, 3, 4,
        3, 0, 4
    ], dtype=np.uint32)

    vertex_shader = gl.glCreateShader(gl.GL_VERTEX_SHADER)
    gl.glShaderSource(vertex_shader, vertex_code)
    gl.glCompileShader(vertex_shader)

    if not gl.glGetShaderiv(vertex_shader, gl.GL_COMPILE_STATUS):
        info = gl.glGetShaderInfoLog(vertex_shader)
        print("vertex shader error occurred")
        print(bytes.decode(info))
        return

    fragment_shader = gl.glCreateShader(gl.GL_FRAGMENT_SHADER)
    gl.glShaderSource(fragment_shader, fragment_code)
    gl.glCompileShader(fragment_shader)

    if not gl.glGetShaderiv(fragment_shader, gl.GL_COMPILE_STATUS):
        info = gl.glGetShaderInfoLog(fragment_shader)
        print("fragment shader error occurred")
        print(bytes.decode(info))
        return

    program = gl.glCreateProgram()
    gl.glAttachShader(program, vertex_shader)
    gl.glAttachShader(program, fragment_shader)
    gl.glLinkProgram(program)
    gl.glUseProgram(program)

    vao = gl.glGenVertexArrays(1)
    gl.glBindVertexArray(vao)

    vbo = gl.glGenBuffers(1)
    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, vbo)
    gl.glBufferData(gl.GL_ARRAY_BUFFER, vertices.nbytes, vertices, gl.GL_STATIC_DRAW)
    gl.glEnableVertexAttribArray(0)
    gl.glVertexAttribPointer(0, 3, gl.GL_FLOAT, gl.GL_FALSE, 0, ctypes.c_void_p(0))

    ibo = gl.glGenBuffers(1)
    gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, ibo)
    gl.glBufferData(gl.GL_ELEMENT_ARRAY_BUFFER, indexes.nbytes, indexes, gl.GL_STATIC_DRAW)
    glut.glutMainLoop()