GithubHelp home page GithubHelp logo

kevinmoran / beginnerdirect3d11 Goto Github PK

View Code? Open in Web Editor NEW
186.0 8.0 32.0 227 KB

Starter code samples for Direct3D11

License: The Unlicense

Batchfile 0.61% C++ 15.70% HLSL 0.57% C 83.12%
3d-graphics direct3d direct3d11 directx directx-11 game-development gamedev graphics graphics-programming graphics-rendering

beginnerdirect3d11's Introduction

Beginner Direct3D11 Programming

This is my starter code for Direct3D11 graphics programming on Windows in a simple, procedural (C-like) style.

No external dependencies, uses stb_image for loading textures and minimal CRT features.

Released into the public domain under the Unlicense, see LICENSE.txt. No warranty is implied.

Code style and ethos

This repository is provided as the resource I wish I had for learning Direct3D11. While tutorials and other samples exist, they are often overcomplicated for simply illustrating basic usage of the API to a beginner. In particular I've seen the simplest code for drawing a triangle split up into several classes and files which make the code flow very hard to follow.

My goal is to provide a straightforward, linear series of API calls that you can follow along with; everything is written in a procedural (C-like) style rather than abstracting code away into container classes. It is a simplified starting point to get you started instead of production-ready code.

Additionally I have split this repo into smaller sub-projects that gradually introduce new concepts important for realtime graphics and game programming. Hopefully this makes approaching these topics a bit easier.

This is not intended to be a tutorial. If you are using this as a learning resource you will have to look up the documentation for the Win32 and Direct3D structs/functions being used to get a good understanding of what is being done and why. I think it's much more valuable to provide working code as a reference that you can explore and play around with rather than writing pages explaining what each line of code does.

To any beginners reading this: Learning a 3D graphics API is tricky. You invariably have to learn 10 new concepts at once at all times. Rather than learning from the bottom up (i.e. understanding every line of code before moving on) I advise you to try and get the general idea for most things as you go, play around and slowly build up your knowledge. You will probably feel a bit overwhelmed at times, but with patience and persistence you will eventually have 'Eureka' moments where things click into place. If you have any questions I'll be happy to answer them.

To any non-beginners reading this: If you notice any mistakes/areas for improvement please let me know.

Building the source code

Compilation for each sub-project is handled using a simple batch file called build.bat, you can also use the provided Visual Studio 2019 solution.

For using the solution or batch files, you will have to install Visual Studio to use the MSVC compiler if you haven't already (the Community version is free). Or if you want to make your own CMake projects it should be really easy, there are very few files and fairly straightforward compiler arguments!

To call the Microsoft compiler from the command-line or in a batch file you need to set up your command line environment so it knows where to find the compiler executable (this is weird and it's a bit annoying that installing Visual Studio doesn't just handle this for you). There are two ways to do this:

  • The easiest is to use the special command prompt that Visual Studio sets up for you on installation. For VS2019 it is called "Developer Command Prompt for VS 2019". If you open the Start menu and search vs it should show up.
  • Alternatively you can open a regular command prompt and call a special script named vcvarsall. You can (hopefully) find it in one of the following locations, depending on the version of Visual Studio you're using:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat
C:\Program Files (x86)\Microsoft Visual Studio 13.0\VC\vcvarsall.bat
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat

Once you have your command line set up in either way, you can compile each subproject by navigating with cd to a directory containing a build.bat script and running it like so:

build.bat

This will create a directory called build containing an executable main.exe that you can run.

Additionally I have included configuration files for building/running the code using VSCode, my editor of choice. Once you have your command line interface set up as explained above simply run the command code to launch VS Code. Now if you open one of the project folders in VSCode you should be able to build and run using the Run Build Task and Start Debugging commands.

If you try to build one of the subprojects and you get the following error message it means that you haven't set up your command line properly because it does not recognised the compiler executable cl.exe:

'cl' is not recognized as an internal or external command,
operable program or batch file.

Resources

These are online resources I found helpful when learning the basics of Direct3D11/Win32 programming.

Acknowledgements

  • Thanks to chanibal for setting up a Visual Studio solution.

beginnerdirect3d11's People

Contributors

chanibal avatar kevinmoran avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

beginnerdirect3d11's Issues

Lesson 04 and 05 uniform buffer color does not change.

Windows 10
Visual Studio 2017

In lesson 04 using a uniform buffer for me the rectangle is always green and changing the color in the Constant does not do anything.
In lesson 05 the color should be animated but it is always constant.

Changing the pos from a float2 to a float4 seems to fix the issue or just removing the pos from the Constant struct.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.