Esempio n. 1
0
def csaaScreenshot(useNVidiaAA, width, height, scene):
    try:
        csaaFmt = trinity.TRIMULTISAMPLE_8_SAMPLES if useNVidiaAA else trinity.TRIMULTISAMPLE_NONE
        csaaQty = 2 if useNVidiaAA else 0
        buffer = trinity.Tr2RenderTarget(width, height, 1,
                                         trinity.PIXEL_FORMAT.B8G8R8X8_UNORM,
                                         csaaFmt, csaaQty)
        depth = trinity.Tr2DepthStencil(width, height,
                                        trinity.DEPTH_STENCIL_FORMAT.D24S8,
                                        csaaFmt, csaaQty)
        job = trinity.CreateRenderJob('CSAA screenshot')
        job.SetRenderTarget(buffer)
        job.SetDepthStencil(depth)
        vp = trinity.TriViewport()
        vp.x = 0
        vp.y = 0
        vp.width = width
        vp.height = height
        job.SetViewport(vp)
        job.Clear((0, 0, 0, 0), 1.0)
        job.RenderScene(scene)
        trinity.SetPerspectiveProjection(trinity.GetFieldOfView(),
                                         trinity.GetFrontClip(),
                                         trinity.GetBackClip(), 1.0)
        job.ScheduleOnce()
        return (job, buffer)
    except Exception:
        return None
def csaaScreenshot(useNVidiaAA, width, height, scene):
    """
    Create a renderjob that will render the scene into a buffer using CSAA, if available.
    Returns ( job, buffer ) (which can be None if you ask for CSAA and it doesn't work).
    Use Tr2HostBitmap(buffer).Save or whatever to get to the data, after doing WaitForFinish if needed
    """
    try:
        csaaFmt = trinity.TRIMULTISAMPLE_8_SAMPLES if useNVidiaAA else trinity.TRIMULTISAMPLE_NONE
        csaaQty = 2 if useNVidiaAA else 0
        buffer = trinity.Tr2RenderTarget(width, height, 1,
                                         trinity.PIXEL_FORMAT.B8G8R8X8_UNORM,
                                         csaaFmt, csaaQty)
        depth = trinity.Tr2DepthStencil(width, height,
                                        trinity.DEPTH_STENCIL_FORMAT.D24S8,
                                        csaaFmt, csaaQty)
        job = trinity.CreateRenderJob('CSAA screenshot')
        job.SetRenderTarget(buffer)
        job.SetDepthStencil(depth)
        vp = trinity.TriViewport()
        vp.x = 0
        vp.y = 0
        vp.width = width
        vp.height = height
        job.SetViewport(vp)
        job.Clear((0, 0, 0, 0), 1.0)
        job.RenderScene(scene)
        trinity.SetPerspectiveProjection(trinity.GetFieldOfView(),
                                         trinity.GetFrontClip(),
                                         trinity.GetBackClip(), 1.0)
        job.ScheduleOnce()
        return (job, buffer)
    except Exception:
        return None
Esempio n. 3
0
def Main(postCreateCallback=None,
         fullscreen=False,
         size=None,
         windowType=WT_DEFAULT_FRAME):
    hwnd = CreateWindow(fullscreen, size, windowType)
    CreateDevice(hwnd, fullscreen)
    w, h = GetWindowSize(hwnd)
    asp = float(w) / float(h)
    trinity.SetPerspectiveProjection(1.57, 1.0, 1000.0, asp)
    if postCreateCallback and callable(postCreateCallback):
        postCreateCallback()
    RunTestScript()
    msg = MSG()
    pMsg = ctypes.pointer(msg)
    running = True
    TranslateMessage = ctypes.windll.user32.TranslateMessage
    DispatchMessageA = ctypes.windll.user32.DispatchMessageA
    PeekMessageA = ctypes.windll.user32.PeekMessageA
    while running:
        while PeekMessageA(pMsg, NULL, 0, 0, 1):
            if msg.message == WM_QUIT:
                running = False
                break
            TranslateMessage(pMsg)
            DispatchMessageA(pMsg)

        blue.os.Pump()

    ctypes.windll.user32.PostQuitMessage(0)
    return msg.wParam
Esempio n. 4
0
 def Update(self):
     parentMat = geo2.MatrixTranslation(*self.parentPos)
     viewInv = geo2.MatrixInverse(self.localViewMatrix)
     newT = geo2.MatrixMultiply(viewInv, parentMat)
     self.viewMatrix = geo2.MatrixInverse(newT)
     trinity.SetViewTransform(self.viewMatrix)
     trinity.SetPerspectiveProjection(self.fieldOfView, self.frontClip, self.backClip, self.aspectRatio)
     self.projection.PerspectiveFov(self.fieldOfView, self.aspectRatio, self.frontClip, self.backClip)
Esempio n. 5
0
def Main(postCreateCallback = None, fullscreen = False, size = None, windowType = WT_DEFAULT_FRAME):
    hwnd = CreateWindow(fullscreen, size, windowType)
    CreateDevice(hwnd, fullscreen)
    w, h = GetWindowSize(hwnd)
    asp = float(w) / float(h)
    trinity.SetPerspectiveProjection(1.57, 1.0, 1000.0, asp)
    if postCreateCallback and callable(postCreateCallback):
        postCreateCallback()
    RunTestScript()
    MinimeMainLoop()
Esempio n. 6
0
def WndProc(hwnd, message, wParam, lParam):
    dev = trinity.device
    if message == WM_DESTROY:
        blue.os.Terminate()
        return 0
    elif message == WM_CLOSE:
        blue.os.Terminate()
        return 0
    if message == WM_SIZE:
        if dev.GetWindow():
            rect = RECT()
            ctypes.windll.user32.GetClientRect(hwnd, ctypes.byref(rect))
            viewTrans = trinity.GetViewTransform()
            fov = trinity.GetFieldOfView()
            front = trinity.GetFrontClip()
            back = trinity.GetBackClip()
            w, h = rect.right, rect.bottom
            defaultBackBuffer = trinity.device.GetRenderContext().GetDefaultBackBuffer()
            if w == defaultBackBuffer.width and h == defaultBackBuffer.height:
                return 0
            asp = float(w) / float(h)
            dev.ChangeBackBufferSize(w, h)
            trinity.SetPerspectiveProjection(fov, front, back, asp)
            trinity.SetViewTransform(viewTrans)
    elif message == WM_LBUTTONDOWN:
        rect = RECT()
        ctypes.windll.user32.GetClientRect(hwnd, ctypes.byref(rect))
        offset = POINT()
        ctypes.windll.user32.ClientToScreen(hwnd, ctypes.byref(offset))
        ctypes.windll.user32.OffsetRect(ctypes.byref(rect), offset.x, offset.y)
        ctypes.windll.user32.ClipCursor(ctypes.byref(rect))
        PostOnMouse('LEFT_BUTTON_DOWN', wParam, lParam)
    elif message == WM_LBUTTONUP:
        ctypes.windll.user32.ClipCursor(0)
        PostOnMouse('LEFT_BUTTON_UP', wParam, lParam)
    elif message == WM_LBUTTONDBLCLK:
        PostOnMouse('LEFT_BUTTON_DBLCLK', wParam, lParam)
    elif message == WM_RBUTTONUP:
        PostOnMouse('RIGHT_BUTTON_UP', wParam, lParam)
    elif message == WM_RBUTTONDOWN:
        PostOnMouse('RIGHT_BUTTON_DOWN', wParam, lParam)
    elif message == WM_RBUTTONDBLCLK:
        PostOnMouse('RIGHT_BUTTON_DBLCLK', wParam, lParam)
    elif message == WM_MBUTTONUP:
        PostOnMouse('MIDDLE_BUTTON_UP', wParam, lParam)
    elif message == WM_MBUTTONDOWN:
        PostOnMouse('MIDDLE_BUTTON_DOWN', wParam, lParam)
    elif message == WM_MBUTTONDBLCLK:
        PostOnMouse('MIDDLE_BUTTON_DBLCLK', wParam, lParam)
    elif message == WM_MOUSEMOVE:
        PostOnMouse('MOUSE_MOVE', wParam, lParam)
    elif message == WM_MOUSEWHEEL:
        PostOnMouse('MOUSE_WHEEL', wParam, lParam)
    elif message == WM_ACTIVATE:
        if not (wParam == WA_ACTIVE and wParam == WA_CLICKACTIVE):
            ctypes.windll.user32.ClipCursor(0)
    elif message == WM_SYSCOMMAND:
        if wParam == SC_KEYMENU:
            return 0
    else:
        if message == WM_ERASEBKGND:
            return 0
        if message == WM_KEYDOWN:
            if OnKeyDown is not None and callable(OnKeyDown):
                OnKeyDown(wParam)
        elif message == WM_KEYUP:
            if OnKeyUp is not None and callable(OnKeyUp):
                OnKeyUp(wParam)
        elif message == WM_CHAR:
            if OnChar is not None and callable(OnChar):
                OnChar(wParam)
    if uilib is not None:
        try:
            return int(uilib.OnAppEvent(message, wParam, lParam))
        except:
            import traceback
            traceback.print_exc()

        return 0
    else:
        return ctypes.windll.user32.DefWindowProcA(ctypes.c_int(hwnd), ctypes.c_int(message), ctypes.c_int(wParam), ctypes.c_int(lParam))