Esempio n. 1
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    MouseStatus status;
    MouseButton button = No_Button;
    switch(msg)
    {
    case WM_SIZE:
        ResizeView(WinSys_View, LOWORD(lParam), HIWORD(lParam));
        break;
    case WM_CLOSE:
        DestroyWindow(hWnd);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    case WM_KEYDOWN:
        // (lParam bit 30) == 1 means the key was already down.
        if((lParam & (1 << 30)) == 0)
            InputReceiveKey (GetInputHandler(WinSys_View),
                            wParam,
                            Key_Down);
        break;
    case WM_KEYUP:
        InputReceiveKey(GetInputHandler(WinSys_View),
                        wParam,
                        Key_Up);
        break;
    case WM_MOUSEMOVE:
        status = Mouse_Move;
        goto mouseevent;
    case WM_LBUTTONDOWN:
    case WM_RBUTTONDOWN:
    case WM_MBUTTONDOWN:
        status = Mouse_Down;
        goto mouseevent;
    case WM_LBUTTONUP:
    case WM_RBUTTONUP:
    case WM_MBUTTONUP:
        status = Mouse_Up;
        goto mouseevent;
mouseevent:
        if(wParam & MK_LBUTTON)
            button = (MouseButton)(button | Left_Button);
        else if(wParam & MK_RBUTTON)
            button = (MouseButton)(button | Right_Button);
        else if(wParam & MK_MBUTTON)
            button = (MouseButton)(button | Mid_Button);

        InputMouseEvent(GetInputHandler(WinSys_View),
                        LOWORD(lParam),
                        HIWORD(lParam),
                        button,
                        status);
        break;
    default:
        return DefWindowProc(hWnd, msg, wParam, lParam);
    }
    return 0;
}
Esempio n. 2
0
	void CorePlatformAndroid::RenderRecreated(int32 w, int32 h)
	{
		Logger::Debug("[CorePlatformAndroid::RenderRecreated] start");

		renderIsActive = true;

		Thread::InitMainThread();

		if(wasCreated)
		{
			RenderManager::Instance()->Lost();
			RenderResource::SaveAllResourcesToSystemMem();
			RenderResource::LostAllResources();

			ResizeView(w, h);

			RenderManager::Instance()->Invalidate();
			RenderResource::InvalidateAllResources();
		}
		else
		{
			wasCreated = true;

			Logger::Debug("[CorePlatformAndroid::] before create renderer");
			RenderManager::Create(Core::RENDERER_OPENGL_ES_2_0);

			RenderManager::Instance()->InitFBO(androidDelegate->RenderBuffer(), androidDelegate->FrameBuffer());
			Logger::Debug("[CorePlatformAndroid::] after create renderer");

			ResizeView(w, h);

			FrameworkDidLaunched();

			RenderManager::Instance()->SetFPS(60);

			//////////////////////////////////////////////////////////////////////////
			Core::Instance()->SystemAppStarted();

			StartForeground();
		}

		Logger::Debug("[CorePlatformAndroid::RenderRecreated] end");
	}
RenderWindow::RenderWindow(std::shared_ptr<SDL_Window> spWindow)
:m_spWindow(spWindow)
{
   // output some OpenGL diagnostics
   OpenGL::LogDiagnostics();

   int iWidth = 0, iHeight = 0;
   SDL_GetWindowSize(spWindow.get(), &iWidth, &iHeight);

   ResizeView(unsigned(iWidth), unsigned(iHeight));
}
Esempio n. 4
0
	void CorePlatformAndroid::RenderRecreated(int32 w, int32 h)
	{
		Logger::Debug("[CorePlatformAndroid::RenderRecreated] start");

		renderIsActive = true;

		Thread::InitMainThread();

		if(wasCreated)
		{
            ResizeView(w, h);
			RenderResource::InvalidateAllResources();
		}
		else
		{
			wasCreated = true;

			Logger::Debug("[CorePlatformAndroid::] before create renderer");
			RenderManager::Create(Core::RENDERER_OPENGL_ES_2_0);

			RenderManager::Instance()->InitFBO(androidDelegate->RenderBuffer(), androidDelegate->FrameBuffer());
			Logger::Debug("[CorePlatformAndroid::] after create renderer");

            ResizeView(w, h);

			FrameworkDidLaunched();
			screenOrientation = Core::SCREEN_ORIENTATION_PORTRAIT; //no need rotate GL for Android

			RenderManager::Instance()->SetFPS(60);

			//////////////////////////////////////////////////////////////////////////
			Core::Instance()->SystemAppStarted();

			StartForeground();
		}

		Logger::Debug("[CorePlatformAndroid::RenderRecreated] end");
	}
Esempio n. 5
0
int InitWindowAndLoop(int argc, char** argv)
{
    char* ClassName = "BOOTEDWIN";
    WNDCLASSEX ClassStruct;
    memset(&ClassStruct, 0, sizeof(ClassStruct));
    ClassStruct.cbSize = sizeof(ClassStruct);
    ClassStruct.style = CS_OWNDC;
    ClassStruct.lpfnWndProc = WndProc;
    ClassStruct.hInstance = WinSys_hInstance;
    ClassStruct.lpszClassName = ClassName;
    RegisterClassEx(&ClassStruct);
    HWND hWnd = CreateWindow(ClassName,
                             "BootEd Window.",
                             WS_TILEDWINDOW,
                             CW_USEDEFAULT,
                             CW_USEDEFAULT,
                             1024,
                             768,
                             NULL,
                             NULL,
                             WinSys_hInstance,
                             NULL);

    ShowWindow(hWnd, SW_SHOW);

    HDC dc = GetDC(hWnd);

    PIXELFORMATDESCRIPTOR pfd;
    memset(&pfd, 0, sizeof(pfd));
    pfd.nSize = sizeof(pfd);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 32;
    pfd.cDepthBits = 32;
    pfd.iLayerType = PFD_MAIN_PLANE;

    int pixel_format = ChoosePixelFormat(dc, &pfd);
    if(pixel_format == 0)
        return 1;

    if(!SetPixelFormat(dc, pixel_format, &pfd))
        return 1;

    HGLRC glRc = wglCreateContext(dc);
    wglMakeCurrent(dc, glRc);

    void InitGLExt();
    InitGLExt();

    WinSys_View = InitView();
    ResizeView(WinSys_View, WinSys_Width, WinSys_Height);

    // This message loop is meant to consume all system resources, needs
    // to be changed for apps that are meant to idle, I.E. editors.
    bool continue_loop = true;
    while(continue_loop)
    {
        MSG msg;
        while(PeekMessage(&msg, NULL, 0, 0, 0))
        {
            if(!GetMessage(&msg, NULL, 0, 0))
                continue_loop = false;

            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        UpdateView(WinSys_View);
        SwapBuffers(dc);
    }

    FinishView(WinSys_View);
    wglMakeCurrent(NULL, NULL);
    wglDeleteContext(glRc);

    return 0;
}
void RenderWindow::InitVideo(const CString& cszWindowCaption, unsigned int uiWidth, unsigned int uiHeight, bool bFullscreen)
{
   // output SDL version number
   {
      SDL_version linked = {0};
      SDL_GetVersion(&linked);

      CString cszText;
      cszText.Format(_T("using SDL %u.%u.%u"), linked.major, linked.minor, linked.patch);
      LOG_INFO(cszText, Log::Client::Renderer);
   }

   // first, initialize SDL's video subsystem
   if (SDL_Init(SDL_INIT_VIDEO) < 0)
   {
      CString cszText;
      cszText.Format(_T("video initialization failed: %hs"), SDL_GetError());

      LOG_ERROR(cszText, Log::Client::Renderer);
      throw Exception(cszText, __FILE__, __LINE__);
   }

   // setup video mode
   int iFlags = SDL_WINDOW_OPENGL | (bFullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);

   {
      CString cszText;
      cszText.Format(_T("setting video mode: %u x %u%s"),
         uiWidth, uiHeight,
         bFullscreen ? _T(", fullscreen") : _T(""));

      LOG_INFO(cszText, Log::Client::Renderer);
   }

   CStringA cszaWindowCaption(cszWindowCaption);
   SDL_Window* pWindow = SDL_CreateWindow(cszaWindowCaption.GetString(),
      SDL_WINDOWPOS_UNDEFINED,
      SDL_WINDOWPOS_UNDEFINED,
      static_cast<int>(uiWidth),
      static_cast<int>(uiHeight),
      iFlags);

   if (pWindow == nullptr)
   {
      CString cszText;
      cszText.Format(_T("video mode set failed: %hs"), SDL_GetError());

      LOG_ERROR(cszText, Log::Client::Renderer);
      throw Exception(cszText, __FILE__, __LINE__);
   }

   m_spWindow.reset(pWindow, &SDL_DestroyWindow);

   SDL_GLContext glcontext = SDL_GL_CreateContext(pWindow);
   m_spGLCcontext.reset(glcontext, &SDL_GL_DeleteContext);

#ifndef _DEBUG
   // enable vsync for release; 1 means vsync on
   SDL_GL_SetSwapInterval(1);
#endif

   // output some OpenGL diagnostics
   OpenGL::LogDiagnostics();

   ResizeView(uiWidth, uiHeight);
}