Thread: Starting out with DirectX

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005

    Starting out with DirectX

    So, my simple (not actually simple) goal is to create a junky pong game. I'm not really interested in a third dimension (3d) yet, but I was questioning whether or not to bother with ortho view or not. Can't I just set my Z axis to 0 at all times for all my objects? Viola, effectively 2d yes?

    I've followed some basic tutorials on DirectX at, and I've come up with a basic Renderer class that manages the 3d stuff.

    #ifndef RENDERER_H
    #define RENDERER_H
    #include <d3d11.h>
    #include <d3dx11.h>
    #include <d3dx10.h>
    #include "Vertex.h"
    // include the Direct3D Library file
    #pragma comment (lib, "d3d11.lib")
    #pragma comment (lib, "d3dx11.lib")
    #pragma comment (lib, "d3dx10.lib")
    // define the screen resolution
    #define SCREEN_WIDTH  1920
    #define SCREEN_HEIGHT 1080
    class Renderer
    	Renderer(HWND hWnd);
    	// function prototypes
    	void Update();
    	IDXGISwapChain * swapchain;             // the pointer to the swap chain interface
    	ID3D11Device *dev;                     // the pointer to our Direct3D device interface
    	ID3D11DeviceContext *devcon;           // the pointer to our Direct3D device context
    	ID3D11RenderTargetView *backbuffer;    // the pointer to our Direct3D backbuffer
    	ID3D11VertexShader *pVS;    // the vertex shader
    	ID3D11PixelShader *pPS;     // the pixel shader
    	ID3D11Buffer *pVBuffer;    // the vertex buffer
    	ID3D11InputLayout *pLayout;    // the input layout
    	void InitD3D(HWND hWnd);    // sets up and initializes Direct3D
    	void InitPipeline(void);
    	void InitGraphics(void);
    So, some questions on Ortho/2d... First off, I think the only reason I am tempted to do 2d in a 3d environment is because I already have a 3d environment set up via tutorials, and I don't have a 2d environment set up, and I'm really not sure how do go about doing that.

    I saw a tutorial here:

    But honestly, before I get too deep into that, I wanted to ask you all if...

    1. Is there a better tutorial out there?
    2. Is there something a little more basic, I mean, to help me understand what the heck ortho is in relation to the following things:
    A. vertex buffer
    B. Pixel Buffer
    C. Device Context
    D. Rendering Pipeline
    E. Other graphics lingo I'm not super familiar with

    What I'm really asking, is does all the ortho setup happen here or, in my other initialization steps?

    void Renderer::Update(void)
    	// clear the back buffer to a deep blue
    	devcon->ClearRenderTargetView(backbuffer, D3DXCOLOR(0.0f, 0.2f, 0.4f, 1.0f));
    	// select which vertex buffer to display
    	UINT stride = sizeof(Vertex);
    	UINT offset = 0;
    	devcon->IASetVertexBuffers(0, 1, &pVBuffer, &stride, &offset);
    	// select which primtive type we are using
    	// draw the vertex buffer to the back buffer
    	devcon->Draw(3, 0);
    	// switch the back buffer and the front buffer
    	swapchain->Present(0, 0);
    Thanks, feel free to educate me .
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  2. #2
    Absent Minded Programmer
    Join Date
    May 2005
    Okay, so, working through this tutorial, hoping someone here can give me a better understanding of what code I'm ripping from the tutorial and mashing into my own setup..

    First thing I added was these:

    	ID3D11DepthStencilState *m_depthDisabledStencilState;
    	D3D11_DEPTH_STENCIL_DESC depthDisabledStencilDesc;
    	D3DXMATRIX m_orthoMatrix;
    So, here we have a Depth Stencil State, and a Depth Stencil Description, and a Matrix for our orthographic view, I'd love a little more robust understanding of items 1 and 2...

    Moving on, I am doing a little bit more in my InitD3D function:

    	//Set up Ortho Stuff
    	D3DXMatrixOrthoLH(&m_orthoMatrix, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 1);
    	ZeroMemory(&depthDisabledStencilDesc, sizeof(depthDisabledStencilDesc));
    	// Create Depth Stencil State with No Z Axis (Depth = FALSE)
    	depthDisabledStencilDesc.DepthEnable = false;
    	depthDisabledStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
    	depthDisabledStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
    	depthDisabledStencilDesc.StencilEnable = true;
    	depthDisabledStencilDesc.StencilReadMask = 0xFF;
    	depthDisabledStencilDesc.StencilWriteMask = 0xFF;
    	depthDisabledStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
    	depthDisabledStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
    	depthDisabledStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
    	depthDisabledStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
    	depthDisabledStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
    	depthDisabledStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
    	depthDisabledStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
    	depthDisabledStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
    	// craete the depth stencil state
    	dev->CreateDepthStencilState(&depthDisabledStencilDesc, &m_depthDisabledStencilState);
    	// set the depth stencil state
    	devcon->OMSetDepthStencilState(m_depthDisabledStencilState, 1);
    So here, I see we initialize our ortho matrix, setting up our depth stencil description, and then creating COM objects for our depth stencil state, and finally, setting the depth stencil state...

    So far so good right?

    Next we have....

    Wait a minute, not sure what's next yet .
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Starting up a pc
    By Pana in forum C Programming
    Replies: 1
    Last Post: 01-14-2014, 02:20 PM
  2. Starting DirectX in .Net 2033
    By Kaminaga in forum Game Programming
    Replies: 5
    Last Post: 10-06-2005, 10:58 AM
  3. DirectX - Starting Guide?
    By Zeusbwr in forum Game Programming
    Replies: 13
    Last Post: 11-25-2004, 12:49 AM
  4. DirectX 8: Creating the DirectX Object
    By Toraton in forum Game Programming
    Replies: 3
    Last Post: 11-28-2002, 03:45 AM
  5. just starting
    By Moffesto in forum C++ Programming
    Replies: 8
    Last Post: 06-19-2002, 03:15 PM

Tags for this Thread