Beispiel #1
0
	bool DX9RenderSystem::Begin2d( )
	{
		SetCullMode( CullMode::NONE );
		SetFillMode( FillMode::SOLID );
		SetProjectionMatrix( Matrix4::CreateOrthoLH( (float)mSize.x, -(float)mSize.y, 0.0f, 1.0f ) );
		SetViewMatrix( Matrix4::IDENTITY );
		SetWorldMatrix( Matrix4::IDENTITY );
		SetVertexDeclaration( m2dDecl );

		SetTextureStageState( 0, TextureState::TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
		SetTextureStageState( 0, TextureState::COLOROP, BlendOp::MODULATE );
		SetTextureStageState( 0, TextureState::COLORARG1, BlendArg::TEXTURE );
		SetTextureStageState( 0, TextureState::COLORARG2, BlendArg::DIFFUSE );
		SetTextureStageState( 0, TextureState::ALPHAOP, BlendOp::MODULATE );
		SetTextureStageState( 0, TextureState::ALPHAARG1, BlendArg::TEXTURE );
		SetTextureStageState( 0, TextureState::ALPHAARG2, BlendArg::DIFFUSE );
		SetTextureStageState( 1, TextureState::COLOROP, BlendOp::DISABLE );
		SetTextureStageState( 1, TextureState::ALPHAOP, BlendOp::DISABLE );
		SetAlphaBlendEnabled( true );
		SetAlphaTestEnabled( false );
		SetDepthWriteEnabled( true );
		SetDepthBufferEnabled( false );
		SetSpecularEnabled( false );

		return true;
	};
Beispiel #2
0
void renderScene(GLFWwindow *window, ShadowMap *shadowMap) {
    glUseProgram(ShadeProg);

    glUniform3f(h_uLightColor, 0.4, 0.4, 0.38);
    glUniform4f(h_uLightVec, 0.0, 1.0, 1.0, 0.0);

    // Render depth info from light's perspective
    shadowMap->BindFBO();
    glClear(GL_DEPTH_BUFFER_BIT);
    curView = SetView(); // CHANGE TO LIGHT'S PERSPECTIVE, NOT EYE
    curProj = SetOrthoProjectionMatrix();
    glUniform3f(h_uCamPos, 0.0, 1.0, 1.0);
    glfwDraw(window);

    // Render scene normally and draw
    shadowMap->UnbindFBO();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    curView = SetView();
    curProj = SetProjectionMatrix();
    glUniform3f(h_uCamPos, GetEye().x, GetEye().y, GetEye().z);
    glfwDraw(window);

    // Disable the shaders
    glUseProgram(0);
    glfwSwapBuffers(window);
}
Beispiel #3
0
/* Main display function */
void Draw (void)
{
   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   //Start our shader   
   glUseProgram(ShadeProg);
   
   SetModelI();
   /* Set up the projection and view matrices */
   SetProjectionMatrix();
   SetView();

   /* Set up the light's direction and color */
   glUniform3f(h_uLightColor, sunShade.x, sunShade.y, sunShade.z);
   glUniform3f(h_uSun, sunDir.x, sunDir.y, sunDir.z);

   // set the normal flag
   glUniform1i(h_uShadeType, g_shadeType);

 // ======================== draw square stuff =========================

      drawModel(&bunnyModel);

 // ================== end of bird stuff ====================

   //clean up 
   safe_glDisableVertexAttribArray(h_aPosition);
   safe_glDisableVertexAttribArray(h_aNormal);

   //disable the shader
   glUseProgram(0);
}
Beispiel #4
0
void ViewCtrl::hitscene(float &x, float &y, float &z){  

  SetProjectionMatrix();
  glReadPixels(x,mssh.wndh-y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&z);
  //printf("before: px=%f py=%f pz=%f\n", x,y,z);
  BackScreenTransform(x,y,z);
  //printf("scene point:  px=%f py=%f pz=%f\n", x,y,z);
}
//-------------------------------------
// Update()
//-------------------------------------
void EffectManager::Update()
{
	SetViewMatrix();
	SetProjectionMatrix();
	for (auto it = effects_.begin(); it != effects_.end(); ++it){
		(*it).second->Update(manager_);
	}
	manager_->Update();
	effect_count_ = effects_.size();
}
Beispiel #6
0
void ViewCtrl::movecont(int x, int y){
  if(opercode==3){
    int dy = (zoomy-y);
    zoom = zoom0*(250+dy)/250.;
    SetProjectionMatrix();
  }
  else{
    mssh.ContinueMOper(x,y);
  }
}
void NsRendererOGL3::ResetMatrices()
{
	mWorldMatrix = NsMatrix4::Identity();
	mViewMatrix = NsMatrix4::Identity();
	mProjMatrix = NsMatrix4::Identity();
	
	SetWorldMatrix(NsMatrix4::Identity());
	SetViewMatrix(NsMatrix4::Identity());
	SetProjectionMatrix(NsMatrix4::Identity());
}
Beispiel #8
0
//----------------------------------------------------------------------------
void Renderer_GL::ReshapeWindow(int w, int h)
{
	windowWidth = w;
	windowHeight = h;

	const float defaultFov = 60.0f;	
	const float defaultNear = 0.1f;
	const float defaultFar = 100.0f;
	
	SetProjectionMatrix(defaultFov, defaultNear, defaultFar);
}
Beispiel #9
0
void ViewCtrl::SelectObj2(int x, int y) { 
  mssh.sx0=x;mssh.sy0=y;
  SetProjectionMatrix();
  glSelectBuffer (1024, selectBuf); 
  glRenderMode (GL_SELECT); 
  glInitNames(); 
  dv->Draw(0);
  hits = glRenderMode (GL_RENDER);
  if(hits==-1){
  	printf("ViewCtrl::SelectObj2 \"Selection Buffer overflow\"\n");
    hits=0;
  }
}
Beispiel #10
0
void TreeViewport::wheelEvent(QWheelEvent* event)
{
	const float STEP_SIZE = 15;

	if(event->modifiers() == Qt::ControlModifier)
	{
		m_zoom += (event->delta()/STEP_SIZE)*ZOOM_SENSITIVITY;
		SetProjectionMatrix();
	}
	else
	{
		QGraphicsView::wheelEvent(event);
	}
}
GLvoid resize(GLsizei width, GLsizei height) {
    if(height == 0)
    {
        height = 1;
    }

    glViewport(0, 0, width, height);					// Sev view area

    Height = height;
    Width = width;

    SetProjectionMatrix();
    SetModelviewMatrix();
}
void
ShaderProgramOGL::Activate()
{
  if (mProgramState == STATE_NEW) {
    if (!Initialize()) {
      NS_WARNING("Shader could not be initialised");
      return;
    }
  }
  NS_ASSERTION(HasInitialized(), "Attempting to activate a program that's not in use!");
  mGL->fUseProgram(mProgram);

  // check if we need to set the projection matrix
  if (mIsProjectionMatrixStale) {
    SetProjectionMatrix(mProjectionMatrix);
  }
}
Beispiel #13
0
GLvoid Engine::Resize(GLsizei width, GLsizei height)
{
	if (height == 0)									
	{
		height = 1;										
	}

  GLsizei nSize = min(width, height);
	glViewport(0, 0, nSize, nSize);					// ”станавливаетс¤ область просмотра
  //glViewport(0, 0, width, height);					// ”станавливаетс¤ область просмотра

	Height = height;
	Width = width;

	SetProjectionMatrix();
	SetModelviewMatrix();
}
void
ShaderProgramOGL::Activate()
{
  if (mProgramState == STATE_NEW) {
    if (!Initialize()) {
      NS_WARNING("Shader could not be initialised");
      return;
    }
  }
  NS_ASSERTION(HasInitialized(), "Attempting to activate a program that's not in use!");
  mGL->fUseProgram(mProgram);
#if CHECK_CURRENT_PROGRAM
  mGL->SetUserData(&sCurrentProgramKey, this);
#endif
  // check and set the projection matrix
  if (mIsProjectionMatrixStale) {
    SetProjectionMatrix(mProjectionMatrix);
  }
}
void NsRendererOGL3::BeginDraw(NsCamera * pCamera)
{
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );

	glClearDepth(1);

	glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );

	glEnable( GL_DEPTH_TEST );
	glDepthMask( GL_TRUE );
	glDepthFunc( GL_LESS );

	glFrontFace( GL_CCW );
	glEnable( GL_CULL_FACE );
	glCullFace( GL_BACK );

	glPolygonMode( GL_FRONT, GL_FILL );

	ResetMatrices();

	NsMatrix4  projectionMatrix;
	projectionMatrix.BuildPerspectiveLH(
		pCamera->fovY,
		pCamera->aspect,
		pCamera->nearZ,
		pCamera->farZ
	);
	SetProjectionMatrix( projectionMatrix );

	NsMatrix4  viewMatrix(
		BuildLookAtMatrixLH(
			pCamera->viewOrigin,
			pCamera->GetLookDirection(),
			pCamera->GetUp()
	));

	SetViewMatrix( viewMatrix );
}
Beispiel #16
0
void GLWidget::wheelEvent(QWheelEvent * event)
{
    if (m_pMain == NULL)
        return;


    emit Mouse_Wheel();

    /*float sensitivity = 10000.0;
    float fMouseWheelDelta = (event->delta() / sensitivity);
    m_curZoom = m_curZoom + fMouseWheelDelta;*/
    /*if (m_curZoom < 0)
        m_curZoom = 0.0001;*/

    short zDelta = event->delta();

    if (zDelta > 0)
        m_dZoomFactor /= 1.1;		// zoom in
    else
        m_dZoomFactor *= 1.1;

    SetProjectionMatrix();
    updateGL();    
}
Beispiel #17
0
void ViewCtrl::Zoom(float r){
    if(r != 1.0)  zoom *= r;
    else          zoom = 1;
    SetProjectionMatrix();
}
Beispiel #18
0
void ceDeviceGL20::SetProjector (const ceProjector &projector)
{
  SetProjectionMatrix(projector.GetMatrix());
}
Beispiel #19
0
//Initialisation
bool 
ASCDX9Renderer::Initialise( SRendererInit& rParameters )
{
	WNDCLASSEX wc = 
	{ 
		sizeof(WNDCLASSEXA), 
		CS_CLASSDC,
		ASCDX9Renderer::MsgProc, 
		0L, 0L, 
		GetModuleHandle(NULL), 
		NULL, NULL, 
		NULL, NULL,
#ifdef _DEBUG
		"AscensionWindow",
#else
		L"AscensionWindow",
#endif
		NULL 
	};
	RegisterClassEx( &wc );

	LPCWSTR lstrWindowTitle = CharStrToLPCWSTR(rParameters.m_strWindowName.c_str());

	RECT rc = { 0, 0, rParameters.m_uScreenWidth, rParameters.m_uScreenHeight };

	AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, false );

	m_hWnd = CreateWindowW(		L"AscensionWindow",
								lstrWindowTitle,
								WS_OVERLAPPEDWINDOW - (WS_MAXIMIZEBOX|WS_THICKFRAME), 
								CW_USEDEFAULT, CW_USEDEFAULT, 
								rc.right - rc.left, 
								rc.bottom - rc.top, 
								GetDesktopWindow(), NULL, 
								wc.hInstance, NULL );
	
	assert_msg(m_hWnd != NULL, "Guts, Failed to create window");
	
	UINT32 uScreenX = GetSystemMetrics(SM_CXFULLSCREEN);
	UINT32 uScreenY = GetSystemMetrics(SM_CYFULLSCREEN);

	UINT32 uX = (uScreenX / 2) - (rParameters.m_uScreenWidth / 2);
	UINT32 uY = (uScreenY / 2) - (rParameters.m_uScreenHeight / 2);

	SetWindowPos(m_hWnd, NULL, uX, uY, 0, 0, SWP_NOSIZE);

	if ( NULL == ( m_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
	{
		assert_now("Guts, Failed to create D3D9");
		return false;
	}
	
	//Window parameters
	ZeroMemory( &m_d3dPP, sizeof( m_d3dPP ) );
	
	m_d3dPP.Windowed = rParameters.m_bWindowMode;
	m_d3dPP.SwapEffect = D3DSWAPEFFECT_DISCARD;
	m_d3dPP.BackBufferFormat = D3DFMT_X8R8G8B8;
	m_d3dPP.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
	m_d3dPP.EnableAutoDepthStencil = TRUE;
	m_d3dPP.AutoDepthStencilFormat = D3DFMT_D24X8;
	m_d3dPP.BackBufferWidth = rParameters.m_uScreenWidth;
	m_d3dPP.BackBufferHeight = rParameters.m_uScreenHeight;

	UINT32 AdapterToUse = D3DADAPTER_DEFAULT;
	D3DDEVTYPE DeviceType=D3DDEVTYPE_HAL;
	for (UINT32 Adapter = 0; Adapter < m_pD3D->GetAdapterCount(); Adapter++)
	{
		D3DADAPTER_IDENTIFIER9 Identifier;
		HRESULT Res;
		Res = m_pD3D->GetAdapterIdentifier(Adapter,0,&Identifier);
		if (strstr(Identifier.Description,"PerfHUD") != 0)
		{
			AdapterToUse=Adapter;
			DeviceType=D3DDEVTYPE_REF;
			break;
		}
	}
	
	if ( D3D_OK != m_pD3D->CreateDevice( AdapterToUse, DeviceType, 
										m_hWnd,
										 D3DCREATE_HARDWARE_VERTEXPROCESSING,
										&m_d3dPP, &m_pDevice ) ) 
	{
		assert_now("Guts, Failed to create D3D9 device");
		return false;
	}
	
	// Show the window
	ShowWindow( m_hWnd, SW_SHOWDEFAULT );
	UpdateWindow( m_hWnd );

	m_hInst = wc.hInstance;
	
	VertElement sDeclElem[] = {	VertElement::Init(0,	ES_POSITION,	0, ET_FLOAT32,	4),
								VertElement::Init(16,	ES_COLOUR,		0, ET_UINT8,		4),
								VertElement::Init(20,	ES_TANGENT,		0, ET_UINT8,		4),
								VertElement::Init(24,	ES_TEXTURE,		0, ET_FLOAT32,	2),
								VertElement::Init(32,	ES_NORMAL,		0, ET_FLOAT32,	3),
								VertElement::Init(44,	ES_BINORMAL,	0, ET_FLOAT32,	3),};

	m_pDefaultVertDecl = new ASCDX9VertexDeclaration(sDeclElem, 6, m_pDevice);
	m_pDefaultVertDecl->Apply();

	D3DCAPS9 pCaps;
	m_pD3D->GetDeviceCaps(AdapterToUse, DeviceType, &pCaps);
	if (pCaps.AlphaCmpCaps & D3DPCMPCAPS_GREATEREQUAL)
	{
		m_pDevice->SetRenderState(D3DRS_ALPHAREF, (DWORD)0x00000001);
		m_pDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); 
		m_pDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
	}

	SetRenderState( RS_bAlphaBlendEnable, true );
	SetRenderState( RS_bAlphaBlendEnable, true );
	SetRenderState( RS_eAlphaSrcBlend, AB_SrcAlpha );
	SetRenderState( RS_eDestBlend, AB_InvSrcAlpha );
	
	m_pTextureManager = new ASCDX9TextureManager( m_pDevice );
	m_pShaderManager = new ASCDX9ShaderManager( m_pDevice );

	m_ProjectionMatrix = CreateProjectionMatrix( SC_FLOAT(rParameters.m_uScreenWidth), SC_FLOAT(rParameters.m_uScreenHeight), rParameters.m_fNear, rParameters.m_fFar);
	SetProjectionMatrix(m_ProjectionMatrix);

	m_ViewMatrix = CreateViewMatrix();
	SetViewMatrix(m_ViewMatrix);

	return true;
}
Beispiel #20
0
//-----------------------------------------------------------------------------
// Name: RestoreDeviceObjects()
// Desc: Initialize scene objects.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::RestoreDeviceObjects()
{
    // Restore the fonts
    m_pFont->RestoreDeviceObjects();

    HRESULT hr = S_OK;
    D3DLIGHT8 light;

    m_ArcBall.SetWindow( m_d3dsdBackBuffer.Width, m_d3dsdBackBuffer.Height, 2.0f );

    if (m_pdeSelected != NULL)
        SetProjectionMatrix();

    m_pd3dDevice->SetRenderState( D3DRS_DITHERENABLE, TRUE );
    m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
    m_pd3dDevice->SetRenderState( D3DRS_SPECULARENABLE, FALSE );
    m_pd3dDevice->SetRenderState( D3DRS_NORMALIZENORMALS, TRUE );

    m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CW );
    m_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );
    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR  );
    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR  );

    m_pd3dDevice->SetRenderState( D3DRS_COLORVERTEX, FALSE );

    // Create vertex shader for the indexed skinning
    DWORD dwIndexedVertexDecl1[] =
    {
        D3DVSD_STREAM( 0 ),
        D3DVSD_REG( 0, D3DVSDT_FLOAT3 ), // Position of first mesh
        D3DVSD_REG( 2, D3DVSDT_D3DCOLOR ), // Blend indices
//        D3DVSD_REG( 2, D3DVSDT_UBYTE4 ), // Blend indices
        D3DVSD_REG( 3, D3DVSDT_FLOAT3 ), // Normal
        D3DVSD_REG( 4, D3DVSDT_FLOAT2 ), // Tex coords
        D3DVSD_END()
    };

    DWORD dwIndexedVertexDecl2[] =
    {
        D3DVSD_STREAM( 0 ),
        D3DVSD_REG( 0, D3DVSDT_FLOAT3 ), // Position of first mesh
        D3DVSD_REG( 1, D3DVSDT_FLOAT1 ), // Blend weights
        D3DVSD_REG( 2, D3DVSDT_D3DCOLOR ), // Blend indices
//        D3DVSD_REG( 2, D3DVSDT_UBYTE4 ), // Blend indices
        D3DVSD_REG( 3, D3DVSDT_FLOAT3 ), // Normal
        D3DVSD_REG( 4, D3DVSDT_FLOAT2 ), // Tex coords
        D3DVSD_END()
    };

    DWORD dwIndexedVertexDecl3[] =
    {
        D3DVSD_STREAM( 0 ),
        D3DVSD_REG( 0, D3DVSDT_FLOAT3 ), // Position of first mesh
        D3DVSD_REG( 1, D3DVSDT_FLOAT2 ), // Blend weights
        D3DVSD_REG( 2, D3DVSDT_D3DCOLOR ), // Blend indices
//        D3DVSD_REG( 2, D3DVSDT_UBYTE4 ), // Blend indices
        D3DVSD_REG( 3, D3DVSDT_FLOAT3 ), // Normal
        D3DVSD_REG( 4, D3DVSDT_FLOAT2 ), // Tex coords
        D3DVSD_END()
    };

    DWORD dwIndexedVertexDecl4[] =
    {
        D3DVSD_STREAM( 0 ),
        D3DVSD_REG( 0, D3DVSDT_FLOAT3 ), // Position of first mesh
        D3DVSD_REG( 1, D3DVSDT_FLOAT3 ), // Blend weights
        D3DVSD_REG( 2, D3DVSDT_D3DCOLOR ), // Blend indices
//        D3DVSD_REG( 2, D3DVSDT_UBYTE4 ), // Blend indices
        D3DVSD_REG( 3, D3DVSDT_FLOAT3 ), // Normal
        D3DVSD_REG( 4, D3DVSDT_FLOAT2 ), // Tex coords
        D3DVSD_END()
    };

    DWORD* dwIndexedVertexDecl[] = {dwIndexedVertexDecl1, dwIndexedVertexDecl2, dwIndexedVertexDecl3, dwIndexedVertexDecl4};

    LPD3DXBUFFER pCode;

    DWORD bUseSW = D3DUSAGE_SOFTWAREPROCESSING;
    if (m_d3dCaps.VertexShaderVersion >= D3DVS_VERSION(1, 1))
    {
        bUseSW = 0;
    }

    for (DWORD i = 0; i < 4; ++i)
    {
        // Assemble the vertex shader file
        if( FAILED( hr = D3DXAssembleShaderFromResource(NULL, MAKEINTRESOURCE(IDD_SHADER1 + i), 0, NULL, &pCode, NULL ) ) )
            return hr;

        // Create the vertex shader
        if( FAILED( hr = m_pd3dDevice->CreateVertexShader( dwIndexedVertexDecl[i], 
                                             (DWORD*)pCode->GetBufferPointer(),
                                             &(m_dwIndexedVertexShader[i]) , bUseSW ) ) )
        {
            return hr;
        }

        pCode->Release();
    }
    
    ZeroMemory( &light, sizeof(light) );
    light.Type = D3DLIGHT_DIRECTIONAL;

    light.Diffuse.r = 1.0;
    light.Diffuse.g = 1.0;
    light.Diffuse.b = 1.0;
    light.Specular.r = 0;
    light.Specular.g = 0;
    light.Specular.b = 0;
    light.Ambient.r = 0.25;
    light.Ambient.g = 0.25;
    light.Ambient.b = 0.25;

    light.Direction = D3DXVECTOR3( 0.0f, 0.0f, -1.0f);

    hr = m_pd3dDevice->SetLight(0, &light );
    if (FAILED(hr))
        return E_FAIL;

    hr = m_pd3dDevice->LightEnable(0, TRUE);
    if (FAILED(hr))
        return E_FAIL;

    // Set Light for vertex shader
    D3DXVECTOR4 vLightDir( 0.0f, 0.0f, 1.0f, 0.0f );
    m_pd3dDevice->SetVertexShaderConstant(1, &vLightDir, 1);

    return S_OK;
}
Beispiel #21
0
void TreeViewport::ZoomDefault()
{
	m_zoom = 0;
	SetProjectionMatrix();
}
Beispiel #22
0
void TreeViewport::ZoomOut()
{
	m_zoom -= ZOOM_SENSITIVITY;
	SetProjectionMatrix();
}
Beispiel #23
0
CCamera::CCamera( CCamera *camera,CCopier *copier ):
CEntity( camera,copier ){
	SetViewport( camera->Viewport() );
	SetProjectionMatrix( camera->ProjectionMatrix() );
}
Beispiel #24
0
CCamera::CCamera(){
	SetViewport( CRect( 0,0,App.Graphics()->WindowWidth(),App.Graphics()->WindowHeight() ) );
	float aspect=float( App.Graphics()->WindowWidth() )/float( App.Graphics()->WindowHeight() );
	SetProjectionMatrix( CMat4::PerspectiveMatrix( PI/2,aspect,.15f,256.0f ) );
}
Beispiel #25
0
bool Graphics::CreateDefaultShader()
{
	HRESULT r = 0;

	ID3DBlob* vsBuffer = 0;
	ID3DBlob* buffer = 0;

	ID3DBlob* Errors = 0;

	DWORD shaderFlags = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_DEBUG;

	bool b = CompileD3DShader("..\\te010\\DefaultShader.fx", 0, "fx_5_0", &buffer);

	if (!b)
	{
		if (buffer)
		{
			buffer->Release();
		}
		NAIA_FATAL("Unnable to compile default shader");
	}

	r = D3DX11CreateEffectFromMemory(buffer->GetBufferPointer(), buffer->GetBufferSize(), 0 , m_Device, &m_Effect);
	if (FAILED(r))
	{
		NAIA_FATAL("Unnable to create effect");
	}

	m_Technique = m_Effect->GetTechniqueByName("DefaultTechnique");

	if (!m_Technique)
	{
		NAIA_FATAL("Can not find DefaultTechnique in default shader");
	}

	D3D11_INPUT_ELEMENT_DESC defaultLayout[] =
	{
		{"POSITION", 0,  DXGI_FORMAT_R32G32B32_FLOAT,    0,  0,                             D3D11_INPUT_PER_VERTEX_DATA,    0},
		{"NORMAL",   0,  DXGI_FORMAT_R32G32B32_FLOAT,    0,  D3D11_APPEND_ALIGNED_ELEMENT,  D3D11_INPUT_PER_VERTEX_DATA,    0},
		{"COLOR",    0,  DXGI_FORMAT_R32G32B32_FLOAT,    0,  D3D11_APPEND_ALIGNED_ELEMENT,  D3D11_INPUT_PER_VERTEX_DATA,    0},
		{"TEXCOORD", 0,  DXGI_FORMAT_R32G32B32_FLOAT,    0,  D3D11_APPEND_ALIGNED_ELEMENT,  D3D11_INPUT_PER_VERTEX_DATA,    0}
	};

	unsigned int totalLayoutElements = ARRAYSIZE(defaultLayout);

	D3DX11_PASS_DESC descPASS;
	m_Technique->GetPassByIndex(0)->GetDesc(&descPASS);

	r = m_Device->CreateInputLayout(defaultLayout, totalLayoutElements, descPASS.pIAInputSignature, descPASS.IAInputSignatureSize, &m_InputLayout);
	if (FAILED(r))
	{
		NAIA_FATAL("Failed to create input layout");
	}

	m_Context->IASetInputLayout(m_InputLayout);

	Mat4x4 world = Mat4x4::g_Identity;
	SetWorldMatrix(world);

	Mat4x4 view = Mat4x4::g_Identity;
	Vec3 eye(6.0f, 6.0f, 6.0f);
	Vec3 at(0.f,0.f,0.f);
	Vec3 up(0.f,1.0f,0.f);
	D3DXMatrixLookAtLH(&view, &eye, &at, &up);
	SetViewMatrix(view);

	Mat4x4 proj = Mat4x4::g_Identity;
	D3DXMatrixPerspectiveFovLH(&proj, NAIA_PI/2, Application::instance()->m_Width/(float)Application::instance()->m_Height, 0.01f, 100.0f);
	SetProjectionMatrix(proj);

#pragma region Create constant buffers

	D3D11_BUFFER_DESC bd;
	ZeroMemory(&bd, sizeof(bd));
	bd.Usage = D3D11_USAGE_DEFAULT;
	bd.ByteWidth = sizeof(CBNeverChanges);
	bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	bd.CPUAccessFlags = 0; 
	r = m_Device->CreateBuffer(&bd, NULL, &m_cbNeverChanges);
	if (FAILED(r))
	{
		NAIA_FATAL("Can not create constant buffer (Never changes)");
	}

	bd.ByteWidth = sizeof(CBChangeOnResize);
	r = m_Device->CreateBuffer(&bd, NULL, &m_cbChangesOnResize);
	if (FAILED(r))
	{
		NAIA_FATAL("Can not create constant buffer (Changes on resize)");
	}

	bd.ByteWidth = sizeof(CBChangesEveryFrame);
	r = m_Device->CreateBuffer(&bd, NULL, &m_cbChangesEveryFrame);
	if (FAILED(r))
	{
		NAIA_FATAL("Can not create constant buffer (Changes every frame)");
	}
#pragma endregion

	CBNeverChanges cbNeverChanges;
	cbNeverChanges.View = view;
	m_Context->UpdateSubresource(m_cbNeverChanges, 0, NULL, &cbNeverChanges, 0, 0);

	CBChangeOnResize cbChangesOnResize;
	cbChangesOnResize.Projection = proj;
	m_Context->UpdateSubresource(m_cbChangesOnResize, 0, NULL, &cbChangesOnResize, 0, 0);

	CBChangesEveryFrame cbChangesEveryFrame;
	cbChangesEveryFrame.World = world;
	m_Context->UpdateSubresource(m_cbChangesEveryFrame, 0, NULL, &cbChangesEveryFrame, 0, 0);

	return true;
}
void CRender::ViewSetup3D( const CViewSetup *pView, Frustum frustumPlanes )
{
	VPROF("CRender::ViewSetup3D");
	m_view = *pView;
	m_yFOV = CalcFov( m_view.fov, ( float )m_view.width, ( float )m_view.height );

	if( g_nFrameBuffersToClear > 0 )
	{
		SetViewport( m_view.x, m_view.y, m_view.width, m_view.height );
		materialSystemInterface->ClearBuffers( true, m_view.clearDepth );
		g_nFrameBuffersToClear--;
	}

	SetViewport( m_view.x, m_view.y + m_view.height * ( 1.0f - g_ViewportScale ), 
		m_view.width * g_ViewportScale, m_view.height * g_ViewportScale );
	if( m_view.clearColor || m_view.clearDepth )
	{
		materialSystemInterface->ClearBuffers( m_view.clearColor, m_view.clearDepth );
	}
	materialSystemInterface->DepthRange( 0, 1 );

	// build the transformation matrix for the given view angles
	VectorCopy( m_view.origin, r_origin );

	AngleVectors( m_view.angles, &vpn, &vright, &vup );

//	vup = -vup;

	// Copy for VectorTransform
	VectorCopy( &vpn.x, asmvpn );
	VectorCopy( &vright.x, asmvright );
	VectorCopy( &vup.x, asmvup );

	if ( pView->m_bOrtho )
	{
		SetProjectionMatrixOrtho(pView->m_OrthoLeft, pView->m_OrthoTop, pView->m_OrthoRight, pView->m_OrthoBottom, pView->zNear, pView->zFar);
	}
	else
	{
		SetProjectionMatrix( m_view.fov, m_view.zNear, m_view.zFar, m_view.m_bForceAspectRatio1To1 );
	}

	SetViewMatrix( m_view.origin, m_view.angles );

	ExtractMatrices();

	if ( pView->m_bOrtho )
	{
		OrthoExtractFrustumPlanes( frustumPlanes );
	}
	else
	{
		ExtractFrustumPlanes(frustumPlanes);
	}

	OcclusionSystem()->SetView( m_view.origin, m_view.fov, m_matrixView, m_matrixProjection, frustumPlanes[ FRUSTUM_NEARZ ] );

	R_SceneBegin();

	// debug, build leaf volume
	LeafVisBuild( Vector(r_origin) );
}