def __init__(clock=None, framerate=None, backend=None):
    """ Initialize the main loop

    Parameters
    ----------
    clock : Clock
        clock to use to run the app (gives the elementary tick)

    framerate : int
        frames per second

    backend : python module
        Backend module
    """

    global __clock__

    options = parser.get_options()

    if options.debug:
        log.setLevel(logging.DEBUG)

    if framerate is None:
        framerate = options.framerate
    if framerate > 0:
        log.info("Running at %d frames/second" % framerate)
    else:
        log.info("Running at full speed")

    if clock is None:
        __clock__ = _clock.get_default()
    else:
        __clock__ = clock
    __clock__.set_fps_limit(framerate)

    # OpenGL Initialization
    gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1)
    gl.glPixelStorei(gl.GL_PACK_ALIGNMENT, 1)
    gl.glEnable(gl.GL_VERTEX_PROGRAM_POINT_SIZE)
    gl.glEnable(gl.GL_POINT_SPRITE)
    gl.glEnable(gl.GL_BLEND)
    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

    # Initialize timers for all windows
    for window in backend.windows():
        window._clock = __clock__

        # Start timers
        for i in range(len(window._timer_stack)):
            handler, interval = window._timer_stack[i]
            __clock__.schedule_interval(handler, interval)

        # Dispatch init event
        window.dispatch_event('on_init')

        # Dispatch an initial resize event
        window.dispatch_event('on_resize', window._width, window._height)

    return __clock__
Exemple #2
0
# Author: Tomas Hodan ([email protected])
# Center for Machine Perception, Czech Technical University in Prague

# Renders rgb/depth image of a 3D mesh model.

import numpy as np
from glumpy import app, gloo, gl

# Set backend (http://glumpy.readthedocs.io/en/latest/api/app-backends.html)
# app.use('pyglet')
# app.use('freeglut')

# Set logging level
from glumpy.log import log
import logging
log.setLevel(logging.WARNING) # ERROR, WARNING, DEBUG, INFO

# Color vertex shader
#-------------------------------------------------------------------------------
_color_vertex_code = """
uniform mat4 u_mv;
uniform mat4 u_mvp;
uniform vec3 u_light_eye_pos;

attribute vec3 a_position;
attribute vec3 a_color;

varying vec3 v_color;
varying vec3 v_eye_pos;
varying vec3 v_L;
Exemple #3
0
# Renders rgb/depth image of a 3D mesh model.
from __future__ import print_function, division
import numpy as np
from glumpy import app, gloo, gl

# Set backend (http://glumpy.readthedocs.io/en/latest/api/app-backends.html)
app.use("glfw")
# app.use('qt5')
# app.use('pyside')

# Set logging level
from glumpy.log import log
import logging

log.setLevel(logging.WARNING)  # ERROR, WARNING, DEBUG, INFO

# Color vertex shader
# -------------------------------------------------------------------------------
_color_vertex_code = """
uniform mat4 u_mv;
uniform mat4 u_nm;
uniform mat4 u_mvp;
uniform vec3 u_light_eye_pos;

attribute vec3 a_position;
attribute vec3 a_normal;
attribute vec3 a_color;
attribute vec2 a_texcoord;

varying vec3 v_color;
Exemple #4
0
# Author: Tomas Hodan ([email protected])
# Center for Machine Perception, Czech Technical University in Prague
"""A Python based renderer."""

import os
import numpy as np
from glumpy import app, gloo, gl

from bop_toolkit_lib import inout
from bop_toolkit_lib import misc
from bop_toolkit_lib import renderer

# Set glumpy logging level.
from glumpy.log import log
import logging
log.setLevel(logging.WARNING)  # Options: ERROR, WARNING, DEBUG, INFO.

# Set backend (http://glumpy.readthedocs.io/en/latest/api/app-backends.html).
# app.use('glfw')  # Options: 'glfw', 'qt5', 'pyside', 'pyglet'.

# RGB vertex shader.
_rgb_vertex_code = """
uniform mat4 u_mv;
uniform mat4 u_nm;
uniform mat4 u_mvp;
uniform vec3 u_light_eye_pos;

attribute vec3 a_position;
attribute vec3 a_normal;
attribute vec3 a_color;
attribute vec2 a_texcoord;
Exemple #5
0
def __init__(clock=None, framerate=None, backend=None):
    """ Initialize the main loop

    Parameters
    ----------
    clock : Clock
        clock to use to run the app (gives the elementary tick)

    framerate : int
        frames per second

    backend : python module
        Backend module
    """

    global __clock__

    options = parser.get_options()

    if options.debug:
        log.setLevel(logging.DEBUG)

    if framerate is None:
        framerate = options.framerate
    if framerate > 0:
        log.info("Running at %d frames/second" % framerate)
    else:
        log.info("Running at full speed")


    if clock is None:
        __clock__ = _clock.get_default()
    else:
        __clock__ = clock
    __clock__.set_fps_limit(framerate)

    # OpenGL Initialization
    for window in backend.windows():
        window.activate()
        gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1)
        gl.glPixelStorei(gl.GL_PACK_ALIGNMENT, 1)
        gl.glEnable(gl.GL_VERTEX_PROGRAM_POINT_SIZE)
        gl.glEnable(gl.GL_POINT_SPRITE)
        gl.glEnable(gl.GL_BLEND)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)


    # Initialize timers for all windows
    for window in backend.windows():
        window._clock = __clock__

        # Start timers
        for i in range(len(window._timer_stack)):
            handler, interval = window._timer_stack[i]
            __clock__.schedule_interval(handler, interval)

        # Activate window
        window.activate()

        # Dispatch init event
        window.dispatch_event('on_init')

        # Dispatch an initial resize event
        window.dispatch_event('on_resize', window._width, window._height)

    return __clock__
Exemple #6
0
import numpy as np
from glumpy import app, gloo, gl

# Set backend (http://glumpy.readthedocs.io/en/latest/api/app-backends.html)
app.use('glfw')

# Set logging level
from glumpy.log import log
import logging
#log.setLevel(logging.WARNING) # ERROR, WARNING, DEBUG, INFO
log.setLevel(logging.ERROR)

# Depth vertex shader
# Ref: https://github.com/julienr/vertex_visibility/blob/master/depth.py
#-------------------------------------------------------------------------------
# Getting the depth from the depth buffer in OpenGL is doable, see here:
#   http://web.archive.org/web/20130416194336/http://olivers.posterous.com/linear-depth-in-glsl-for-real
#   http://web.archive.org/web/20130426093607/http://www.songho.ca/opengl/gl_projectionmatrix.html
#   http://stackoverflow.com/a/6657284/116067
# But it is hard to get good precision, as explained in this article:
# http://dev.theomader.com/depth-precision/
#
# Once the vertex is in view space (view * model * v), its depth is simply the
# Z axis. So instead of reading from the depth buffer and undoing the projection
# matrix, we store the Z coord of each vertex in the color buffer. OpenGL allows
# for float32 color buffer components.
_depth_vertex_code = """
uniform mat4 u_mv;
uniform mat4 u_mvp;
attribute vec3 a_position;
attribute vec3 a_color;