예제 #1
0
	inline static void InitEngine()
	{
		glEnable(GL_DEPTH_TEST);
		EnableLighting();
		glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
		//glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
	}
예제 #2
0
int CGLLightManager::Add(LightSource& lightSource)
{
	if (_lightSources.size() > CAppConstants::MaxLights)
		return -1;
	_lightSources.push_back(lightSource);
	if (_lightSources.size() == 1)
		EnableLighting();
	return (int)_lightSources.size();
}
예제 #3
0
void Stage01::InitBackground()
{
	auto engine = STGEngine::GetInstance();
	auto background = engine->GetGameScene()->GetBackgroundLayer();

	SetupCamera();
	SetupFog();

	background->SetSkyBox(sky);
	background->EnableLighting(true);
	background->SetAmbientLight(Vector4f(0.3f, 0.3f, 0.3f, 1.0f));
	background->AddLight(Ptr<DirectionalLight>::New(Vector3f(1.8f, 1.8f, 1.8f), Vector3f(1.0f, -1.0f, 0.0f)).Get());

	InitBackgroundObjects();
}
예제 #4
0
 void ProcessNaviMesh(Render2 *render, Scene::Node *node, System::Object* o)
 {
     if (!o)
         return;
     AI::NaviMesh *mesh = (AI::NaviMesh*)o;
     auto m_frame = render->GetCurrentFrame();
     if (m_frame->IsEnabledNaviMeshRendering())
     {
         if (mesh)
         {
             auto r = Gpu::AsRenderable(*mesh, m_frame->GetVideoDriver());
             m_frame->PushAllState();
             m_frame->EnableTexturing(false);
             m_frame->EnableLighting(false);
             m_frame->EnableBlending(true);
             m_frame->SetDiffuseColor(0, 0, 1.0, .5);
             m_frame->Submit(r, true);
             m_frame->PopAllState();
         }
     }
     render->ProcessChildren(node);
 }
예제 #5
0
	void CoreDelegateImpl::Draw()
	{
		auto p_lights = Core::GetRenderer()->GetLightsController();
		p_lights->DisableLighting();
		drawGrid(100, 4);
		p_lights->EnableLighting();
		static float x = 50;
		static float y = 600;
		auto p_renderer = Core::GetRenderer();
		IRect rect = p_renderer->GetTargetRectangle();
		p_renderer->SetMatrix(MatrixMode::Projection, Matrix4f::CreateOrtho(0, rect.Width(), 0, rect.Height()));
		std::wstring message = L"FPS: " + std::to_wstring(Core::GetApplication()->GetCurrentFPS());
		auto en_font = Core::GetGlobalObject<Resources::ResourceManager>()->GetHandleToResource<Render::Font>("Arial_en");

		auto p_font_mgr = Core::GetGlobalObject<Render::FontManager>();
		p_font_mgr->Render({ x, 900 }, 0.6f, message, en_font);
		p_font_mgr->Render({ x, 865 }, 0.6f, L"Vertices: " + std::to_wstring(Core::GetGlobalObject<Render::MeshSystem>()->GetVerticesRendered()), en_font);
		p_font_mgr->Render({ x, 830 }, 0.6f, L"Trigs: " + std::to_wstring(Core::GetGlobalObject<Render::MeshSystem>()->GetTrianglesRendered()), en_font);
		/*message = L"asdqwetbij[we6  ewrgasdf";
		for (int i = 0; i < 100; ++i)
			p_font_mgr->Render({ x, y }, 1.f, message, en_font);*/
	}
예제 #6
0
bool COGLWin::Init()
{
	// OpenGL rendering context exists at this point.
	m_pWindow->callback((Fl_Callback *) COGLWin::CB_Quit, this);

	glutIdleFunc(CallIdleFunc);
/*
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0, m_iOutSizeX, m_iOutSizeY, 0);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
*/
	glutSetWindow(m_iHWin);
	////////////////////////////////////////////////////

	//COGLBitmapText::InitFonts();

	// Lighting has to be enabled BEFORE
	// you call CGLUTBase::Init() !!!
	EnableLighting();

	// Initialize OpenGL settings.
	CCLUDrawBase::Init();

	m_dlSpace.Create();

	// Can change sensitivity of mouse
	// for rotation...
	SetRotFac(0.5f); // default = 1.0

	// and for translation
	SetTransFac(0.02f);  // default = 0.05

	// Enable lighting for filter
	m_Filter.EnableLighting();

	// Reduce sensitivity
	m_Filter.SetSensitivity(1e-5);//1e-4);

	// Initialize Settings for E3Filter
	m_Filter.Init();

	// Initialize Parser
	if (!m_Parse.Init())
		return false;

	m_Parse.SetMVFilter(&m_Filter);
	m_Parse.SetTransform(&m_mTransform);
	m_Parse.SetFrameRotor(&m_vRMain);
	m_Parse.SetCLUDrawBase((CCLUDrawBase *) this);
	m_Parse.InitBitmapFont();

	InitScriptListWindow();

	//AddToolSlider("Mouse Mode", 0, 9, 1, 0, true, "Set the mouse mode here.");
	//AddToolSlider("Test2", -10, 2, 0.02, "World");

	SetTitle();

	return true;
}
예제 #7
0
BOOL cGraphics::SetMode(HWND hWnd, BOOL Windowed, BOOL UseZBuffer, long Width, long Height, char BPP)
{
  D3DPRESENT_PARAMETERS d3dpp;
  D3DFORMAT             Format, AltFormat;
  RECT                  WndRect, ClientRect;
  long                  WndWidth, WndHeight;
  float                 Aspect;

  // Error checking
  if((m_hWnd = hWnd) == NULL)
    return FALSE;
  if(m_pD3D == NULL)
    return FALSE;

  // Get the current display format
  if(FAILED(m_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &m_d3ddm)))
    return FALSE;

  // Configure width
  if(!Width) {
    // Default to screen width if fullscreen
    if(Windowed == FALSE) {
      m_Width = m_d3ddm.Width;
    } else {
      // Otherwise grab from client size
      GetClientRect(m_hWnd, &ClientRect);
      m_Width = ClientRect.right;
    }
  } else {
    m_Width = Width;
  }

  // Configure height
  if(!Height) {
    // Default to screen height if fullscreen
    if(Windowed == FALSE) {
      m_Height = m_d3ddm.Height;
    } else {
      // Otherwise grab from client size
      GetClientRect(m_hWnd, &ClientRect);
      m_Height = ClientRect.bottom;
    }
  } else {
    m_Height = Height;
  }

  // Configure BPP
  if(!(m_BPP = BPP) || Windowed == TRUE) {
    if(!(m_BPP = GetFormatBPP(m_d3ddm.Format)))
      return FALSE;
  }

  // Resize client window if using windowed mode
  if(Windowed == TRUE) {
    GetWindowRect(m_hWnd, &WndRect);
    GetClientRect(m_hWnd, &ClientRect);

    WndWidth  = (WndRect.right  - (ClientRect.right  - m_Width))  - WndRect.left;
    WndHeight = (WndRect.bottom - (ClientRect.bottom - m_Height)) - WndRect.top;

    MoveWindow(m_hWnd, WndRect.left, WndRect.top, WndWidth, WndHeight, TRUE);
  }

  // Clear presentation structure
  ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));
  
  // Default to no hardware acceleration detected
  m_HAL = FALSE;

  // Setup Windowed or fullscreen usage
  if((m_Windowed = Windowed) == TRUE) {
    d3dpp.Windowed         = TRUE;
    d3dpp.SwapEffect       = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = m_d3ddm.Format;

    // See if card supports HAL
    if(CheckFormat(m_d3ddm.Format, TRUE, TRUE) == TRUE) {
      m_HAL = TRUE;
    } else {
      // Return error if not emulated
      if(CheckFormat(m_d3ddm.Format, TRUE, FALSE) == FALSE)
        return FALSE;
    }
  } else {
    d3dpp.Windowed   = FALSE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP;
  
    d3dpp.BackBufferWidth  = m_Width;
    d3dpp.BackBufferHeight = m_Height;
    d3dpp.FullScreen_RefreshRateInHz      = D3DPRESENT_RATE_DEFAULT;
    d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; // or D3DPRESENT_INTERVAL_DEFAULT or D3DPRESENT_INTERVAL_IMMEDIATE

    // Figure display format to use
    if(m_BPP == 32) {
      Format    = D3DFMT_X8R8G8B8;
      AltFormat = D3DFMT_X8R8G8B8;
    }
    if(m_BPP == 24) {
      Format    = D3DFMT_R8G8B8;
      AltFormat = D3DFMT_R8G8B8;
    }
    if(m_BPP == 16) {
      Format    = D3DFMT_R5G6B5;
      AltFormat = D3DFMT_X1R5G5B5;
    }
    if(m_BPP == 8) {
      Format    = D3DFMT_P8;
      AltFormat = D3DFMT_P8;
    }

    // Check for HAL device
    if(CheckFormat(Format, FALSE, TRUE) == TRUE) {
      m_HAL = TRUE;
    } else {
      // Check for HAL device in alternate format
      if(CheckFormat(AltFormat, FALSE, TRUE) == TRUE) {
        m_HAL = TRUE;
        Format = AltFormat;
      } else {
        // Check for Emulation device
        if(CheckFormat(Format, FALSE, FALSE) == FALSE) {
          // Check for Emulation device in alternate format
          if(CheckFormat(AltFormat, FALSE, FALSE) == FALSE)
            return FALSE;
          else
            Format = AltFormat;
        }
      }
    }

    d3dpp.BackBufferFormat = Format;
  }

  // Setup Zbuffer format - 16 bit
  if((m_ZBuffer = UseZBuffer) == TRUE) {
    d3dpp.EnableAutoDepthStencil = TRUE;
    d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
  } else {
    d3dpp.EnableAutoDepthStencil = FALSE;
  }

  // Create the Direct3D Device object
  if(FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, 
               (m_HAL == TRUE) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF, 
               hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
               &d3dpp, &m_pD3DDevice))) {

    // Try to create Direct3D without ZBuffer support 
    // if selected and first call failed.
    if(m_ZBuffer == TRUE) {
      m_ZBuffer = FALSE;
      d3dpp.EnableAutoDepthStencil = FALSE;

      if(FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, 
                   (m_HAL == TRUE) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF, 
                   hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                   &d3dpp, &m_pD3DDevice)))
        return FALSE;
    } else                                   
      return FALSE;
  }

	//// create and set the render target surface
 //   // it should be lockable on XP and nonlockable on Vista
 //   if (FAILED(m_pD3DDevice->CreateRenderTarget(m_Width, m_Height, 
 //       D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, 
 //       TRUE, // lockable
 //       &m_pD3DSurface, NULL)))
 //   {
 //       return FALSE;
 //   }
 //   //m_pD3DDevice->SetRenderTarget(0, m_pD3DSurface);

  // Set default rendering states
  EnableLighting(FALSE);
  EnableZBuffer(m_ZBuffer);
  EnableAlphaBlending(FALSE);
  EnableAlphaTesting(FALSE);

  // Enable texture rendering stages and filter types
  m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
  m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
  m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );

  m_pD3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
  m_pD3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);

  // Set default ambient color to white
  SetAmbientLight(255,255,255);

  // Calculate the aspect ratio based on window size
  Aspect = (float)m_Height / (float)m_Width;
  SetPerspective(D3DX_PI/4, Aspect, 1.0f, 10000.0f);

  // Create a sprite interface
  if(FAILED(D3DXCreateSprite(m_pD3DDevice, &m_pSprite)))
    return FALSE;

  return TRUE;
}