This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository Direct3D.wiki.
View the commit online.
commit 935ee7d92bf622c85a1577963fb5e28728b39b15
Author: Vincent Torri <vincent.to...@gmail.com>
AuthorDate: Fri Aug 18 21:59:05 2023 -0700
Update 'Direct3D 11 for 2D: Display a pink triangle'
---
Direct3D-11-for-2D%3A-Display-a-pink-triangle.md | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/Direct3D-11-for-2D%3A-Display-a-pink-triangle.md b/Direct3D-11-for-2D%3A-Display-a-pink-triangle.md
index f5213af..0a60d77 100644
--- a/Direct3D-11-for-2D%3A-Display-a-pink-triangle.md
+++ b/Direct3D-11-for-2D%3A-Display-a-pink-triangle.md
@@ -32,19 +32,19 @@ The vertices are displayed in a (normalized) coordinate system different from th
So the normalized coordinate system goes from (-1, 1), corresponding to pixel (0,0) in the window of size (w, h) pixels, to (1, -1), corresponding to pixel (w, h) outside the window. So the normalized coordinate (0, 0) corresponds to the center of the window.
-Conversion from pixel coordinates on the screen (from (0, 0) to (w, h), that is 1 pixel outside the window) to normalized coordinates (from (-1, 1) to (1, -1)) must be computed. It is basic math. Let us call xf(x) the value of the normalized coordinates, function of the x coordinate of a pixel. The value xf(x) is affine in x, meaning xf(x) = ax + b, a and b being real numbers. So
+Conversion from pixel coordinates on the screen (from (0, 0) to (w, h), that is 1 pixel outside the window) to normalized coordinates (from (-1, 1) to (1, -1)) must be computed. It is basic math. Let us call xf(x) the value of the normalized coordinates, function of the x coordinate of a pixel. The value xf(x) is affine in x, meaning $xf(x) = ax + b$, $a$ and $b$ being real numbers. So
-* xf(0) = -1 = b, and
-* xf(w) = 1 = aw - 1
+* $xf(0) = -1 = b$, and
+* $xf(w) = 1 = aw - 1$
-So xf(x) = (2x - w)/w. Similarly, yf(y) = (h - 2y) / h. Let us define these two macros:
+So $xf(x) = (2x - w)/w$. Similarly, $yf(y) = (h - 2y) / h$. Let us define these two macros:
```c
#define XF(w,x) ((float)(2 * (x) - (w)) / (float)(w))
#define YF(h,y) ((float)((h) - 2 * (y)) / (float)(h))
```
-These two macros will be used in the final code below.
+These two macros will be used in the final code below to transform pixel coordinate system to the normalized coordinate system.
### The scene
@@ -68,7 +68,7 @@ We have to pass the vertices of our triangle (which are the geometric data) to t
The code below is the HLSL code which contains both the function `main_vs()` for the vertex shader program, and the function `main_ps()` for the pixel shader program. Save it under the name `shader_1.hlsl`.
-```c
+```c(file)
struct vs_input
{
float2 position : POSITION;
@@ -115,3 +115,5 @@ float4 main_ps(ps_input input) : SV_TARGET
### The full code
The file `shader_1.hlsl` must be saved in the same directory than `win.c` and `d3d_2.c` (as well as all the other following sections). Here is the full D3D code, followed with the diff between `d3d_1.c` and `d3d_2.c`.
+
+H
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.