void InitViewMatrix(void) { static char matrix_string[256]; // put the center at the origin for opengl. get_opengl_transforms(); sprintf(matrix_string,"%0.2f %0.2f %0.2f %0.2f %0.2f %0.2f %0.2f %0.2f %0.2f", (ldraw_commandline_opts.S * ldraw_commandline_opts.A.a), (ldraw_commandline_opts.S * ldraw_commandline_opts.A.b), (ldraw_commandline_opts.S * ldraw_commandline_opts.A.c), (ldraw_commandline_opts.S * ldraw_commandline_opts.A.d), (ldraw_commandline_opts.S * ldraw_commandline_opts.A.e), (ldraw_commandline_opts.S * ldraw_commandline_opts.A.f), (ldraw_commandline_opts.S * ldraw_commandline_opts.A.g), (ldraw_commandline_opts.S * ldraw_commandline_opts.A.h), (ldraw_commandline_opts.S * ldraw_commandline_opts.A.i)); #ifdef USE_GL_TWIRL sprintf(matrix_string,"1.00 0.00 0.00 0.00 1.00 0.00 0.00 0.00 1.00"); #endif if (ldraw_commandline_opts.debug_level == 1) printf("SetViewMatrix(%s);\n", matrix_string); SetViewMatrix(matrix_string); }
void Renderer::SetViewMatrix(const Vec3f & position, const Vec3f & dir, const Vec3f & up) { EERIEMATRIX mat; Util_SetViewMatrix(mat, position, dir, up); SetViewMatrix(mat); }
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; };
void CTouchFreeCamera::Update(float dt) { if(m_isDragging) { float deltaX = m_dragPosition.x - m_mousePosition.x; float deltaY = m_dragPosition.y - m_mousePosition.y; m_cameraHAngle = m_dragHAngle + deltaX * 0.015f; m_cameraVAngle = m_dragVAngle + deltaY * 0.015f; m_cameraVAngle = std::min<float>(m_cameraVAngle, M_PI / 2); m_cameraVAngle = std::max<float>(m_cameraVAngle, -M_PI / 2); } CMatrix4 yawMatrix(CMatrix4::MakeAxisYRotation(m_cameraHAngle)); CMatrix4 pitchMatrix(CMatrix4::MakeAxisXRotation(m_cameraVAngle)); CMatrix4 rotationMatrix = yawMatrix * pitchMatrix; if(m_isStrafingLeft || m_isStrafingRight) { CVector3 rightVector = CVector3(1, 0, 0) * rotationMatrix; float direction = m_isStrafingLeft ? (-1.0f) : (1.0f); m_cameraPosition += (rightVector * direction * MOVE_SPEED * dt); } if(m_isMovingForward || m_isMovingBackward) { CVector3 forwardVector = CVector3(0, 0, 1) * rotationMatrix; float direction = m_isMovingForward ? (-1.0f) : (1.0f); m_cameraPosition += (forwardVector * direction * MOVE_SPEED * dt); } CMatrix4 translationMatrix(CMatrix4::MakeTranslation(-m_cameraPosition.x, -m_cameraPosition.y, -m_cameraPosition.z)); CMatrix4 totalMatrix = translationMatrix * rotationMatrix; SetViewMatrix(totalMatrix); }
void GuiLabel::Render(const TMatrix4x4f& pViewMatrix) { SetViewMatrix(pViewMatrix*GetAdjMatrix()); DrawImage(tImgFone, GetVertexObj(), GetStdTextureObj(), cColor); sCaption.Render(*this,pViewMatrix); GuiEnControl::Render(pViewMatrix); }
//------------------------------------- // 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(); }
void NsRendererOGL3::ResetMatrices() { mWorldMatrix = NsMatrix4::Identity(); mViewMatrix = NsMatrix4::Identity(); mProjMatrix = NsMatrix4::Identity(); SetWorldMatrix(NsMatrix4::Identity()); SetViewMatrix(NsMatrix4::Identity()); SetProjectionMatrix(NsMatrix4::Identity()); }
void CGameRenderer::ComposeFrame(){ m_d3ddevice->Clear(0L, NULL, D3DCLEAR_TARGET, 0xFFFFFF, 1.0f, 0L); //clear render buffer if(SUCCEEDED(m_d3ddevice->BeginScene())){ //can start rendering //move objects g_cObjectManager.move(); //set camera location float x, y; //plane's current location g_cObjectManager.GetPlayerLocation(x, y); //get plane's lcoation if(m_bCameraDefaultMode) SetViewMatrix(x+500, y, -350.0f); else SetViewMatrix(x + g_nScreenWidth/2.0f, 1000.0f, -5000.0f); //draw background DrawBackground(x + g_nScreenWidth/2); //draw objects g_cObjectManager.draw(); if(currentKey > 4){ //while(VFrameCount < 6){ //for(VFrameCount = 0; VFrameCount < 6; VFrameCount++){ g_cObjectManager.draw2(currentKey-4); // VFrameCount++; //} //} if(AttackCount) currentKey = currentKey - 4; VFrameCount = 0; }else{ AttackCount = FALSE; g_cObjectManager.draw(currentKey); } //draw text on the HUD g_cObjectManager.DrawTextHeader(); m_d3ddevice->EndScene(); //done rendering } } //ComposeFrame
void GuiCheckbox::Render(const TMatrix4x4f& pViewMatrix) { if (!vboCheckImg) InitCheckImg(); RefTexture img(IsEnable()?(bChecked?tImgDown:tImgUp):(bChecked?tImgDownNE:tImgUpNE)); SetViewMatrix(pViewMatrix*GetAdjMatrix()); DrawImage(tImgFone, GetVertexObj(), GetStdTextureObj(), cColor); DrawImage(img, vboCheckImg, GetStdTextureObj(), cColor); sCaption.Render(*this,pViewMatrix); GuiEnControl::Render(pViewMatrix); }
void DrawModel(void) { if (!nParts) return; #ifdef USE_OPENGL InitViewMatrix(); if (ldraw_commandline_opts.output > 0) { if ((output_file = fopen(output_file_name,"w+"))==NULL) { ldraw_commandline_opts.output = 0; } } Init1LineCounter(); include_stack_ptr = 0; // Start nesting level pointer at 0. #ifdef USE_OPENGL if (1) { struct L3PartS *RCPartPtr = LoadRC(); if (RCPartPtr) DrawPart(1,RCPartPtr, ldraw_commandline_opts.C, m_m); } #endif DrawPart(1,&Parts[0], ldraw_commandline_opts.C, m_m); //if (ldraw_commandline_opts.output != 1) zStep(INT_MAX, 0); // if (include_stack_ptr <= ldraw_commandline_opts.output_depth ) include_stack_ptr = 0; zStep(stepcount,0); if (output_file != NULL) { fclose(output_file); output_file = NULL; } if (ldraw_commandline_opts.debug_level == 1) printf("Done\n"); #else SetViewMatrix("1 0 1 .5 1 -.5 -1 0 1"); DrawPart(1,&Parts[0], 7, m_m); #endif }
Plane::Plane( D3D::GraphicDevice &device, const Material& material ) : device_(device), vertexDeclaration_(device, DefaultVertexDeclaration), vertexBuffer_(device), indexBuffer_(device), shader_(device, L"plane.vsh"), material_(material) { Vertices vertices; Indices indices; InitVertices( vertices, indices ); nVertices_ = vertices.size(); nPrimitives_ = indices.size()/3; vertexBuffer_.SetVertices( &vertices[0], vertices.size() ); indexBuffer_.SetIndices( &indices[0], indices.size() ); SetViewMatrix( UnityMatrix() ); SetProjectiveMatrix( UnityMatrix() ); }
void GuiImage::Render(const TMatrix4x4f& pViewMatrix) { SetViewMatrix(pViewMatrix); /*Texture::Texture2D_Sync& tex(avi_read.GetFrame()); Sync lock_section(tex.GetSyncObject()); if (tex.IsChanged()) { tex.Bind(); tex.SendGPU(false); } DrawImage(&tex, GetVertexObj(), GetStdTextureObj(), cColor);*/ DrawImage(tImg, GetVertexObj(), GetStdTextureObj(), cColor); GuiControl::Render(pViewMatrix); GuiControl::SetChangeFlag(); }
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 ); }
Sphere::Sphere( float radius, unsigned tesselationLevel, D3D::GraphicDevice device, float freq, const Material& material ) : device_(device), vertexDeclaration_(device, DefaultVertexDeclaration), vertexBuffer_(device), indexBuffer_(device), shader_(device, L"sphere.vsh"), radius_(radius), tesselationLevel_(tesselationLevel), freq_(freq), material_(material) { Vertices vertices; Indices indices; InitVertices(tesselationLevel, radius*sqrtf(2), vertices, indices); nVertices_ = vertices.size(); nPrimitives_ = indices.size()/3; vertexBuffer_.SetVertices( &vertices[0], vertices.size() ); indexBuffer_.SetIndices( &indices[0], indices.size() ); SetPositionMatrix( UnityMatrix() ); SetViewMatrix( UnityMatrix() ); SetProjectiveMatrix( UnityMatrix() ); }
void ceDeviceGL20::SetCamera (const ceCamera &camera) { SetViewMatrix(camera.GetMatrix()); }
void CL3View::OnToolbarRight() { SetViewMatrix("0 0 -1 0 1 0 1 0 0"); }
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) ); }
void CL3View::OnToolbarBack() { SetViewMatrix("-1 0 0 0 1 0 0 0 -1"); }
//-------------------------------------------------------------------------------------- // Called every time the application receives a message //-------------------------------------------------------------------------------------- LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { PAINTSTRUCT ps; HDC hdc; float step = 0.1f; bool cambiaView = false; switch( message ) { case WM_PAINT: hdc = BeginPaint( hWnd, &ps ); EndPaint( hWnd, &ps ); break; case WM_DESTROY: PostQuitMessage( 0 ); break; case WM_KEYDOWN: switch (wParam) { case 0x57: // W z += step; cambiaView = true; break; case 0x53: // S z -= step; cambiaView = true; break; case 0x41: // A x -= step; cambiaView = true; break; case 0x44: // D x += step; cambiaView = true; break; case 0x51: // Q y += step; cambiaView = true; break; case 0x45: // E y -= step; cambiaView = true; break; case 0x42: // B bump = (float)(((int)bump + 1) % 2); break; case 0x56: // V vsync = !vsync; break; case 'T': useTexture = (float)(((int)useTexture + 1) % 2); break; case 'C': x = 0.0f, y = 0.0f, z = -5.0f; cambiaView = true; break; case 'P': paused = !paused; if (!paused) { restarted = true; } break; case 'R': rotate = !rotate; break; case 'M': if (modelo == ModeloMono) modelo = ModeloCubo; else if (modelo == ModeloCubo) modelo = ModeloMono; break; case 'F': wireframe = !wireframe; /* if ( !wireframe ) { g_pImmediateContext->RSSetState(m_rasterState); } else { g_pImmediateContext->RSSetState(m_rasterStateWF); } */ break; } if (cambiaView) SetViewMatrix(); break; case WM_LBUTTONDOWN: ptBeg.x = ptEnd.x = LOWORD(lParam); ptBeg.y = ptEnd.y = HIWORD(lParam); SetCursor(LoadCursor(NULL, IDC_CROSS)); fBlocking = TRUE; return 0; case WM_MOUSEMOVE: if (fBlocking) { SetCursor(LoadCursor(NULL, IDC_CROSS)); ptEnd.x = LOWORD(lParam); ptEnd.y = HIWORD(lParam); x += (ptEnd.x - ptBeg.x) / 4.0f; y += (ptEnd.y - ptBeg.y) / 4.0f; ptBeg.x = ptEnd.x; ptBeg.y = ptEnd.y; SetViewMatrix(); } return 0; case WM_LBUTTONUP: if (fBlocking) { SetCursor(LoadCursor(NULL, IDC_ARROW)); fBlocking = FALSE; } return 0; default: return DefWindowProc( hWnd, message, wParam, lParam ); } return 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 CL3View::OnToolbarLeft() { SetViewMatrix("0 0 1 0 1 0 -1 0 0"); }
HRESULT InitDevice() { HRESULT hr = S_OK; RECT rc; GetClientRect(g_hWnd, &rc); UINT width = rc.right - rc.left; UINT height = rc.bottom - rc.top; UINT createDeviceFlags = 0; #ifdef _DEBUG createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; #endif D3D_DRIVER_TYPE driverTypes[] = { D3D_DRIVER_TYPE_HARDWARE, D3D_DRIVER_TYPE_WARP, D3D_DRIVER_TYPE_REFERENCE, }; UINT numDriverTypes = ARRAYSIZE(driverTypes); D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0, }; UINT numFeatureLevels = ARRAYSIZE(featureLevels); DXGI_SWAP_CHAIN_DESC sd; ZeroMemory(&sd, sizeof(sd)); sd.BufferCount = 1; sd.BufferDesc.Width = width; sd.BufferDesc.Height = height; sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; sd.BufferDesc.RefreshRate.Numerator = 60; sd.BufferDesc.RefreshRate.Denominator = 1; sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; sd.OutputWindow = g_hWnd; sd.SampleDesc.Count = 1; sd.SampleDesc.Quality = 0; sd.Windowed = TRUE; sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; for (UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++) { g_driverType = driverTypes[driverTypeIndex]; hr = D3D11CreateDeviceAndSwapChain(NULL, g_driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext); if (SUCCEEDED(hr)) break; } if (FAILED(hr)) return hr; // Create a render target view ID3D11Texture2D* pBackBuffer = NULL; hr = g_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer); if (FAILED(hr)) return hr; hr = g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &g_pRenderTargetView); pBackBuffer->Release(); if (FAILED(hr)) return hr; // Create depth stencil texture D3D11_TEXTURE2D_DESC descDepth; ZeroMemory(&descDepth, sizeof(descDepth)); descDepth.Width = width; descDepth.Height = height; descDepth.MipLevels = 1; descDepth.ArraySize = 1; descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; descDepth.SampleDesc.Count = 1; descDepth.SampleDesc.Quality = 0; descDepth.Usage = D3D11_USAGE_DEFAULT; descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL; descDepth.CPUAccessFlags = 0; descDepth.MiscFlags = 0; hr = g_pd3dDevice->CreateTexture2D(&descDepth, NULL, &g_pDepthStencil); if (FAILED(hr)) return hr; // Create the depth stencil view D3D11_DEPTH_STENCIL_VIEW_DESC descDSV; ZeroMemory(&descDSV, sizeof(descDSV)); descDSV.Format = descDepth.Format; descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; descDSV.Texture2D.MipSlice = 0; hr = g_pd3dDevice->CreateDepthStencilView(g_pDepthStencil, &descDSV, &g_pDepthStencilView); if (FAILED(hr)) return hr; g_pImmediateContext->OMSetRenderTargets(1, &g_pRenderTargetView, g_pDepthStencilView); // Setup the viewport D3D11_VIEWPORT vp; vp.Width = (FLOAT)width; vp.Height = (FLOAT)height; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; vp.TopLeftX = 0; vp.TopLeftY = 0; g_pImmediateContext->RSSetViewports(1, &vp); // Compile the vertex shader ID3DBlob* pVSBlob = NULL; hr = CompileShaderFromFile(L"Tutorial05.fx", "VS", "vs_4_0", &pVSBlob); if (FAILED(hr)) { MessageBox(NULL, L"The FX file cannot be compiled. Please run this executable from the directory that contains the FX file.", L"Error", MB_OK); return hr; } // Create the vertex shader hr = g_pd3dDevice->CreateVertexShader(pVSBlob->GetBufferPointer(), pVSBlob->GetBufferSize(), NULL, &g_pVertexShader); if (FAILED(hr)) { pVSBlob->Release(); return hr; } // Define the input layout D3D11_INPUT_ELEMENT_DESC layout[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 36, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 48, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "BINORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 60, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; UINT numElements = ARRAYSIZE(layout); // Create the input layout hr = g_pd3dDevice->CreateInputLayout(layout, numElements, pVSBlob->GetBufferPointer(), pVSBlob->GetBufferSize(), &g_pVertexLayout); pVSBlob->Release(); if (FAILED(hr)) return hr; // Set the input layout g_pImmediateContext->IASetInputLayout(g_pVertexLayout); // Compile the pixel shader ID3DBlob* pPSBlob = NULL; hr = CompileShaderFromFile(L"Tutorial05.fx", "PS", "ps_4_0", &pPSBlob); if (FAILED(hr)) { MessageBox(NULL, L"The FX file cannot be compiled. Please run this executable from the directory that contains the FX file.", L"Error", MB_OK); return hr; } // Create the pixel shader hr = g_pd3dDevice->CreatePixelShader(pPSBlob->GetBufferPointer(), pPSBlob->GetBufferSize(), NULL, &g_pPixelShader); pPSBlob->Release(); if (FAILED(hr)) return hr; // ------------------------------------------------------------- // JPE: Shaders para WireFrame // ------------------------------------------------------------- // Compile the vertex shader ID3DBlob* pVSBlobWF = NULL; hr = CompileShaderFromFile(L"Tutorial05.fx", "VS_WF", "vs_4_0", &pVSBlobWF); if (FAILED(hr)) { MessageBox(NULL, L"The FX file cannot be compiled. Please run this executable from the directory that contains the FX file.", L"Error", MB_OK); return hr; } // Create the vertex shader hr = g_pd3dDevice->CreateVertexShader(pVSBlobWF->GetBufferPointer(), pVSBlobWF->GetBufferSize(), NULL, &g_pVertexShaderWF); pVSBlobWF->Release(); if (FAILED(hr)) return hr; // Compile the pixel shader ID3DBlob* pPSBlobWF = NULL; hr = CompileShaderFromFile(L"Tutorial05.fx", "PS_WF", "ps_4_0", &pPSBlobWF); if (FAILED(hr)) { MessageBox(NULL, L"The FX file cannot be compiled. Please run this executable from the directory that contains the FX file.", L"Error", MB_OK); return hr; } // Create the pixel shader hr = g_pd3dDevice->CreatePixelShader(pPSBlobWF->GetBufferPointer(), pPSBlobWF->GetBufferSize(), NULL, &g_pPixelShaderWF); pPSBlobWF->Release(); if (FAILED(hr)) return hr; // ------------------------------------------------------------- // JPE: Create vertex buffer and index buffer SimpleVertex* vertices; WORD* indices; if (modelo == ModeloMono) { LoadFileOFF(&vertices, &indices, &cantVertices, &cantIndices); } else { LoadVertices(&vertices, &indices, &cantVertices, &cantIndices); } CalcularNormales(vertices, indices, cantVertices, cantIndices); // Crea Buffer para Vertices D3D11_BUFFER_DESC bd; ZeroMemory( &bd, sizeof(bd) ); bd.Usage = D3D11_USAGE_DEFAULT; bd.ByteWidth = sizeof( SimpleVertex ) * cantVertices; bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; bd.CPUAccessFlags = 0; D3D11_SUBRESOURCE_DATA InitData; ZeroMemory( &InitData, sizeof(InitData) ); InitData.pSysMem = vertices; hr = g_pd3dDevice->CreateBuffer( &bd, &InitData, &g_pVertexBuffer ); if( FAILED( hr ) ) return hr; // Set vertex buffer UINT stride = sizeof( SimpleVertex ); UINT offset = 0; g_pImmediateContext->IASetVertexBuffers( 0, 1, &g_pVertexBuffer, &stride, &offset ); // Crea Buffer para Indexes bd.Usage = D3D11_USAGE_DEFAULT; bd.ByteWidth = sizeof( WORD ) * cantIndices; // 36 vertices needed for 12 triangles in a triangle list bd.BindFlags = D3D11_BIND_INDEX_BUFFER; bd.CPUAccessFlags = 0; InitData.pSysMem = indices; hr = g_pd3dDevice->CreateBuffer( &bd, &InitData, &g_pIndexBuffer ); if( FAILED( hr ) ) return hr; // Set index buffer g_pImmediateContext->IASetIndexBuffer( g_pIndexBuffer, DXGI_FORMAT_R16_UINT, 0 ); // Set primitive topology g_pImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); // Create the constant buffer bd.Usage = D3D11_USAGE_DEFAULT; bd.ByteWidth = sizeof(ConstantBuffer); bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; bd.CPUAccessFlags = 0; hr = g_pd3dDevice->CreateBuffer( &bd, NULL, &g_pConstantBuffer ); if( FAILED( hr ) ) return hr; // JPE: Create the constant buffer for PixelShader bd.Usage = D3D11_USAGE_DEFAULT; bd.ByteWidth = sizeof(ConstantBufferPS); bd.BindFlags = D3D11_BIND_SHADER_RESOURCE; bd.CPUAccessFlags = 0; hr = g_pd3dDevice->CreateBuffer(&bd, NULL, &g_pConstantBufferPS); if (FAILED(hr)) return hr; // Initialize the world matrix g_World1 = XMMatrixIdentity(); g_World2 = XMMatrixIdentity(); SetViewMatrix(); // Initialize the projection matrix g_Projection = XMMatrixPerspectiveFovLH( XM_PIDIV2, width / (FLOAT)height, 0.01f, 100.0f ); // JPE: Texturas loadTextures(g_pd3dDevice); // JPE: Raster state ///* D3D11_RASTERIZER_DESC rasterDesc; // Setup the raster description which will determine how and what polygons will be drawn. rasterDesc.AntialiasedLineEnable = false; rasterDesc.CullMode = D3D11_CULL_BACK; rasterDesc.DepthBias = 0; rasterDesc.DepthBiasClamp = 0.0f; rasterDesc.DepthClipEnable = true; rasterDesc.FillMode = D3D11_FILL_SOLID; rasterDesc.FrontCounterClockwise = false; rasterDesc.MultisampleEnable = false; rasterDesc.ScissorEnable = false; rasterDesc.SlopeScaledDepthBias = 0.0f; // Create the rasterizer state from the description we just filled out. hr = g_pd3dDevice->CreateRasterizerState(&rasterDesc, &m_rasterState); if (FAILED(hr)) { return hr; } // Now set the rasterizer state. g_pImmediateContext->RSSetState(m_rasterState); //*/ // JPE: Raster state para WireFrame // Setup the raster description which will determine how and what polygons will be drawn. rasterDesc.AntialiasedLineEnable = false; rasterDesc.CullMode = D3D11_CULL_BACK; rasterDesc.DepthBias = 0; rasterDesc.DepthBiasClamp = 0.0f; rasterDesc.DepthClipEnable = true; rasterDesc.FillMode = D3D11_FILL_WIREFRAME; rasterDesc.FrontCounterClockwise = false; rasterDesc.MultisampleEnable = false; rasterDesc.ScissorEnable = false; rasterDesc.SlopeScaledDepthBias = 0.0f; // Create the rasterizer state from the description we just filled out. hr = g_pd3dDevice->CreateRasterizerState(&rasterDesc, &m_rasterStateWF); if (FAILED(hr)) { return hr; } // JPE: Parametros default if (modelo == ModeloMono) { bump = false; useTexture = false; rotate = false; } return S_OK; }
void CL3View::OnToolbarFront() { SetViewMatrix("1 0 0 0 1 0 0 0 1"); }
void CL3View::OnToolbarOver() { SetViewMatrix("0 0 1 1 0 0 0 1 0"); }
sector_t * FGLRenderer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen) { sector_t * lviewsector; mSceneClearColor[0] = 0.0f; mSceneClearColor[1] = 0.0f; mSceneClearColor[2] = 0.0f; R_SetupFrame (camera); SetViewArea(); // We have to scale the pitch to account for the pixel stretching, because the playsim doesn't know about this and treats it as 1:1. double radPitch = ViewPitch.Normalized180().Radians(); double angx = cos(radPitch); double angy = sin(radPitch) * glset.pixelstretch; double alen = sqrt(angx*angx + angy*angy); mAngles.Pitch = (float)RAD2DEG(asin(angy / alen)); mAngles.Roll.Degrees = ViewRoll.Degrees; // Scroll the sky mSky1Pos = (float)fmod(gl_frameMS * level.skyspeed1, 1024.f) * 90.f/256.f; mSky2Pos = (float)fmod(gl_frameMS * level.skyspeed2, 1024.f) * 90.f/256.f; if (camera->player && camera->player-players==consoleplayer && ((camera->player->cheats & CF_CHASECAM) || (r_deathcamera && camera->health <= 0)) && camera==camera->player->mo) { mViewActor=NULL; } else { mViewActor=camera; } // 'viewsector' will not survive the rendering so it cannot be used anymore below. lviewsector = viewsector; // Render (potentially) multiple views for stereo 3d float viewShift[3]; const s3d::Stereo3DMode& stereo3dMode = mainview && toscreen? s3d::Stereo3DMode::getCurrentMode() : s3d::Stereo3DMode::getMonoMode(); stereo3dMode.SetUp(); for (int eye_ix = 0; eye_ix < stereo3dMode.eye_count(); ++eye_ix) { const s3d::EyePose * eye = stereo3dMode.getEyePose(eye_ix); eye->SetUp(); SetOutputViewport(bounds); Set3DViewport(mainview); mDrawingScene2D = true; mCurrentFoV = fov; // Stereo mode specific perspective projection SetProjection( eye->GetProjection(fov, ratio, fovratio) ); // SetProjection(fov, ratio, fovratio); // switch to perspective mode and set up clipper SetViewAngle(ViewAngle); // Stereo mode specific viewpoint adjustment - temporarily shifts global ViewPos eye->GetViewShift(GLRenderer->mAngles.Yaw.Degrees, viewShift); s3d::ScopedViewShifter viewShifter(viewShift); SetViewMatrix(ViewPos.X, ViewPos.Y, ViewPos.Z, false, false); gl_RenderState.ApplyMatrices(); clipper.Clear(); angle_t a1 = FrustumAngle(); clipper.SafeAddClipRangeRealAngles(ViewAngle.BAMs() + a1, ViewAngle.BAMs() - a1); ProcessScene(toscreen); if (mainview && toscreen) EndDrawScene(lviewsector); // do not call this for camera textures. if (mainview && FGLRenderBuffers::IsEnabled()) { mBuffers->BlitSceneToTexture(); UpdateCameraExposure(); BloomScene(); TonemapScene(); ColormapScene(); LensDistortScene(); ApplyFXAA(); // This should be done after postprocessing, not before. mBuffers->BindCurrentFB(); glViewport(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height); DrawBlend(lviewsector); } mDrawingScene2D = false; if (!stereo3dMode.IsMono() && FGLRenderBuffers::IsEnabled()) mBuffers->BlitToEyeTexture(eye_ix); eye->TearDown(); } stereo3dMode.TearDown(); gl_frameCount++; // This counter must be increased right before the interpolations are restored. interpolator.RestoreInterpolations (); return lviewsector; }
void CL3View::OnToolbarUnder() { SetViewMatrix("0 0 1 -1 0 0 0 -1 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; }
//----------------------------------------------------------------------------- // // SetupView // Setup the view rotation matrix for the given viewpoint // //----------------------------------------------------------------------------- void FGLRenderer::SetupView(float vx, float vy, float vz, DAngle va, bool mirror, bool planemirror) { SetViewAngle(va); SetViewMatrix(vx, vy, vz, mirror, planemirror); gl_RenderState.ApplyMatrices(); }
void CL3View::OnToolbarFur() // Front Upper Right { SetViewMatrix("1 0 1 .5 1 -.5 -1 0 1"); }