def create(x=None, y=None, w=None, h=None, near=None, far=None, fov=DEFAULT_FOV, depth=DEFAULT_DEPTH, background=None, tk=False, window_title='', window_parent=None, mouse=False, frames_per_second=None): """ Creates a pi3d Display. *x* Left x coordinate of the display. If None, defaults to the x coordinate of the tkwindow parent, if any. *y* Top y coordinate of the display. If None, defaults to the y coordinate of the tkwindow parent, if any. *w* Width of the display. If None, full the width of the screen. *h* Height of the display. If None, full the height of the screen. *near* This will be used for the default instance of Camera *near* plane *far* This will be used for the default instance of Camera *far* plane *fov* Used to define the Camera lens field of view *depth* The bit depth of the display - must be 8, 16 or 24. *background* r,g,b,alpha (opacity) *tk* Do we use the tk windowing system? *window_title* A window title for tk windows only. *window_parent* An optional tk parent window. *mouse* Automatically create a Mouse. *frames_per_second* Maximum frames per second to render (None means "free running"). """ if tk: from pi3d.util import TkWin if not (w and h): # TODO: how do we do full-screen in tk? #LOGGER.error("Can't compute default window size when using tk") #raise Exception # ... just force full screen - TK will automatically fit itself into the screen w = 1920 h = 1180 tkwin = TkWin.TkWin(window_parent, window_title, w, h) tkwin.update() if x is None: x = tkwin.winx if y is None: y = tkwin.winy else: tkwin = None x = x or 0 y = y or 0 display = Display(tkwin) if (w or 0) <= 0: w = display.max_width - 2 * x if w <= 0: w = display.max_width if (h or 0) <= 0: h = display.max_height - 2 * y if h <= 0: h = display.max_height LOGGER.debug('Display size is w=%d, h=%d', w, h) display.frames_per_second = frames_per_second if near is None: near = DEFAULT_NEAR if far is None: far = DEFAULT_FAR display.width = w display.height = h display.near = near display.far = far display.fov = fov display.left = x display.top = y display.right = x + w display.bottom = y + h display.opengl.create_display(x, y, w, h, depth) display.mouse = None if mouse: from pi3d.Mouse import Mouse display.mouse = Mouse(width=w, height=h) display.mouse.start() # This code now replaced by camera 'lens' """opengles.glMatrixMode(GL_PROJECTION) Utility.load_identity() if is_3d: hht = near * math.tan(math.radians(aspect / 2.0)) hwd = hht * w / h opengles.glFrustumf(c_float(-hwd), c_float(hwd), c_float(-hht), c_float(hht), c_float(near), c_float(far)) opengles.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) else: opengles.glOrthof(c_float(0), c_float(w), c_float(0), c_float(h), c_float(near), c_float(far)) """ opengles.glMatrixMode(GL_MODELVIEW) Utility.load_identity() if background: display.set_background(*background) return display
def create(x=None, y=None, w=None, h=None, near=None, far=None, fov=DEFAULT_FOV, depth=DEFAULT_DEPTH, background=None, tk=False, window_title='', window_parent=None, mouse=False, frames_per_second=None, samples=DEFAULT_SAMPLES, use_pygame=False, layer=0, display_config=DISPLAY_CONFIG_DEFAULT): """ Creates a pi3d Display. *x* Left x coordinate of the display. If None, defaults to the x coordinate of the tkwindow parent, if any. *y* Top y coordinate of the display. If None, defaults to the y coordinate of the tkwindow parent, if any. *w* Width of the display. If None, full the width of the screen. *h* Height of the display. If None, full the height of the screen. *near* This will be used for the default instance of Camera *near* plane *far* This will be used for the default instance of Camera *far* plane *fov* Used to define the Camera lens field of view *depth* The bit depth of the display - must be 8, 16 or 24. *background* r,g,b,alpha (opacity) *tk* Do we use the tk windowing system? *window_title* A window title for tk windows only. *window_parent* An optional tk parent window. *mouse* Automatically create a Mouse. *frames_per_second* Maximum frames per second to render (None means "free running"). *samples* EGL_SAMPLES default 0, set to 4 for improved anti-aliasing *use_pygame* To use pygame for display surface, mouse and keyboard - as per windows This almost certainly would conflict if attempting to use in combination with tk=True. Default False *layer* display layer height - used by dispmanx on Raspberry Pi only. -128 will move the pi3d window behind the X11 desktop *display_config* Configuration of display - See pi3d.constants for DISPLAY_CONFIG options """ if tk: #NB this happens before Display created so use_pygame will not work on linux if PLATFORM != PLATFORM_PI and PLATFORM != PLATFORM_ANDROID: #just use python-xlib same as non-tk but need dummy behaviour from pi3d.Keyboard import Keyboard class DummyTkWin(object): def __init__(self): self.tkKeyboard = Keyboard() self.ev = "" self.key = "" self.winx, self.winy = 0, 0 self.width, self.height = 1920, 1180 self.event_list = [] def update(self): if PLATFORM == PLATFORM_WINDOWS or pi3d.USE_PYGAME: #uses pygame UI k = self.tkKeyboard.read() if k == -1: self.key = "" self.ev = "" else: if k == 27: self.key = "Escape" else: self.key = chr(k) self.ev = "key" else: self.key = self.tkKeyboard.read_code() if self.key == "": self.ev = "" else: self.ev = "key" tkwin = DummyTkWin() x = x or 0 y = y or 0 else: from pi3d.util import TkWin if not (w and h): # TODO: how do we do full-screen in tk? #LOGGER.error('Can't compute default window size when using tk') #raise Exception # ... just force full screen - TK will automatically fit itself into the screen w = 1920 h = 1180 if background is not None: bg_i = [int(i * 255) for i in background] bg = '#{:02X}{:02X}{:02X}'.format(bg_i[0], bg_i[1], bg_i[2]) else: bg = '#000000' tkwin = TkWin.TkWin(window_parent, window_title, w, h, bg) tkwin.update() w = tkwin.winfo_width() h = tkwin.winfo_height() if x is None: x = tkwin.winx if y is None: y = tkwin.winy else: tkwin = None x = x or 0 y = y or 0 display = Display(tkwin, use_pygame) if (w or 0) <= 0: w = display.max_width - 2 * x if w <= 0: w = display.max_width if (h or 0) <= 0: h = display.max_height - 2 * y if h <= 0: h = display.max_height LOGGER.debug('Display size is w=%d, h=%d', w, h) display.frames_per_second = frames_per_second if near is None: near = DEFAULT_NEAR if far is None: far = DEFAULT_FAR display.width = w display.height = h display.near = near display.far = far display.fov = fov display.left = x display.top = y display.right = x + w display.bottom = y + h display.layer = layer display.opengl.create_display(x, y, w, h, depth=depth, samples=samples, layer=layer, display_config=display_config) if PLATFORM == PLATFORM_ANDROID: display.width = display.right = display.max_width = display.opengl.width #not available until after create_display display.height = display.bottom = display.max_height = display.opengl.height display.top = display.bottom = 0 if frames_per_second is not None: display.android.frames_per_second = frames_per_second display.frames_per_second = None #to avoid clash between two systems! display.mouse = None if mouse: from pi3d.Mouse import Mouse display.mouse = Mouse(width=w, height=h, restrict=False) display.mouse.start() if background is not None: display.set_background(*background) return display
def create(x=None, y=None, w=None, h=None, near=None, far=None, fov=DEFAULT_FOV, depth=DEFAULT_DEPTH, background=None, tk=False, window_title='', window_parent=None, mouse=False, frames_per_second=None): """ Creates a pi3d Display. *x* Left x coordinate of the display. If None, defaults to the x coordinate of the tkwindow parent, if any. *y* Top y coordinate of the display. If None, defaults to the y coordinate of the tkwindow parent, if any. *w* Width of the display. If None, full the width of the screen. *h* Height of the display. If None, full the height of the screen. *near* This will be used for the default instance of Camera *near* plane *far* This will be used for the default instance of Camera *far* plane *fov* Used to define the Camera lens field of view *depth* The bit depth of the display - must be 8, 16 or 24. *background* r,g,b,alpha (opacity) *tk* Do we use the tk windowing system? *window_title* A window title for tk windows only. *window_parent* An optional tk parent window. *mouse* Automatically create a Mouse. *frames_per_second* Maximum frames per second to render (None means "free running"). """ if tk: if PLATFORM != PLATFORM_PI: #just use python-xlib same as non-tk but need dummy behaviour class DummyTkWin(object): def __init__(self): self.tkKeyboard = Keyboard() self.ev = "" self.key = "" self.winx, self.winy = 0, 0 self.width, self.height = 1920, 1180 self.event_list = [] def update(self): self.key = self.tkKeyboard.read_code() if self.key == "": self.ev = "" else: self.ev = "key" tkwin = DummyTkWin() x = x or 0 y = y or 0 else: from pi3d.util import TkWin if not (w and h): # TODO: how do we do full-screen in tk? #LOGGER.error('Can't compute default window size when using tk') #raise Exception # ... just force full screen - TK will automatically fit itself into the screen w = 1920 h = 1180 tkwin = TkWin.TkWin(window_parent, window_title, w, h) tkwin.update() if x is None: x = tkwin.winx if y is None: y = tkwin.winy else: tkwin = None x = x or 0 y = y or 0 display = Display(tkwin) if (w or 0) <= 0: w = display.max_width - 2 * x if w <= 0: w = display.max_width if (h or 0) <= 0: h = display.max_height - 2 * y if h <= 0: h = display.max_height LOGGER.debug('Display size is w=%d, h=%d', w, h) display.frames_per_second = frames_per_second if near is None: near = DEFAULT_NEAR if far is None: far = DEFAULT_FAR display.width = w display.height = h display.near = near display.far = far display.fov = fov display.left = x display.top = y display.right = x + w display.bottom = y + h display.opengl.create_display(x, y, w, h, depth) display.mouse = None if mouse: from pi3d.Mouse import Mouse display.mouse = Mouse(width=w, height=h, restrict=False) display.mouse.start() if background: display.set_background(*background) return display