DirectX Detailed Tutorial?

Pages: 12
Jun 11, 2012 at 5:11am
closed account (LAfSLyTq)
i cant seem to find a detailed DirectX Game Programming tutorial... i am a person that does not know how to install the SDK nor do i know where to place it or anything. i know plenty about C++ i made some game hacks at http://youtube.com/tripdaripper but i want to make my own video game for my fellow youtubers to enjoy and stuff. help?
Jun 11, 2012 at 12:30pm
Well, I think most have started migrating from DirectX directly to using XNA to make games. XNA has DX under the hood, but XNA API is way simpler to understand than the DX API.
Jun 11, 2012 at 2:41pm
closed account (o1vk4iN6)
What statistics do you have to prove this ? Just cause it has more features doesn't mean more people use it. They are for two different things, if you want everything done for you there is XNA, it is by no means a replacement for directx. It has model loading animations everything you could need to make a game but if you want to add a feature that isn't already there you'll have to end up remaking everything anyways. If you just want to make a game there's UDK and other solutions, if you want to learn how games are programmed, XNA isn't the way to go, it's just a cheap version of something like UDK.


e:

ammo hacks are the easiest to do, i don't get why people make videos about it. As well theres a console which turns on infinite ammo and such for some games anyways.
Last edited on Jun 11, 2012 at 2:48pm
Jun 11, 2012 at 3:21pm
Well if you are wanting to make games that have the possibility of being published on more than one system then XNA is the only option you have (for Microsoft) as you can make games and then buy the license and publish them on Windows (can do this freely without license) and use the license to attempt to get them published on 360 and the Windows Phone. DX locks you into Windows only, UDK has a lot of bugs depending on hardware (as my old graphics card wouldn't show the textures right in front of you so you only saw a grey wall and wouldn't display the AI bots so you were getting killed by nothing). It's my understanding that XNA has DX under the hood, but is designed so you aren't dealing with it directly.

Then you have Allegro, SDL, SFML, and other libraries that you can use from open source that are cross platform (but that only gives you Windows, Linux, Mac, and maybe Android, and iOS. If you want a larger publishing base XNA, SDL, Allegro, and SFML are better choices than DX.

Also, it is obvious a lot of people are using XNA when looking at the indie marketplace on 360 and the site where you can see what games are being developed for which system and buy them if you like. His choice depends on how large a base he wants for when he decides to publish a game (if he does). If he wants to just release on Windows then DX is the best to use, but if he wants to release on a larger base he needs to chose something.

XNA can't be that bad, the creator of Allegro is on the XNA team ;).
Last edited on Jun 11, 2012 at 3:33pm by closed account z6A9GNh0
Jun 11, 2012 at 4:30pm
http://directxtutorial.com/

This is what I used when I was dabbling in DirectX. The first few sections are free, but sadly you have to pay a one time fee for the rest. It is well worth it though, just make sure you have a strong math background.
Jun 11, 2012 at 5:24pm
@BHXSpecter
Isn't XNA for managed code only?
Jun 11, 2012 at 6:08pm
closed account (o1vk4iN6)
Indeed directx is limited to only windows, you'd be better off learning opengl (I preference it over directx anyways) allowing you to create programs on linux, windows, mac os x, android, iOS, etc... It also has nice integration with Qt for creating editing tools. Microsoft is really running directx into the ground and window 8 along with it, a bit sad to see (anyone remember the zune?).
Jun 11, 2012 at 6:16pm
Knowing Microsoft, probably. I know Shawn Hargreaves told me this
XNA is a .NET API, so you can use any .NET languages supported by whichever platform you are on


Never used XNA outside C#, for C++ I play with Allegro/SFML/SDL.

I try to avoid tools like UDK or Torque Engine and its tools. I also avoid DirectX due to its over complexity.
Jun 12, 2012 at 12:11am
closed account (o1vk4iN6)
Well what's the point if you aren't going down in the dirt with directx, it's just a graphics library, it isn't meant to write one line of code and you have a game. Which is why i said you might as well be use UDK which provides a UI to do all the easy stuff you'd be doing in code anyways. Writing your own data structures, picking which algorithms to use and making your own decisions is what I find fun about it. If you just want to make a game cause you had an idea, well what's the point of half ass-ing it by using something like XNA.
Jun 12, 2012 at 2:15am
Well some of the guys I've talked to when I seek advice in the industry have said to use tools like UDK and get a few games running before diving into the dark underbelly of the code. Using UDK/XNA/Torque/etc will help you get an understanding of how a game is put together so you are prepared to make a game from scratch in C/C++/C# and the libraries of your choice.

[EDIT]
It is far easier to learn how games go together by making simple games with Torque/XNA/Unity/UDK than it is having to learn how games go together on top of learning such a complex API like DX.
Last edited on Jun 12, 2012 at 2:49am by closed account z6A9GNh0
Jun 12, 2012 at 3:17pm
closed account (o1vk4iN6)
There is nothing complex about the API, if anything someone who doesn't know linear algebra will have difficulty using it which has nothing to do with the API itself but a poor understanding of the fundamental math that is required when dealing with 3D.
Jun 13, 2012 at 7:57pm
closed account (LAfSLyTq)
i just wanted to know how to make a simple game like mario
Jun 13, 2012 at 10:17pm
Nope, nothing complex about learning Win32 API and Direct X API compared to other APIs that hide it under the hood. These just create the blank window for the game to be drawn in.
Direct 3D Window:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// include the basic windows header files and the Direct3D header files
#include <windows.h>
#include <windowsx.h>
#include <d3d11.h>
#include <d3dx11.h>
#include <d3dx10.h>

// include the Direct3D Library file
#pragma comment (lib, "d3d11.lib")
#pragma comment (lib, "d3dx11.lib")
#pragma comment (lib, "d3dx10.lib")

// global declarations
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

// function prototypes
void InitD3D(HWND hWnd);    // sets up and initializes Direct3D
void CleanD3D(void);        // closes Direct3D and releases memory

// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);


// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    HWND hWnd;
    WNDCLASSEX wc;

    ZeroMemory(&wc, sizeof(WNDCLASSEX));

    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.lpszClassName = L"WindowClass";

    RegisterClassEx(&wc);

    RECT wr = {0, 0, 800, 600};
    AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);

    hWnd = CreateWindowEx(NULL,
                          L"WindowClass",
                          L"Our First Direct3D Program",
                          WS_OVERLAPPEDWINDOW,
                          300,
                          300,
                          wr.right - wr.left,
                          wr.bottom - wr.top,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

    ShowWindow(hWnd, nCmdShow);

    // set up and initialize Direct3D
    InitD3D(hWnd);

    // enter the main loop:

    MSG msg;

    while(TRUE)
    {
        if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);

            if(msg.message == WM_QUIT)
                break;
        }
        else
        {
            // Run game code here
            // ...
            // ...
        }
    }

    // clean up DirectX and COM
    CleanD3D();

    return msg.wParam;
}


// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
        case WM_DESTROY:
            {
                PostQuitMessage(0);
                return 0;
            } break;
    }

    return DefWindowProc (hWnd, message, wParam, lParam);
}


// this function initializes and prepares Direct3D for use
void InitD3D(HWND hWnd)
{
    // create a struct to hold information about the swap chain
    DXGI_SWAP_CHAIN_DESC scd;

    // clear out the struct for use
    ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));

    // fill the swap chain description struct
    scd.BufferCount = 1;                                    // one back buffer
    scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;     // use 32-bit color
    scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;      // how swap chain is to be used
    scd.OutputWindow = hWnd;                                // the window to be used
    scd.SampleDesc.Count = 4;                               // how many multisamples
    scd.Windowed = TRUE;                                    // windowed/full-screen mode

    // create a device, device context and swap chain using the information in the scd struct
    D3D11CreateDeviceAndSwapChain(NULL,
                                  D3D_DRIVER_TYPE_HARDWARE,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  D3D11_SDK_VERSION,
                                  &scd,
                                  &swapchain,
                                  &dev,
                                  NULL,
                                  &devcon);
}


// this is the function that cleans up Direct3D and COM
void CleanD3D(void)
{
    // close and release all existing COM objects
    swapchain->Release();
    dev->Release();
    devcon->Release();
} 

SDL Window
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "SDL/SDL.h"

int main(int argc, char* args[])
{
	// Start SDL
	SDL_Init(SDL_INIT_VIDEO);
	SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
	SDL_Delay(6000);
	// Quit SDL
	SDL_Quit();
	
	return 0;
}

SFML Window
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <SFML/Window.hpp>
int main()
{
    // Create the main window
    sf::Window App(sf::VideoMode(800, 600, 32), "SFML Window");

    // Start main loop
    bool Running = true;
    while (Running)
    {
        App.Display();
    }

    return EXIT_SUCCESS;
}

Allegro Window
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
#include <allegro5/allegro.h>
 
int main(int argc, char **argv){
 
   ALLEGRO_DISPLAY *display = NULL;
 
   if(!al_init()) {
      fprintf(stderr, "failed to initialize allegro!\n");
      return -1;
   }
 
   display = al_create_display(640, 480);
   if(!display) {
      fprintf(stderr, "failed to create display!\n");
      return -1;
   }
 
   al_clear_to_color(al_map_rgb(0,0,0));
 
   al_flip_display();
 
   al_rest(10.0);
 
   al_destroy_display(display);
 
   return 0;
}

XNA Window (slightly smaller than DX/Win32API)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsGame1
{    
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }
       
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
        }

       
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
        }
       
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
               protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here

            base.Update(gameTime);
        }

        /// This is called when the game should draw itself.
               protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
    }
}
Last edited on Jun 13, 2012 at 11:08pm by closed account z6A9GNh0
Jun 14, 2012 at 1:34am
closed account (o1vk4iN6)
Is that suppose to be sarcastic ... win32 AND directx ? In your directx/win32 example, directx is only one line of code. You also didn't show any of the other API's setting any configurations for the directx device as if you expect everyone will simply only have the need for default settings. Most people simply use it cause they don't know what the settings do and it's "easier" to have them set for them, until they run into problems.

Win32 API is complex I agree, but you don't need to use it with directx, the two have no correlation with each other. You can use WTL, Qt or any other UI wrapper API to create a window in fewer lines (and with more control than XNA, SDL, allergo, etc...) as opposed to using Win32. I don't really get what you are trying to say other than yes Microsoft needs to update their UI API and metro isn't the answer.
Jun 14, 2012 at 1:52am
closed account (1yR4jE8b)
XNA is deprecated, it's being dumped in favor of HTML5/Javascript and Metro in Windows 8. I've also been teaching myself how to use the new C++ DirectX APIs for Metro and it's been fairly straightforward and fun.

If you want something similar to XNA, but not tied down to Microsoft check out libgdx for Java or if you want to stick with C++ you've got SFML 2.0, Allegro, and Panda 3d.

Don't even bother learning Win32, with Windows 8 Microsoft is shipping an entirely new OS API called WinRT (Windows RunTime). It's easier, faster, and just better overall. It's the future of Windows development.

If you want to do any kind of *serious* Windows development, do yourself a favor and make a dual-boot with the Windows 8 RC and Visual Studio 2012 RC, learn the new APIs and get a head start making applications for Metro. Microsoft won't be supporting the legacy stuff that much longer. Or you could like me and switch over completely: I'm running solely Windows 8 on my desktop, laptop and Windows Server 2012 on my home server box. Bleeding edge, baby.
Last edited on Jun 14, 2012 at 1:53am
Jun 14, 2012 at 2:02am
Win32 API is complex I agree, but you don't need to use it with directx, the two have no correlation with each other.


That is news to me as I've never seen a DX tutorial that didn't use Win32 API. That example code was pulled straight from the DX 11 tutorial from directxtutorial.com that was linked above. DX is overkill for a mario like game. Not to mention DX and XNA lock your games into Microsoft only platforms (assuming you want to pay the $100 to get the publishing license and jump through Microsoft's hoops to get it published). While SDL/SFML/Allegro all let you program your game and focus on it then easily port it between Windows/Mac/Linux/iOS/Android and whatever other OSes they support.

It is also my understanding that DX is slowly being phased out as is XNA in favor of Metro and the industry seems to be using OpenGL more now than DX.
Jun 14, 2012 at 3:39pm
closed account (o1vk4iN6)
Lol, there's more to programming than just following tutorials you find on the internet.
Jun 14, 2012 at 4:48pm
DX kinda uses WinAPI, but they are still separate entities.
Jun 14, 2012 at 10:46pm
Lol, there's more to programming than just following tutorials you find on the internet.

Problem is that the only way to learn DirectX is tutorials, books, and the included examples. All of which use Win32API for making the window and none that I have read say anything about using another GUI API to make the window using DirectX. Though, some GUI libraries may cause issues and make the DirectX part disappear if you aren't careful (even Win32API can do this as I've had a few demos lose focus and display just a grey or blank screen if you change program focus).
Jun 15, 2012 at 3:44am
closed account (o1vk4iN6)
Like I said, if all you do is follow tutorials and don't take anything from them other than copying and pasting, you wouldn't be able to connect the lines yourself. If someone didn't tell you to breathe would you not know how to ? If everyone just expects all the possibilities to be spoon fed to them in tutorials than programming would be pretty dull.
Last edited on Jun 15, 2012 at 3:46am
Pages: 12