Jump to content
  • Advertisement

EngineProgrammer

Member
  • Content count

    92
  • Joined

  • Last visited

Community Reputation

295 Neutral

About EngineProgrammer

  • Rank
    Member
  1. EngineProgrammer

    drawing in Win32

    Hey everyone, I'm just having some fun with reinventing many wheels. I just love to understand the low level programming! So here is what I want to do: basically I want to make my own pixel drawing system. I want to create a pixel class which stores a color. After I make an array of [640][480] which will be my "screen". When I gave all pixels a color I want to draw every pixel on the screen. How can I draw all pixels on the screen? SetPixel is a very slow method so I want to avoid that. Is it possible to directly connect my pixels to the screen pixels? How does the GDI communicate with the screen pixels? How can I communicate with the screen pixels without using the GDI or SetPixel? Is it even possible? Kind regards, Jonathan
  2. EngineProgrammer

    3D algorithm

    Thanks for the help, I've made a colorshader last year, but I didn't understood a single line of code what I was writing. Shaders are quite hard to understand for me. How does DirectX render his transformations? I just made a matrix class that can translate, scale and rotate. Tested it and it works. Don't mind how I use the methods. It's just a testing project. Matrix matTranslate, matRotate, matScale, matWorld; matTranslate.SetAsTranslate(-0.7f, -0.4f); matRotate.SetAsRotate(80.0); matScale.SetAsScale(0.5,0.5); matWorld = matRotate * matScale * matTranslate; Matrix::SetAsWorld(hDC, matWorld); Rectangle(hDC, -1, -1, 1, 1); This is what I use for my transformations: Matrix::Matrix(): eM11(0.0f), eM12(0.0f), eM13(0.0f), eM21(0.0f), eM22(0.0f), eM23(0.0f), eM31(0.0f), eM32(0.0f), eM33(0.0f) { } void Matrix::SetAsTranslate(float x, float y) { eM11 = 1.0f; eM12 = 0.0f; eM13 = 0.0f; eM21 = 0.0f; eM22 = 1.0f; eM23 = 0.0f; eM31 = x; eM32 = y; eM33 = 1.0f; } void Matrix::SetAsRotate(float radians) { eM11 = (float)cos(radians); eM12 = (float)sin(radians); eM13 = 0.0f; eM21 = (float)-sin(radians); eM22 = (float)cos(radians); eM23 = 0.0f; eM31 = 0.0f; eM32 = 0.0f; eM33 = 1.0f; } void Matrix::SetAsRotate(double degrees) { float radians = (float)(degrees/180 * M_PI); eM11 = (float)cos(radians); eM12 = (float)sin(radians); eM13 = 0.0f; eM21 = (float)-sin(radians); eM22 = (float)cos(radians); eM23 = 0.0f; eM31 = 0.0f; eM32 = 0.0f; eM33 = 1.0f; } void Matrix::SetAsScale(float x, float y) { eM11 = x; eM12 = 0.0f; eM13 = 0.0f; eM21 = 0.0f; eM22 = y; eM23 = 0.0f; eM31 = 0.0f; eM32 = 0.0f; eM33 = 1.0f; } Matrix operator*(const Matrix& ref1, const Matrix& ref2) { Matrix mat; mat.eM11 = ref1.eM11 * ref2.eM11 + ref1.eM12 * ref2.eM21 + ref1.eM13 * ref2.eM31; mat.eM12 = ref1.eM11 * ref2.eM12 + ref1.eM12 * ref2.eM22 + ref1.eM13 * ref2.eM32; mat.eM13 = ref1.eM11 * ref2.eM13 + ref1.eM12 * ref2.eM23 + ref1.eM13 * ref2.eM33; mat.eM21 = ref1.eM21 * ref2.eM11 + ref1.eM22 * ref2.eM21 + ref1.eM23 * ref2.eM31; mat.eM22 = ref1.eM21 * ref2.eM12 + ref1.eM22 * ref2.eM22 + ref1.eM23 * ref2.eM32; mat.eM23 = ref1.eM21 * ref2.eM13 + ref1.eM22 * ref2.eM23 + ref1.eM23 * ref2.eM33; mat.eM31 = ref1.eM31 * ref2.eM11 + ref1.eM32 * ref2.eM21 + ref1.eM33 * ref2.eM31; mat.eM32 = ref1.eM31 * ref2.eM12 + ref1.eM32 * ref2.eM22 + ref1.eM33 * ref2.eM32; mat.eM33 = ref1.eM31 * ref2.eM13 + ref1.eM32 * ref2.eM23 + ref1.eM33 * ref2.eM33; return mat; } void Matrix::SetAsWorld(HDC hDC, const Matrix& mat) { XFORM form; form.eM11 = mat.eM11; form.eM12 = mat.eM12; form.eM21 = mat.eM21; form.eM22 = mat.eM22; form.eDx = mat.eM31; form.eDy = mat.eM32; SetWorldTransform(hDC, &form); } The calculations I've written on paper first with help from a book. So I didn't copied anything from the internet. I'm getting the hang of matrices very fast with this book, next chapter is linear transformations! But indeed, I'm using GDI and it's getting pretty classic. But I really don't want to use a single external library. Because it's too "easy" then.. I'm not trying to be stubborn. Any suggestions how I avoid the classic functions? DirectX also must use a classic way or are they working very low level and code all their rendering themselves?
  3. EngineProgrammer

    3D algorithm

    I will gladly post my progress but it will take a while, today I realized I better learn matrices through 2D and when I understand everything I'll change to 3D. I'm making my own matrix class which will be supported with the function SetWorldTransform. This function works with XFORM but I'm not using this one. It's better to write my own calculations self so I can learn from it. When I got it all calculated I just put everything into an XFORM and transform the world. So when I understand the matrix and transform concept I go to 3D. Or is there a better way to transform my object(rectangle, bitmap, etc)? I know matrices needs to be used to transform such an object, but I mean, is there something else to transform my world with?
  4. EngineProgrammer

    Viewports

    When looking at 3D projections and transformations I was thinking on 3Dsmax, which has multiple viewports. So I've tried to get my own viewport with logical units -1 to 1. Now I wonder if I'm using a modern way of setting up a viewport. I have found these functions on msdn but I have no idea if these are still used nowadays. hDC = BeginPaint(hWnd, &ps); GetClientRect(hWnd, &client); SetMapMode(hDC, MM_ANISOTROPIC); SetViewportOrgEx(hDC, client.right/2, client.bottom/2, 0); SetViewportExtEx(hDC, client.right, client.bottom, 0); SetWindowOrgEx(hDC, 0, 0 ,0); SetWindowExtEx(hDC, 2, 2, 0); Rectangle(hDC, 0, 0, 1, 1); EndPaint(hWnd, &ps); This code sets up my window to 2 logical units, from -1 to 1. So like DirectX uses his viewport. And I've changed the viewport extends so when I scale the window, the objects in the window are scaled also.
  5. EngineProgrammer

    4D Arrays?

    4D "can" be visualized in 3D: http://en.wikipedia.org/wiki/Tesseract The fourth dimension can called whatever you like, some people say it's time, some people say it's space and some say it's an object in itself. Here is a nice link about how you project the 4D in 3D: http://steve.hollasc...s/chapter4.html Four-dimensional geometry: http://steve.hollasc...s/chapter2.html
  6. EngineProgrammer

    3D algorithm

    If you're not sure, you're definitely using a CPU You only "use" the GPU (at least the current generation) by programming little programs called shaders (in HLSL, or GLSL) which perform very specific tasks (e.g. transform vertices, or shade pixels). All the rest is done by the driver automatically. You don't actually write complete software on it. Everything that you code in C++ or C# or Java or whatever language, really, is done on your CPU. [/quote] Damn, I messed up my mind then. Thank you for clearing this out!
  7. EngineProgrammer

    3D algorithm

    Thanks everyone! Radikalizm, I'm not trying to make a commercial software renderer DirectX and OpenGL can't be beaten so I won't try to. It's all learning purpose. You say that I first need to work with the CPU, how do I do that? How can I choose which one I can use to get my project running? I know the difference between both tho, cpu only does 1 thing at the time while a gpu does multiple things at the same time. But no idea when I'm using a cpu or a gpu. DracoLacertae, thanks for the examples! So drawing lines isn't that hard to get in 3D Before I get on to it, I bought a math book which covers every mathematics what game programming concerns. So I hope to get a line or a 3D polygon on my screen today! uglybdavis, nicely done!
  8. EngineProgrammer

    3D algorithm

    I would like to write a small copy of DirectX. How do they handle the vertices and rendering of 3D models? How should it be handled for an optimal framework/engine? If my GPU can handle all the math, how can I render my 3D model with it? I still need to use some math from your first post or don't I? I'm looking up coordinate transformations and it's quite fun. And how about particles? Like when I have 1 million particles. How should I best handle them? Do I need to do all calculations and rendering on the GPU? Or are there better/faster ways? You are helping me already but I'm still a bit confused about how it all works with the gpu / cpu thing. I want to get an optimal render system for low poly models with materials, shaders, lightning, bouncings, etc. I know the pipeline for the graphics rendering but I can't go any further than the first step at the moment. For example I want to be able to load a whole environment like COD with all players, bullets, effects in it. Kind regards, Jonathan
  9. Your intensity of the bounced lights is on 100%? Way too much even for metal. Try to make it changeable. Have watched some video's and I must say, really good work! Keep it up!
  10. EngineProgrammer

    3D algorithm

    I'm looking up some information what GDI exactly is and this is a quote from wikipedia. Simple games that do not require fast graphics rendering use GDI. However, GDI is relatively hard to use for advanced animation, and lacks a notion for synchronizing with individual video frames in the video card, lacks hardware rasterization for 3D, etc. Modern games usually use DirectX or OpenGL instead, which let programmers exploit the features of modern hardware.[/quote] What makes DirectX a fast graphics renderer? How you decide the speed of rendering? I just want to get low-level what programming concerns. I really want to get the knowledge into my head how it's done. GDI only limited to 2D, how do I get the 3D in my program then? I'm assuming I need to calculate every pixel and draw them manually, please correct me if I'm wrong. I want to achieve real-time rendering. Dragging a 3D model into your window and be able to translate, scale and rotate in your project. But that is not for now, first the baby steps. But I can't do this alone sadly enough. Need some help from people who have experience in this because I can't find almost anything that helps me. maybe I'm not looking in the right place. Kind regards, Jonathan
  11. EngineProgrammer

    3D algorithm

    A billion percent thank you! In Win32 there are some standard functions for example: SetWorldTransform, SetGrapicsMode, etc. and structs like XFORM. Should I make any use of those functions and structs or should I rather make my own ones? Kind regards, Jonathan
  12. EngineProgrammer

    OpenGL 3D algorithm

    Hey everyone, has been a while I've programmed but I'm back. I know that re-writing existing code is useless. But I don't mind to re-write some code, I want to learn how it's done. I want to make a 3D polygon and draw it in C++, without using DirectX or OpenGL. I've been looking around after source codes or tutorials but haven't found a single tutorial that helps me. Very simple example of what I want to do: m_Polygon = new Polygon(vertex1, vertex2, vertex3, vertex4); // where the vertexes have a X,Y,Z m_Polygon->Draw(); So I want to draw the 3D polygon in my 2D screen. Can someone help me with this. Thank you and kind regards, Jonathan
  13. EngineProgrammer

    Creotex Engine ~ Introduction

    Thanks! Ah didn't see that. Changed them with using 'link' and they are all good now. ~EngineProgrammer
  14. EngineProgrammer

    Creotex Engine ~ Part 2

    Hello ladies and gentlemen, Welcome to my journal! If some of you guys are following me to create your own game engine, you should have a window by now so let's continue. And if you are just watching what I'm coding, next I'll put all DirectX stuff into my engine. It was hard to find to get, an almost full, initialization of DirectX but I've some decent pieces of code which I have put into my code. bool Graphics::Initialize(Window* pWindow) { HRESULT result; IDXGIFactory* pFactory = nullptr; IDXGIAdapter* pAdapter = nullptr; IDXGIOutput* pAdapterOutput = nullptr; DXGI_MODE_DESC* pDisplayModeList = nullptr; DXGI_ADAPTER_DESC adapterDesc; D3D_FEATURE_LEVEL featureLevel; D3D11_TEXTURE2D_DESC depthBufferDesc; D3D11_DEPTH_STENCIL_DESC depthStencilDesc; D3D11_DEPTH_STENCIL_DESC depthDisableStencilDesc; D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc; D3D11_RASTERIZER_DESC rasterDesc; D3D11_BLEND_DESC blendStateDescription; unsigned int numModes = 0, numerator = 0, denominator = 0; float fieldOfView = 0.0f, screenAspect = 0.0f; // Store the pointer of the window m_pWindow = pWindow; // Create a DirectX graphics interface factory result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&pFactory); if(FAILED(result)) { return ErrorMessage(_T("Graphics"), _T("Initialize"), _T("CreateDXGIFactory")); } // Use the factory to create an adapter for the primary graphics interface ( video card ) result = pFactory->EnumAdapters(0, &pAdapter); if(FAILED(result)) { return ErrorMessage(_T("Graphics"), _T("Initialize"), _T("Set EnumAdapters factory")); } // Enumerate the primary adapted output ( monitor ) result = pAdapter->EnumOutputs(0, &pAdapterOutput); if(FAILED(result)) { return ErrorMessage(_T("Graphics"), _T("Initialize"), _T("Set EnumOutputs adapter")); } // Get the numbder of modes that fit in the display the the adapter output ( monitor ) result = pAdapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, NULL); if(FAILED(result)) { return ErrorMessage(_T("Graphics"), _T("Initialize"), _T("Set GetDisplayModeList adapter")); } // Create list to hold all possible display modes for this monitor/video card combinatior pDisplayModeList = new DXGI_MODE_DESC[numModes]; if(!pDisplayModeList) { return ErrorMessage(_T("Graphics"), _T("Initialize"), _T("creating DisplayModeList")); } // Now fill the fisplay mode list structures result = pAdapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, pDisplayModeList); if(FAILED(result)) { return ErrorMessage(_T("Graphics"), _T("Initialize"), _T("GetDisplayModeList adapter")); } // Now go through all the display modes and find the one that mathces the screen width and height // When a match is found store the numerator and denominator of the refresh rate for that monitor for(int i=0; iGetWindowWidth()) { if(pDisplayModeList.Height == (unsigned int)m_pWindow->GetWindowHeight()) { numerator = pDisplayModeList.RefreshRate.Numerator; denominator = pDisplayModeList.RefreshRate.Denominator; } } } // Get the adapter ( video card ) description result = pAdapter->GetDesc(&adapterDesc); if(FAILED(result)) { return ErrorMessage(_T("Graphics"), _T("Initialize"), _T("GetDesc adapter")); } // Store the dedicated video card memory in megabytes m_VideoCardMemory = (int)(adapterDesc.DedicatedSystemMemory/1024/1024); // Store the video card name m_VideoCardDescription = adapterDesc.Description; // Release the display list, adapter output, adapter, factory SafeDeleteArray(pDisplayModeList); SafeRelease(pAdapterOutput); SafeRelease(pAdapter); SafeRelease(pFactory); // Create a struct to hold information about the swap chain DXGI_SWAP_CHAIN_DESC swapChainDesc; // Clear out the struct for use ZeroMemory(&swapChainDesc, sizeof(swapChainDesc)); // Fill the swap chain description struct swapChainDesc.BufferCount = 1; // 1 Back buffer swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // Use 32-bit color swapChainDesc.BufferDesc.Width = m_pWindow->GetWindowWidth(); // Set the back buffer width swapChainDesc.BufferDesc.Height = m_pWindow->GetWindowHeight(); // Set the back buffer height if(m_pWindow->GetVSync()) { swapChainDesc.BufferDesc.RefreshRate.Numerator = numerator; swapChainDesc.BufferDesc.RefreshRate.Denominator = denominator; } else { swapChainDesc.BufferDesc.RefreshRate.Numerator = 0; swapChainDesc.BufferDesc.RefreshRate.Denominator = 1; } swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; // How the chain is to be used swapChainDesc.OutputWindow = m_pWindow->GetHandleToWindow(); // The window to be used // Turn multisampling off swapChainDesc.SampleDesc.Count = 1; // How many multisamples swapChainDesc.SampleDesc.Quality = 0; swapChainDesc.Windowed = !m_pWindow->GetFullscreen(); // Windowed/Fullscreen mode swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; swapChainDesc.Flags = 0; // Set the feature level to DirectX 11 featureLevel = D3D_FEATURE_LEVEL_11_0; // Create a device, device context and swap chain using the information in the swapChainDesc struct D3D11CreateDeviceAndSwapChain( NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &featureLevel, 1, D3D11_SDK_VERSION, &swapChainDesc, &m_pSwapChain, &m_pDevice, NULL, &m_pDeviceContext ); // Get the adress of the back buffer ID3D11Texture2D* pBackBuffer; m_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer); // Use the back buffer address to create the render target m_pDevice->CreateRenderTargetView(pBackBuffer, NULL, &m_pRenderTargetView); // Set the render target as the back buffer m_pDeviceContext->OMSetRenderTargets(1, &m_pBackBuffer, NULL); // Release back buffer pBackBuffer->Release(); // Initialize the description of the depth buffer ZeroMemory( &depthBufferDesc, sizeof(depthBufferDesc) ); // Set up the description of the depth buffer depthBufferDesc.Width = m_pWindow->GetWindowWidth(); depthBufferDesc.Height = m_pWindow->GetWindowHeight(); depthBufferDesc.MipLevels = 1; depthBufferDesc.ArraySize = 1; depthBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; depthBufferDesc.SampleDesc.Count = 1; depthBufferDesc.SampleDesc.Quality = 0; depthBufferDesc.Usage = D3D11_USAGE_DEFAULT; depthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; depthBufferDesc.CPUAccessFlags = 0; depthBufferDesc.MiscFlags = 0; // create the texture for the depth buffer using the filled out description result = m_pDevice->CreateTexture2D(&depthBufferDesc, NULL, &m_pDepthStencilBuffer); if(FAILED(result)) { return ErrorMessage(_T("Graphics"), _T("Initialize"), _T("CreateTexture2D depthBufferDesc")); } // Initialize the description of the stencil state ZeroMemory(&depthStencilDesc, sizeof(depthStencilDesc)); // Set up the description of the stencil state depthStencilDesc.DepthEnable = true; depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS; depthStencilDesc.StencilEnable = true; depthStencilDesc.StencilReadMask = 0xFF; depthStencilDesc.StencilWriteMask = 0xFF; depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR; depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR; depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS; // Create the depth stencil state result = m_pDevice->CreateDepthStencilState(&depthStencilDesc, &m_pDepthStencilState); if(FAILED(result)) { return ErrorMessage(_T("Graphics"), _T("Initialize"), _T("CreateDepthStencilState depthStencilDesc")); } // Set the depth stencil state m_pDeviceContext->OMSetDepthStencilState(m_pDepthStencilState, 1); // Initialize the depth stencil view ZeroMemory(&depthStencilViewDesc, sizeof(depthStencilViewDesc)); depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; depthStencilViewDesc.Texture2D.MipSlice = 0; // Create the depth stencil view result = m_pDevice->CreateDepthStencilView(m_pDepthStencilBuffer, &depthStencilViewDesc, &m_pDepthStencilView); if(FAILED(result)) { return ErrorMessage(_T("Graphics"), _T("Initialize"), _T("CreateDepthStencilView m_pDepthStencilBuffer")); } // Bind the render target view and depth stencil buffer to the output render pipeline m_pDeviceContext->OMSetRenderTargets(1, &m_pRenderTargetView, m_pDepthStencilView); // 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; result = m_pDevice->CreateRasterizerState(&rasterDesc, &m_pRasterState); if(FAILED(result)) { return ErrorMessage(_T("Graphics"), _T("Initialize"), _T("CreateRasterizerState rasterDesc")); } // Now set the rasterizer state m_pDeviceContext->RSSetState(m_pRasterState); // Set the viewport for rendering D3D11_VIEWPORT viewPort; ZeroMemory(&viewPort, sizeof(D3D11_VIEWPORT)); viewPort.MinDepth = 0.0f; viewPort.MaxDepth = 1.0f; viewPort.TopLeftX = 0; viewPort.TopLeftY = 0; viewPort.Width = (float)m_pWindow->GetWindowWidth(); viewPort.Height = (float)m_pWindow->GetWindowHeight(); m_pDeviceContext->RSSetViewports(1, &viewPort); // Setup Projection matrix fieldOfView = (float)D3DX_PI/4.0f; screenAspect = (float)m_pWindow->GetWindowWidth()/(float)m_pWindow->GetWindowHeight(); // Create the projection matrix for 3D rendering D3DXMatrixPerspectiveFovLH(&m_ProjectionMatrix, fieldOfView, screenAspect, SCREEN_NEAR, SCREEN_DEPTH); // Initialize the world matrix to identity matrix D3DXMatrixIdentity(&m_WorldMatrix); // Create an orthographic projection matrix for 2D rendering D3DXMatrixOrthoLH(&m_OrthoMatrix, (float)m_pWindow->GetWindowWidth(), (float)m_pWindow->GetWindowHeight(), SCREEN_NEAR, SCREEN_DEPTH); // Clear the memory ZeroMemory(&depthDisableStencilDesc, sizeof(depthDisableStencilDesc)); // Set up the description of the stencil state depthDisableStencilDesc.DepthEnable = false; depthDisableStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; depthDisableStencilDesc.DepthFunc = D3D11_COMPARISON_LESS; depthDisableStencilDesc.StencilEnable = true; depthDisableStencilDesc.StencilReadMask = 0xFF; depthDisableStencilDesc.StencilWriteMask = 0xFF; depthDisableStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; depthDisableStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR; depthDisableStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; depthDisableStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; depthDisableStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; depthDisableStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR; depthDisableStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; depthDisableStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS; // Create the depth stencil state result = m_pDevice->CreateDepthStencilState(&depthDisableStencilDesc, &m_pDepthDisableStencilState); if(FAILED(result)) { return ErrorMessage(_T("Graphics"), _T("Initialize"), _T("CreateDepthStencilState depthDisableStencilDesc")); } ZeroMemory(&blendStateDescription, sizeof(D3D11_BLEND_DESC)); blendStateDescription.RenderTarget[0].BlendEnable = TRUE; blendStateDescription.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE; blendStateDescription.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; blendStateDescription.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; blendStateDescription.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; blendStateDescription.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; blendStateDescription.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; blendStateDescription.RenderTarget[0].RenderTargetWriteMask = 0x0f; result = m_pDevice->CreateBlendState(&blendStateDescription, &m_AlphaEnableBlendingState); if(FAILED(result)) { return ErrorMessage(_T("Graphics"), _T("Initialize"), _T("CreateBlendState blendStateDescription")); } blendStateDescription.RenderTarget[0].BlendEnable = FALSE; result = m_pDevice->CreateBlendState(&blendStateDescription, &m_AlphaDisableBlendingState); if(FAILED(result)) { return ErrorMessage(_T("Graphics"), _T("Initialize"), _T("CreateBlendState blendStateDescription")); } return true; } As I've said in the previous entry my Application creates the core(window, system, graphics), so you should be able to initialize these graphics all by yourself. ;) But when you have all initialization ready don't run it yet! don't fly when you can't walk. Else you would forget that you also need to deallocate what you have allocated! ;) void Graphics::Shutdown() { if(m_pSwapChain != nullptr) { m_pSwapChain->SetFullscreenState(false, NULL); } SafeRelease(m_AlphaDisableBlendingState); SafeRelease(m_AlphaEnableBlendingState); SafeRelease(m_pDepthDisableStencilState); SafeRelease(m_pDepthStencilBuffer); SafeRelease(m_pDepthStencilState); SafeRelease(m_pRenderTargetView); SafeRelease(m_pRasterState); SafeRelease(m_pBackBuffer); SafeRelease(m_pDeviceContext); SafeRelease(m_pDevice); SafeRelease(m_pSwapChain); } SafeRelease is a template, I love clear readable code!: template inline void SafeRelease(T &pObject) { if(pObject != nullptr){ pObject->Release(); pObject = nullptr; } } This took a very long time to get and understand all that code. I think I've deserved a break! ^^ By the way my window class you saw last entry is buggy. In case you didn't read the reply there: I was casting the HWND to my Window* so I could call the method 'HandleEvents(...) in the WndProc function. But as soon I changed a data member in the HandleEvents method the application wouldn't start anymore. So needed to change this and this is what I've made: if(msg == WM_CREATE) { SetWindowLong(hWnd, GWL_USERDATA, (LONG)((LPCREATESTRUCT)lParam)->lpCreateParams); } else { Window* pWindow = (Window*)GetWindowLong(hWnd, GWL_USERDATA); if(pWindow) { return pWindow->HandleEvents(hWnd, msg, wParam, lParam); } } return DefWindowProc(hWnd, msg, wParam, lParam); So that was it for the graphics class. I hope you guys enjoy the code! If you want to see more follow my blog to keep in touch. And following this blog also means people are interested in these codes. So next entry will be my system class. But that won't be for today! First I'm going to enjoy my break ^^ So thank you ladies and gentlemen and see you in the next entry!
  15. EngineProgrammer

    Creotex Engine ~ Part 1

    MajorTom, thanks and I'm glad you are looking forward to my future posts! About the function you are right indeed,I've tried to modify a data member of the class inside the HandleEvents method and my window didn't want to launch. Thanks for the answer! ~EngineProgrammer
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!