Ejemplo n.º 1
0
def get_screen_shape():
    """Screen height and width in pixels."""
    return _gl.glutGet(_gl.GLUT_SCREEN_HEIGHT, _gl.GLUT_SCREEN_WIDTH)
Ejemplo n.º 2
0
 def position(self):
     with self:
         return _gl.glutGet(_gl.GLUT_WINDOW_Y), _gl.glutGet(
             _gl.GLUT_WINDOW_X)
Ejemplo n.º 3
0
 def position(self):
     with self:
         return _gl.glutGet(_gl.GLUT_WINDOW_Y), _gl.glutGet(_gl.GLUT_WINDOW_X)
Ejemplo n.º 4
0
 def num_children(self):
     with self:
         return _gl.glutGet(_gl.GLUT_WINDOW_NUM_CHILDREN)
Ejemplo n.º 5
0
 def shape(self):
     with self:
         return _gl.glutGet(_gl.GLUT_WINDOW_HEIGHT), _gl.glutGet(
             _gl.GLUT_WINDOW_WIDTH)
Ejemplo n.º 6
0
 def cursor(self):
     with self:
         return GlutWindow.cursors[_gl.glutGet(_gl.GLUT_WINDOW_CURSOR)]
Ejemplo n.º 7
0
    def __init__(self,
                 version=(3, 2),
                 compatibility_profile=False,
                 debug=False,
                 forward_compatible=True,
                 shape=(300, 300),
                 position=(-1, -1),
                 index=False,
                 double=False,
                 accum=False,
                 alpha=False,
                 depth=False,
                 stencil=False,
                 multisample=False,
                 stereo=False,
                 luminance=False,
                 name="",
                 hide=False):
        """Create a new GLUT window.

        `version` is the OpenGL version to use. It can be either an integer or a (major, minor) tuple.
        If `compatibility_profile` is `True`, the compatibility profile will be used instead of the core profile.
        `debug` enables OpenGL debug mode, `forward_compatible` the forward compatibility mode.
        `shape` and `position` control the initial (height, width) shape and (y, x) position of the window.
        `index` enables color index mode instead of RGBA.
        `double` enables double buffering.
        `accum`, `alpha`, `depth`, and `stencil` enable the corresponding buffers.
        `multisample` enables multisampling.
        `stereo` enables stereo buffers.
        `luminance` enables luminance rendering instead of true RGBA.
        `name` is the name of the window and its initial title.
        If `hide` is `True`, the window will initially be hidden.
        """

        self._stack = []

        self._idle_func = None
        self._display_func = None
        self._reshape_func = None
        self._mouse_func = None
        self._motion_func = None
        self._keyboard_func = None

        self._timer_funcs = {}

        def timer_func(value):
            self._timer_funcs.pop(value)()

        self._timer_func = _gl.glutTimerFunc.argtypes[1](timer_func)

        self._name = self._window_title = self._icon_title = name

        if hasattr(version, "__iter__") and not isinstance(version, str):
            _gl.glutInitContextVersion(*version)
        else:
            _gl.glutInitContextVersion(version, 0)

        _gl.glutInitContextProfile(
            _gl.GLUT_COMPATIBILITY_PROFILE if compatibility_profile else _gl.
            GLUT_CORE_PROFILE)

        _gl.glutInitContextFlags((_gl.GLUT_DEBUG if debug else 0) | (
            _gl.GLUT_FORWARD_COMPATIBLE if forward_compatible else 0))

        height, width = shape
        _gl.glutInitWindowSize(width, height)

        y, x = position
        _gl.glutInitWindowPosition(x, y)

        _gl.glutInitDisplayMode(
            (_gl.GLUT_INDEX if index else _gl.GLUT_RGBA)
            | (_gl.GLUT_DOUBLE if double else _gl.GLUT_SINGLE)
            | (_gl.GLUT_ACCUM if accum else 0)
            | (_gl.GLUT_ALPHA if alpha else 0)
            | (_gl.GLUT_DEPTH if depth else 0)
            | (_gl.GLUT_STENCIL if stencil else 0)
            | (_gl.GLUT_MULTISAMPLE if multisample else 0)
            | (_gl.GLUT_STEREO if stereo else 0)
            | (_gl.GLUT_LUMINANCE if luminance else 0))

        _gl.glutSetOption(_gl.GLUT_ACTION_ON_WINDOW_CLOSE,
                          _gl.GLUT_ACTION_CONTINUE_EXECUTION)

        if not _gl.glutGet(_gl.GLUT_DISPLAY_MODE_POSSIBLE):
            raise RuntimeError("display mode not possible")

        old_binding = context_manager.current_context
        self._id = _gl.glutCreateWindow(
            self._name.encode("utf8")
        )  # creating a window changes the current context without the context manager's knowledge
        if old_binding:
            old_binding._bind(
            )  # rebind the previous context circumventing any caching performed by the context
        else:
            context_manager.current_context = self  # tell the context manager about the changed binding

        super(GlutWindow, self).__init__()

        if hide:
            self.hide()
        else:
            self.show()
Ejemplo n.º 8
0
def get_elapsed_time():
    """Time in seconds since GLUT was initialized."""
    return _gl.glutGet(_gl.GLUT_ELAPSED_TIME) / 1000.0
Ejemplo n.º 9
0
def get_screen_shape_mm():
    """Screen height and width in millimeters."""
    return _gl.glutGet(_gl.GLUT_SCREEN_HEIGHT_MM, _gl.GLUT_SCREEN_WIDTH_MM)
Ejemplo n.º 10
0
def get_screen_shape():
    """Screen height and width in pixels."""
    return _gl.glutGet(_gl.GLUT_SCREEN_HEIGHT, _gl.GLUT_SCREEN_WIDTH)