Example #1
0
bool Application::AppLoopFunc()
{
	MSG msg;
	ZeroMemory(&msg,sizeof(MSG));
	do	{// Обработка всех сообщений
			while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
			{
				if (GetMessage(&msg, NULL, 0, 0))
				{
					TranslateMessage(&msg);
					DispatchMessage(&msg);	
				}	
			}
		ProcessKBInput();
		switch (Globals.ERS.d)
		{
		case ERS::Draw::SCENE:
			RenderScene();
			CCons.Draw();
			break;
		case ERS::Draw::TEXTURE:
			RenderTexture();
		};
		SwapBuffersEXT();
		}
	while (	!Globals.Exiting );
	return true;// Выход
}
Example #2
0
void	Application::ShowMovie(bool	CanBreak)
{
	MSG msg;
	ZeroMemory(&msg,sizeof(MSG));
	do
	{// Обработка всех сообщений
			while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
			{
				if (GetMessage(&msg, NULL, 0, 0))
				{
					//TranslateMessage(&msg);
					DispatchMessage(&msg);	
				}	
			}
		GT.NewFrame();
		AVIp.GrabAVIFrame();
		RenderTexture();
		SwapBuffersEXT();
		if (CanBreak)
		{
			if (Input::I->get(' ')		||
				Input::I->get(VK_RETURN)||
				Input::I->get(VK_ESCAPE))
			{
				break;
			}
		}
	}
	while (	!AVIp.End());
}
Example #3
0
/* Draw each part of the text */
bool Font::PartText(const std::string &message, int x, int y, SDL_Color color)
{
	int corx;
	int cory;

	/* TTF gestion */
	tex = RenderText(message.c_str(), color, size, ren);
	if (tex == NULL){
		return false;
	}

	//Get the texture w/h so we can center it in the screen
	if (isCenter)
	{
		int iW, iH;
		SDL_QueryTexture(tex, NULL, NULL, &iW, &iH);
		corx = x - iW / 2;
		cory = y - iH / 2;
	}
	else
	{
		corx = x;
		cory = y;
	}

	/* Dessiner le texte */
	RenderTexture(tex, ren, corx, cory);

	SDL_DestroyTexture(tex);

	return true;
}
Example #4
0
static void
Display(void)
{
    FrameCount++;
    uint64_t uiStartTime = GetCurrentTime();
    
    glClear (GL_COLOR_BUFFER_BIT);
    
    int err = Recompute();
    if (err != 0)
    {
        printf("Error %d from Recompute!\n", err);
        exit(1);
    }

    RenderTexture(HostImageBuffer);
    ReportInfo();
    
    glFinish(); // for timing

    uint64_t uiEndTime = GetCurrentTime();
    ReportStats(uiStartTime, uiEndTime);

    glutSwapBuffers();
    glutPostRedisplay();
}
Example #5
0
static void
Display(void)
{
   float ar = (float) Width / (float) Height;

   RenderTexture();

   /* draw textured quad in the window */
#if DRAW
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glFrustum(-ar, ar, -1.0, 1.0, 5.0, 25.0);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   glTranslatef(0.0, 0.0, -7.0);

   glViewport(0, 0, Width, Height);

   glClearColor(0.25, 0.25, 0.25, 0);
   glClear(GL_COLOR_BUFFER_BIT);

   glPushMatrix();
   glRotatef(Rot, 0, 1, 0);
   glEnable(TexTarget);
   glBindTexture(TexTarget, TexObj);
   glBegin(GL_POLYGON);
   glColor3f(0.25, 0.25, 0.25);
   if (TexTarget == GL_TEXTURE_2D) {
      glTexCoord2f(0, 0);
      glVertex2f(-1, -1);
      glTexCoord2f(1, 0);
      glVertex2f(1, -1);
      glColor3f(1.0, 1.0, 1.0);
      glTexCoord2f(1, 1);
      glVertex2f(1, 1);
      glTexCoord2f(0, 1);
      glVertex2f(-1, 1);
   }
   else {
      assert(TexTarget == GL_TEXTURE_RECTANGLE_ARB);
      glTexCoord2f(0, 0);
      glVertex2f(-1, -1);
      glTexCoord2f(TexWidth, 0);
      glVertex2f(1, -1);
      glColor3f(1.0, 1.0, 1.0);
      glTexCoord2f(TexWidth, TexHeight);
      glVertex2f(1, 1);
      glTexCoord2f(0, TexHeight);
      glVertex2f(-1, 1);
   }
   glEnd();
   glPopMatrix();
   glDisable(TexTarget);
#endif

   glutSwapBuffers();
   CheckError(__LINE__);
}
Example #6
0
void RenderGlyph(bitmapfont_t * font, int x, int y, char glyph)
{
    if (font) {
        SDL_Rect * tmp = &font->glyphs[glyph - font->begin];
        SDL_Rect dst = *tmp;
        dst.x = x;
        dst.y = y;
        RenderTexture(font->tex,tmp,&dst);
    }
}
	bool D3D11RenderTarget::init()
	{
		m_rt2D = RenderTexture(Size(640, 480), m_sample2D.Count);

		if (!m_rt2D)
		{
			return false;
		}

		return true;
	}
Example #8
0
RenderTargetPtr MultiRenderTarget::CreateTexture(const TargetParam& tp) {
	if (tp.useAsTexture) {
		RenderTexture* rt = NEX_NEW(RenderTexture());
		rt->Create(TextureBase::TEXTURE_2D, tp.format, dimensions.width,
				dimensions.height, 1);
		return Assign(rt);
	} else {
		RenderBuffer* rt = NEX_NEW(RenderBuffer());
		rt->Create(tp.format, dimensions.width, dimensions.height);
		return Assign(rt);
	}
}
Example #9
0
    void RenderTexture(SDL_Texture *tex, SDL_Renderer *ren, int x, int y, SDL_Rect *clip)
    {
        SDL_Rect dst;
        dst.x = x;
        dst.y = y;
        if (clip != nullptr)
        {
            dst.w = clip->w;
            dst.h = clip->h;
        }
        else
        {
            SDL_QueryTexture(tex, NULL, NULL, &dst.w, &dst.h);
        }

        RenderTexture(tex, ren, dst, clip);
    }
Example #10
0
void RenderString(RenderContext *context, float x, float y, const char *text, float spacing,
	uint8 r, uint8 g, uint8 b, uint8 a)
{
	float char_width = context->font.height;
	float char_height = context->font.height;
	float total_width = (float)strlen(text) * (char_width + spacing);
	for (int i = 0; i < strlen(text); ++i)
	{
		float xx =  x + i * (char_width + spacing);
		float yy = y;
		int font_index = (int)font_text.find(text[i]);
		float offset_x = font_index * char_width;

		if (font_index >= 0)
			RenderTexture(context, xx, yy, 0.0f, &context->font, offset_x, 0.0f, char_width, char_height,
			r, g, b, a);
	}
}
Example #11
0
void Engine::RenderEngine()
{
	SDL_GetMouseState(&x, &y);
	if (SDL_PollEvent(&(EngineEvent)) != 0)
	{
		int uiEvent = TwEventSDL20(&(EngineEvent));
		if (!uiEvent) {
			if (EngineEvent.type == SDL_QUIT)
			{
			}
			//If a mouse button was pressed

			if (EngineEvent.button.button == SDL_BUTTON_LEFT)
			{
				mfRot[0] = rotRef.y - y;
				mfRot[1] = rotRef.x - x;
				mfRot[2] = 0;

				glMatrixMode(GL_MODELVIEW);
				glLoadMatrixd(EngineRenderer.ObjectOrientation);
				glRotated(mfRot[0], 1.0f, 0, 0);
				glRotated(mfRot[1], 0, 1.0f, 0);
				glRotated(mfRot[2], 0, 0, 1.0f);

				glGetDoublev(GL_MODELVIEW_MATRIX, EngineRenderer.ObjectOrientation);
				glLoadIdentity();

			}
		}
	}
	rotRef.x = x;
	rotRef.y = y;

	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	if (enableRendering)
		RenderTexture(EngineRenderer.ObjectOrientation, RenderLayerCount, this->OCT);

	TwDraw();

	SDL_GL_SwapWindow(this->EngineRenderer.EngineWindow);
}
Example #12
0
    void EditText::OnDraw()
    {
        SDL_Rect absRect = GetAbsRect();

        if (m_drawBackground)
        {
            // Draw a rectangle as a containing "field"
            SDL_SetRenderDrawColor(m_renderer, m_bgColor.r, m_bgColor.g, m_bgColor.b, m_bgColor.a);
			SDL_RenderFillRect(m_renderer, &absRect);
        }

        if (m_drawBorder)
        {
			SDL_SetRenderDrawColor(m_renderer, m_textColor.r, m_textColor.g, m_textColor.b, m_textColor.a);
			SDL_RenderDrawRect(m_renderer, &absRect);
        }

        if (!m_font || m_text.empty())
            return;

        // If the tecture (that contines the string) is null -> create it!
        if (m_texture == nullptr)
			m_texture = NewTextTexture(m_text.c_str(), m_font, m_textColor, 64, m_renderer, absRect.w);

        // If the texture was not created, so, do not display it! Doh...!
        if (m_texture == nullptr)
            return;

        //Get the texture w/h so we can center it in the screen
        int iW, iH;
        SDL_QueryTexture(m_texture, NULL, NULL, &iW, &iH);
        int _x = absRect.x;
        int _y = absRect.y;// +(GetRect().h / 2 - iH / 2);
        absRect.x = 0;
        absRect.y = 0;
        absRect.w = (absRect.w > iW) ? iW : absRect.w;
        absRect.h = (absRect.h > iH) ? iH : absRect.h;

		RenderTexture(m_texture, m_renderer, _x, _y, &absRect);
    }
Example #13
0
void GLReplay::PickPixel(ResourceId texture, uint32_t x, uint32_t y, uint32_t sliceFace, uint32_t mip, float pixel[4])
{
	WrappedOpenGL &gl = *m_pDriver;
	
	MakeCurrentReplayContext(m_DebugCtx);
	
	gl.glBindFramebuffer(eGL_FRAMEBUFFER, DebugData.pickPixelFBO);
	gl.glBindFramebuffer(eGL_READ_FRAMEBUFFER, DebugData.pickPixelFBO);
	
	pixel[0] = pixel[1] = pixel[2] = pixel[3] = 0.0f;
	gl.glClearBufferfv(eGL_COLOR, 0, pixel);

	DebugData.outWidth = DebugData.outHeight = 1.0f;
	gl.glViewport(0, 0, 1, 1);

	{
		TextureDisplay texDisplay;

		texDisplay.Red = texDisplay.Green = texDisplay.Blue = texDisplay.Alpha = true;
		texDisplay.HDRMul = -1.0f;
		texDisplay.mip = mip;
		texDisplay.CustomShader = ResourceId();
		texDisplay.sliceFace = sliceFace;
		texDisplay.rangemin = 0.0f;
		texDisplay.rangemax = 1.0f;
		texDisplay.scale = 1.0f;
		texDisplay.texid = texture;
		texDisplay.rawoutput = true;
		texDisplay.offx = -float(x);
		texDisplay.offy = -float(y);

		RenderTexture(texDisplay);
	}

	gl.glReadPixels(0, 0, 1, 1, eGL_RGBA, eGL_FLOAT, (void *)pixel);
}
Example #14
0
int
main( int argc, char *argv[] )
{
     DFBResult ret;
     bool      quit = false;
     Test      test;

     ret = Initialize( &test, &argc, &argv );
     if (ret)
          goto error;

     ret = InitGL( &test );
     if (ret)
          goto error;

     ret = InitTexture( &test, &test.texture, 256, 256 );
     if (ret)
          goto error;

     /*
      * Main Loop
      */
     while (!quit) {
          static int frames = 0;
          static double tRot0 = -1.0, tRate0 = -1.0;
          double dt, t = direct_clock_get_millis() / 1000.0;

          if (tRot0 < 0.0)
             tRot0 = t;
          dt = t - tRot0;
          tRot0 = t;

          /* advance rotation for next frame */
          angle += 70.0 * dt;  /* 70 degrees per second */
          if (angle > 3600.0)
             angle -= 3600.0;

          ret = RenderTexture( &test, &test.texture );
          if (ret)
               goto error;

          ret = RenderGL( &test );
          if (ret)
               goto error;

          /*
           * Show the rendered buffer
           */
          test.primary->Flip( test.primary, NULL, DSFLIP_ONSYNC );


          frames++;

          if (tRate0 < 0.0)
             tRate0 = t;
          if (t - tRate0 >= 5.0) {
             GLfloat seconds = t - tRate0;
             GLfloat fps = frames / seconds;
             printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds,
                   fps);
             tRate0 = t;
             frames = 0;
          }


          DFBInputEvent evt;

          /*
           * Process events
           */
          while (test.events->GetEvent( test.events, DFB_EVENT(&evt) ) == DFB_OK) {
               switch (evt.type) {
                    case DIET_KEYPRESS:
                         switch (evt.key_symbol) {
                              case DIKS_ESCAPE:
                                   quit = true;
                                   break;
                              case DIKS_CURSOR_UP:
                                   inc_rotx = 5.0;
                                   break;
                              case DIKS_CURSOR_DOWN:
                                   inc_rotx = -5.0;
                                   break;
                              case DIKS_CURSOR_LEFT:
                                   inc_roty = 5.0;
                                   break;
                              case DIKS_CURSOR_RIGHT:
                                   inc_roty = -5.0;
                                   break;
                              case DIKS_PAGE_UP:
                                   inc_rotz = 5.0;
                                   break;
                              case DIKS_PAGE_DOWN:
                                   inc_rotz = -5.0;
                                   break;
                              default:
                                   ;
                         }
                         break;
                    case DIET_KEYRELEASE:
                         switch (evt.key_symbol) {
                              case DIKS_CURSOR_UP:
                                   inc_rotx = 0;
                                   break;
                              case DIKS_CURSOR_DOWN:
                                   inc_rotx = 0;
                                   break;
                              case DIKS_CURSOR_LEFT:
                                   inc_roty = 0;
                                   break;
                              case DIKS_CURSOR_RIGHT:
                                   inc_roty = 0;
                                   break;
                              case DIKS_PAGE_UP:
                                   inc_rotz = 0;
                                   break;
                              case DIKS_PAGE_DOWN:
                                   inc_rotz = 0;
                                   break;
                              default:
                                   ;
                         }
                         break;
                    case DIET_AXISMOTION:
                         if (evt.flags & DIEF_AXISREL) {
                              switch (evt.axis) {
                                   case DIAI_X:
                                        view_rot[1] += evt.axisrel / 2.0;
                                        break;
                                   case DIAI_Y:
                                        view_rot[0] += evt.axisrel / 2.0;
                                        break;
                                   case DIAI_Z:
                                        view_rot[2] += evt.axisrel / 2.0;
                                        break;
                                   default:
                                        ;
                              }
                         }
                         break;
                    default:
                         ;
               }
          }

          view_rot[0] += inc_rotx;
          view_rot[1] += inc_roty;
          view_rot[2] += inc_rotz;
     }


error:
     Shutdown( &test );

     return ret;
}
Example #15
0
void RenderTexture(RenderContext *context, float x, float y, Texture *texture)
{
	RenderTexture(context, x, y, 0.0f, texture, 0.0f, 0.0f, (float)texture->width, (float)texture->height);
}
Example #16
0
int GameLoop()
{

    Init_Game();

    SDL_Event e;

    MM_Load();

    while(!Quit)
    {
        while(SDL_PollEvent(&e))
        {
            if(e.type == SDL_TEXTINPUT && TI_FLAG == true)
            {
                Returntext.push_back(*e.text.text);
                TI_Update_Text();
                break;
            }
            else if(e.type == SDL_MOUSEBUTTONDOWN)
            {
                double x = e.button.x;
                double y = e.button.y;
                double ax = (x / RES_WIDTH) * 1920;
                double ay = (y / RES_HEIGHT) * 1080;

                for(int y = Button_Stack.size() - 1; y >= 0; y--)
                {
                    for(int x = Button_Stack[y]->size() - 1; x >= 0; x--)
                    {
                        if(ax > Button_Stack.at(y)->at(x)->x && ax < Button_Stack.at(y)->at(x)->x + Button_Stack.at(y)->at(x)->w)
                        {
                            if(ay > Button_Stack.at(y)->at(x)->y && ay < Button_Stack.at(y)->at(x)->y + Button_Stack.at(y)->at(x)->h)
                            {
                                if(Button_Stack.at(y)->at(x)->type == BASIC)
                                {
                                    Button_Stack.at(y)->at(x)->funct();
                                    x = 0;
                                    y = 0;
                                }
                                else if(Button_Stack.at(y)->at(x)->type == LIST)
                                {
                                    Button_Stack.at(y)->at(x)->funct2(Button_Stack.at(y)->at(x)->L_Pos);
                                    x = 0;
                                    y = 0;
                                }
                                else if(Button_Stack.at(y)->at(x)->type == GRID)
                                {
                                    Button_Stack.at(y)->at(x)->funct3(Button_Stack.at(y)->at(x)->G_PosX, Button_Stack.at(y)->at(x)->G_PosY);
                                    x = 0;
                                    y = 0;
                                }
                            }
                        }
                    }
                }
            }
            else if(e.type == SDL_QUIT)
            {
                Quit = true;
            }
            else if(e.type == SDL_KEYDOWN && Key_Stack.size() > 0)
            {
                for(int x = 0; x < Key_Stack.size(); x++)
                {
                    if(Key_Stack.at(x)->input == e.key.keysym.sym)
                        Key_Stack.at(x)->funct();
                }
            }
        }

        for(int x = 0; x < Tx_Stack.size(); x++)
        {
            for(int y = 0; y < Tx_Stack[x]->size(); y++)
            {
                RenderTexture(Tx_Stack[x]->at(y));
            }
        }

        RenderTexture(wally);

        for(int x = 0; x < Text_Stack.size(); x++)
        {
            for(int y = 0; y < Text_Stack[x]->size(); y++)
            {
                RenderTexture(Text_Stack[x]->at(y));
            }
        }

        for(int x = 0; x < Funct_Stack.size(); x++)
        {
            Funct_Stack[x]();
        }

        SDL_RenderPresent(ren);
        SDL_RenderClear(ren);

        SDL_Delay(16);
    }


    App_Quit();


    return 0;
}
HRESULT MPMadPresenter::ClearBackground(LPCSTR name, REFERENCE_TIME frameStart, RECT* fullOutputRect, RECT* activeVideoRect)
{
  HRESULT hr = E_UNEXPECTED;

  if (m_pShutdown)
  {
    Log("MPMadPresenter::ClearBackground() shutdown or init OSD");
    return hr;
  }

  // Lock madVR thread while Shutdown()
  //CAutoLock lock(&m_dsLock);

  WORD videoHeight = (WORD)activeVideoRect->bottom - (WORD)activeVideoRect->top;
  WORD videoWidth = (WORD)activeVideoRect->right - (WORD)activeVideoRect->left;

  CAutoLock cAutoLock(this);

  ReinitOSD();

  //// Ugly hack to avoid flickering (most occurs on Intel GPU)
  //bool isFullScreen = m_pCallback->IsFullScreen();
  //bool isUiVisible = m_pCallback->IsUiVisible();
  //if (isFullScreen)
  //{
  //  if (isUiVisible)
  //  {
  //    //int pRefreshrate = static_cast<int>(m_pRefreshrate);
  //    //Sleep(100 / m_pRefreshrate);
  //    int CountPass = uiVisible ? 1 : 3;
  //    //Log("MPMadPresenter::ClearBackground() uiVisible %x", CountPass);
  //    for (int x = 0; x < CountPass; ++x) // need to let in a loop to slow down why ???
  //    {
  //      // commented out (it slown down video on GPU Nvidia)
  //      //m_pDevice->PresentEx(nullptr, nullptr, nullptr, nullptr, D3DPRESENT_FORCEIMMEDIATE);
  //    }
  //  }
  //  //m_mpWait.Unlock();
  //  //m_dsLock.Unlock();
  //  return uiVisible ? CALLBACK_USER_INTERFACE : CALLBACK_INFO_DISPLAY;
  //}

  uiVisible = false;

  //Log("MPMadPresenter::ClearBackground()");

  if (!m_pMPTextureGui || !m_pMadGuiVertexBuffer || !m_pRenderTextureGui || !m_pCallback)
    return CALLBACK_INFO_DISPLAY;

  m_dwHeight = (WORD)fullOutputRect->bottom - (WORD)fullOutputRect->top; // added back
  m_dwWidth = (WORD)fullOutputRect->right - (WORD)fullOutputRect->left;

  RenderToTexture(m_pMPTextureGui);

  if (SUCCEEDED(hr = m_deviceState.Store()))
  {
    hr = m_pCallback->RenderGui(videoWidth, videoHeight, videoWidth, videoHeight);
    if (m_pCallback->IsUiVisible())
    {
      for (int x = 0; x < m_pMadVRFrameCount; ++x) // need to let in a loop to slow down why ???
      {
        if (x <= 3)
        {
          // commented out (it slown down video on GPU Nvidia)
          m_pDevice->PresentEx(nullptr, nullptr, nullptr, nullptr, D3DPRESENT_FORCEIMMEDIATE);
          //Log("MPMadPresenter::ClearBackground() IsUiVisible");
        }
      }
    }
  }

  uiVisible = hr == S_OK ? true : false;

  //Log("ClearBackground() hr: 0x%08x - 2", hr);

  if (SUCCEEDED(hr = m_pDevice->PresentEx(nullptr, nullptr, nullptr, nullptr, D3DPRESENT_FORCEIMMEDIATE)))
    if (SUCCEEDED(hr = SetupMadDeviceState()))
      if (SUCCEEDED(hr = SetupOSDVertex(m_pMadGuiVertexBuffer)))
        // Draw MP texture on madVR device's side
        RenderTexture(m_pMadGuiVertexBuffer, m_pRenderTextureGui);

  // For 3D
  if (m_madVr3DEnable)
  {
    if (SUCCEEDED(hr = SetupOSDVertex3D(m_pMadGuiVertexBuffer)))
      // Draw MP texture on madVR device's side
      RenderTexture(m_pMadGuiVertexBuffer, m_pRenderTextureGui);
  }

  m_deviceState.Restore();

  //// if we don't unlock, OSD will be slow because it will reach the timeout set in SetOSDCallback()
  //m_mpWait.Unlock();
  //m_dsLock.Unlock();

  return uiVisible ? CALLBACK_USER_INTERFACE : CALLBACK_INFO_DISPLAY;
}
HRESULT MPMadPresenter::RenderOsd(LPCSTR name, REFERENCE_TIME frameStart, RECT* fullOutputRect, RECT* activeVideoRect)
{
  HRESULT hr = E_UNEXPECTED;

  if (m_pShutdown)
  {
    Log("MPMadPresenter::RenderOsd() shutdown");
    return hr;
  }

  // Lock madVR thread while Shutdown()
  //CAutoLock lock(&m_dsLock);

  WORD videoHeight = (WORD)activeVideoRect->bottom - (WORD)activeVideoRect->top;
  WORD videoWidth = (WORD)activeVideoRect->right - (WORD)activeVideoRect->left;

  CAutoLock cAutoLock(this);

  ReinitOSD();

  //// Ugly hack to avoid flickering (most occurs on Intel GPU)
  //bool isFullScreen = m_pCallback->IsFullScreen();
  //bool isUiVisible = m_pCallback->IsUiVisible();
  //if (isUiVisible)
  //{
  //  // Disabled for now (see http://forum.kodi.tv/showthread.php?tid=154534&pid=1964715#pid1964715)
  //  // Present frame in advance option lead to GUI lag and/or stuttering for Intel GPU
  //  //int pRefreshrate = static_cast<int>(m_pRefreshrate);
  //  //Sleep(100 / m_pRefreshrate);
  //  int CountPass = uiVisible ? 3 : 6;
  //  //Log("MPMadPresenter::RenderOsd() uiVisible %x", CountPass);
  //  for (int x = 0; x < CountPass; ++x) // need to let in a loop to slow down why ???
  //  {
  //    // commented out (it slown down video on GPU Nvidia)
  //    //m_pDevice->PresentEx(nullptr, nullptr, nullptr, nullptr, D3DPRESENT_FORCEIMMEDIATE);
  //  }
  //  //m_mpWait.Unlock();
  //  //m_dsLock.Unlock();
  //  //return uiVisible ? CALLBACK_USER_INTERFACE : CALLBACK_INFO_DISPLAY;
  //}

  uiVisible = false;

  //Log("MPMadPresenter::RenderOsd()");

  if (!m_pMPTextureOsd || !m_pMadOsdVertexBuffer || !m_pRenderTextureOsd || !m_pCallback)
    return CALLBACK_INFO_DISPLAY;

  IDirect3DSurface9* SurfaceMadVr = nullptr; // This will be released by C# side

  m_dwHeight = (WORD)fullOutputRect->bottom - (WORD)fullOutputRect->top;
  m_dwWidth = (WORD)fullOutputRect->right - (WORD)fullOutputRect->left;

  // Handle GetBackBuffer to be done only 2 frames
  //countFrame++;
  //if (countFrame == firstFrame || countFrame == secondFrame)
  {
    if (SUCCEEDED(hr = m_pMadD3DDev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &SurfaceMadVr)))
    {
      if (SUCCEEDED(hr = m_pCallback->RenderFrame(videoWidth, videoHeight, videoWidth, videoHeight, reinterpret_cast<DWORD>(SurfaceMadVr))))
      {
        SurfaceMadVr->Release();
      }
      //if (countFrame == secondFrame)
      //{
      //  countFrame = resetFrame;
      //}
    }
  }

  RenderToTexture(m_pMPTextureOsd);

  if (SUCCEEDED(hr = m_deviceState.Store()))
  {
    hr = m_pCallback->RenderOverlay(videoWidth, videoHeight, videoWidth, videoHeight);
    if (m_pCallback->IsUiVisible())
    {
      for (int x = 0; x < m_pMadVRFrameCount; ++x) // need to let in a loop to slow down why ???
      {
        if (x <= 3)
        {
          // commented out (it slown down video on GPU Nvidia)
          m_pDevice->PresentEx(nullptr, nullptr, nullptr, nullptr, D3DPRESENT_FORCEIMMEDIATE);
          //Log("MPMadPresenter::RenderOsd() IsUiVisible");
        }
      }
    }
  }

  uiVisible = hr == S_OK ? true : false;

  //Log("RenderOsd() hr: 0x%08x - 2", hr);

  if (SUCCEEDED(hr = m_pDevice->PresentEx(nullptr, nullptr, nullptr, nullptr, D3DPRESENT_FORCEIMMEDIATE)))
    if (SUCCEEDED(hr = SetupMadDeviceState()))
      if (SUCCEEDED(hr = SetupOSDVertex(m_pMadOsdVertexBuffer)))
        // Draw MP texture on madVR device's side
        RenderTexture(m_pMadOsdVertexBuffer, m_pRenderTextureOsd);

  // For 3D
  if (m_madVr3DEnable)
  {
    if (SUCCEEDED(hr = SetupOSDVertex3D(m_pMadOsdVertexBuffer)))
      // Draw MP texture on madVR device's side
      RenderTexture(m_pMadOsdVertexBuffer, m_pRenderTextureOsd);
  }

  m_deviceState.Restore();

  //// if we don't unlock, OSD will be slow because it will reach the timeout set in SetOSDCallback()
  //m_mpWait.Unlock();
  //m_dsLock.Unlock();

  return uiVisible ? CALLBACK_USER_INTERFACE : CALLBACK_INFO_DISPLAY;
}