[{"data":1,"prerenderedAt":1285},["ShallowReactive",2],{"doc-\u002Fdocs\u002Fapi\u002Feduwin-d3d-api":3},{"id":4,"title":5,"body":6,"description":16,"extension":1279,"meta":1280,"navigation":407,"path":1281,"seo":1282,"stem":1283,"__hash__":1284},"content\u002Fdocs\u002Fapi\u002Feduwin-d3d-api.md","eduwin 3D 渲染 API（D3D11）",{"type":7,"value":8,"toc":1267},"minimark",[9,13,17,23,56,59,63,79,100,140,143,152,166,175,186,188,191,200,203,228,237,240,249,255,264,271,280,283,285,288,308,323,345,347,350,421,424,463,465,469,479,554,564,579,590,643,650,665,668,683,686,701,704,719,722,737,740,749,752,761,764,766,769,778,781,796,815,835,846,854,897,899,902,911,917,926,929,938,941,950,960,962,987,989,993,1002,1015,1024,1031,1033,1078,1080,1083,1094,1149,1151,1154,1261,1263],[10,11,5],"h1",{"id":12},"eduwin-3d-渲染-apid3d11",[14,15,16],"p",{},"eduwin 对 Direct3D 11 的轻量封装。",[14,18,19],{},[20,21,22],"strong",{},"核心约定：",[24,25,26,43,50,53],"ul",{},[27,28,29,30,33,34,38,39,42],"li",{},"矩阵采用 ",[20,31,32],{},"row-major 存储","，与 ",[35,36,37],"code",{},"D3DMATRIX"," 和 HLSL 的 ",[35,40,41],{},"row_major float4x4"," 一致",[27,44,45,46,49],{},"顶点格式包含",[20,47,48],{},"位置 + 法线 + UV + 顶点色","（共 48 字节）",[27,51,52],{},"常量缓冲包含世界\u002F视图\u002F投影矩阵 + 光照参数",[27,54,55],{},"着色器支持：环境光 + 方向光 + 点光源的漫反射光照",[57,58],"hr",{},[60,61,62],"h2",{"id":62},"数据类型",[64,65,70],"pre",{"className":66,"code":67,"language":68,"meta":69,"style":69},"language-c shiki shiki-themes github-light github-dark","typedef struct { float m[16]; } dx_mat4;\n","c","",[35,71,72],{"__ignoreMap":69},[73,74,77],"span",{"class":75,"line":76},"line",1,[73,78,67],{},[14,80,81,82,85,86,89,90,89,93,89,96,99],{},"4×4 矩阵，row-major 存储（",[35,83,84],{},"m[row*4+col]","）。例如 ",[35,87,88],{},"m[0]=_11","，",[35,91,92],{},"m[1]=_12",[35,94,95],{},"m[4]=_21",[35,97,98],{},"m[12]=_41","。",[64,101,103],{"className":66,"code":102,"language":68,"meta":69,"style":69},"typedef struct {\n    float x, y, z;       \u002F\u002F 位置  0-11\n    float nx, ny, nz;    \u002F\u002F 法线  12-23\n    float u, v;          \u002F\u002F UV    24-31\n    float r, g, b, a;    \u002F\u002F 颜色  32-47\n} dx_vertex;\n",[35,104,105,110,116,122,128,134],{"__ignoreMap":69},[73,106,107],{"class":75,"line":76},[73,108,109],{},"typedef struct {\n",[73,111,113],{"class":75,"line":112},2,[73,114,115],{},"    float x, y, z;       \u002F\u002F 位置  0-11\n",[73,117,119],{"class":75,"line":118},3,[73,120,121],{},"    float nx, ny, nz;    \u002F\u002F 法线  12-23\n",[73,123,125],{"class":75,"line":124},4,[73,126,127],{},"    float u, v;          \u002F\u002F UV    24-31\n",[73,129,131],{"class":75,"line":130},5,[73,132,133],{},"    float r, g, b, a;    \u002F\u002F 颜色  32-47\n",[73,135,137],{"class":75,"line":136},6,[73,138,139],{},"} dx_vertex;\n",[14,141,142],{},"顶点格式：位置（3 float）+ 法线（3 float）+ UV（2 float）+ 顶点色（4 float），共 48 字节。",[64,144,146],{"className":66,"code":145,"language":68,"meta":69,"style":69},"typedef struct { void *vb; void *ib; int icount; } dx_geometry;\n",[35,147,148],{"__ignoreMap":69},[73,149,150],{"class":75,"line":76},[73,151,145],{},[14,153,154,157,158,161,162,165],{},[35,155,156],{},"dx_geometry"," 包含顶点缓冲和索引缓冲。通过 ",[35,159,160],{},"dx_create_geometry"," 创建，",[35,163,164],{},"dx_free_geometry"," 释放。",[64,167,169],{"className":66,"code":168,"language":68,"meta":69,"style":69},"typedef struct dx_texture_t dx_texture;\n",[35,170,171],{"__ignoreMap":69},[73,172,173],{"class":75,"line":76},[73,174,168],{},[14,176,177,178,181,182,185],{},"纹理是不透明类型，通过 ",[35,179,180],{},"dx_create_texture"," 或 ",[35,183,184],{},"dx_create_texture_rgba"," 创建。",[57,187],{},[60,189,190],{"id":190},"生命周期",[64,192,194],{"className":66,"code":193,"language":68,"meta":69,"style":69},"int dx_init(HWND hwnd, int w, int h);\n",[35,195,196],{"__ignoreMap":69},[73,197,198],{"class":75,"line":76},[73,199,193],{},[14,201,202],{},"初始化 D3D11。创建 swap chain、编译 shader、创建常量缓冲和光栅化状态。成功返回 1，失败返回 0。",[24,204,205,211,221],{},[27,206,207,210],{},[35,208,209],{},"hwnd"," — 渲染窗口句柄",[27,212,213,216,217,220],{},[35,214,215],{},"w",", ",[35,218,219],{},"h"," — 客户区宽高（像素）",[27,222,223,224,227],{},"内部自动调用 ",[35,225,226],{},"dx_resize"," 创建 render target 和 depth stencil",[64,229,231],{"className":66,"code":230,"language":68,"meta":69,"style":69},"void dx_shutdown(void);\n",[35,232,233],{"__ignoreMap":69},[73,234,235],{"class":75,"line":76},[73,236,230],{},[14,238,239],{},"销毁所有 D3D11 资源（rasterizer state、constant buffer、input layout、shaders、render target、depth stencil、swap chain、device context、device）。",[64,241,243],{"className":66,"code":242,"language":68,"meta":69,"style":69},"void dx_begin(float r, float g, float b, float a);\n",[35,244,245],{"__ignoreMap":69},[73,246,247],{"class":75,"line":76},[73,248,242],{},[14,250,251,252],{},"开始一帧渲染。清空 render target 为指定颜色，清空 depth stencil。",[20,253,254],{},"每帧必须在所有绘制前调用一次。",[64,256,258],{"className":66,"code":257,"language":68,"meta":69,"style":69},"void dx_end(void);\n",[35,259,260],{"__ignoreMap":69},[73,261,262],{"class":75,"line":76},[73,263,257],{},[14,265,266,267,270],{},"结束一帧渲染。调用 ",[35,268,269],{},"Present(1, 0)"," 交换前后缓冲。",[64,272,274],{"className":66,"code":273,"language":68,"meta":69,"style":69},"void dx_resize(int w, int h);\n",[35,275,276],{"__ignoreMap":69},[73,277,278],{"class":75,"line":76},[73,279,273],{},[14,281,282],{},"重建 render target 和 depth stencil。窗口大小变化时调用。",[57,284],{},[60,286,287],{"id":287},"矩阵设置",[64,289,291],{"className":66,"code":290,"language":68,"meta":69,"style":69},"void dx_set_world(dx_mat4 world);\nvoid dx_set_view(dx_mat4 view);\nvoid dx_set_projection(dx_mat4 proj);\n",[35,292,293,298,303],{"__ignoreMap":69},[73,294,295],{"class":75,"line":76},[73,296,297],{},"void dx_set_world(dx_mat4 world);\n",[73,299,300],{"class":75,"line":112},[73,301,302],{},"void dx_set_view(dx_mat4 view);\n",[73,304,305],{"class":75,"line":118},[73,306,307],{},"void dx_set_projection(dx_mat4 proj);\n",[14,309,310,311,314,315,318,319,322],{},"设置世界矩阵、视图矩阵、投影矩阵。在 ",[35,312,313],{},"dx_begin"," \u002F ",[35,316,317],{},"dx_end"," 之间调用，每次 ",[35,320,321],{},"dx_draw_indexed"," 前需先设 world。三个矩阵在常量缓冲中的 HLSL 代码路径为：",[64,324,328],{"className":325,"code":326,"language":327,"meta":69,"style":69},"language-hlsl shiki shiki-themes github-light github-dark","p = mul(p, mWorld);\np = mul(p, mView);\np = mul(p, mProjection);\n","hlsl",[35,329,330,335,340],{"__ignoreMap":69},[73,331,332],{"class":75,"line":76},[73,333,334],{},"p = mul(p, mWorld);\n",[73,336,337],{"class":75,"line":112},[73,338,339],{},"p = mul(p, mView);\n",[73,341,342],{"class":75,"line":118},[73,343,344],{},"p = mul(p, mProjection);\n",[57,346],{},[60,348,349],{"id":349},"相机封装",[64,351,353],{"className":66,"code":352,"language":68,"meta":69,"style":69},"typedef struct {\n    float position[3];   \u002F* 相机位置   camera.position *\u002F\n    float target[3];     \u002F* 观察目标   camera.lookAt *\u002F\n    float up[3];         \u002F* 上方向 *\u002F\n    float fov;           \u002F* 视场角 *\u002F\n    float aspect;        \u002F* 宽高比     width\u002Fheight *\u002F\n    float near_z;        \u002F* 近裁剪面 *\u002F\n    float far_z;         \u002F* 远裁剪面 *\u002F\n} dx_camera;\n\nvoid dx_camera_init(dx_camera *cam, float px, float py, float pz, float aspect);\nvoid dx_camera_update(dx_camera *cam);\n",[35,354,355,359,364,369,374,379,384,390,396,402,409,415],{"__ignoreMap":69},[73,356,357],{"class":75,"line":76},[73,358,109],{},[73,360,361],{"class":75,"line":112},[73,362,363],{},"    float position[3];   \u002F* 相机位置   camera.position *\u002F\n",[73,365,366],{"class":75,"line":118},[73,367,368],{},"    float target[3];     \u002F* 观察目标   camera.lookAt *\u002F\n",[73,370,371],{"class":75,"line":124},[73,372,373],{},"    float up[3];         \u002F* 上方向 *\u002F\n",[73,375,376],{"class":75,"line":130},[73,377,378],{},"    float fov;           \u002F* 视场角 *\u002F\n",[73,380,381],{"class":75,"line":136},[73,382,383],{},"    float aspect;        \u002F* 宽高比     width\u002Fheight *\u002F\n",[73,385,387],{"class":75,"line":386},7,[73,388,389],{},"    float near_z;        \u002F* 近裁剪面 *\u002F\n",[73,391,393],{"class":75,"line":392},8,[73,394,395],{},"    float far_z;         \u002F* 远裁剪面 *\u002F\n",[73,397,399],{"class":75,"line":398},9,[73,400,401],{},"} dx_camera;\n",[73,403,405],{"class":75,"line":404},10,[73,406,408],{"emptyLinePlaceholder":407},true,"\n",[73,410,412],{"class":75,"line":411},11,[73,413,414],{},"void dx_camera_init(dx_camera *cam, float px, float py, float pz, float aspect);\n",[73,416,418],{"class":75,"line":417},12,[73,419,420],{},"void dx_camera_update(dx_camera *cam);\n",[14,422,423],{},"用法：",[64,425,427],{"className":66,"code":426,"language":68,"meta":69,"style":69},"dx_camera cam;\ndx_camera_init(&cam, 0, 3, -5, 800.0f \u002F 600.0f);  \u002F\u002F 初始化\ndx_camera_update(&cam);                             \u002F\u002F 每帧更新\n\n\u002F\u002F 窗口 resize 时改 aspect 再 update：\ncam.aspect = 1024.0f \u002F 768.0f;\ndx_camera_update(&cam);\n",[35,428,429,434,439,444,448,453,458],{"__ignoreMap":69},[73,430,431],{"class":75,"line":76},[73,432,433],{},"dx_camera cam;\n",[73,435,436],{"class":75,"line":112},[73,437,438],{},"dx_camera_init(&cam, 0, 3, -5, 800.0f \u002F 600.0f);  \u002F\u002F 初始化\n",[73,440,441],{"class":75,"line":118},[73,442,443],{},"dx_camera_update(&cam);                             \u002F\u002F 每帧更新\n",[73,445,446],{"class":75,"line":124},[73,447,408],{"emptyLinePlaceholder":407},[73,449,450],{"class":75,"line":130},[73,451,452],{},"\u002F\u002F 窗口 resize 时改 aspect 再 update：\n",[73,454,455],{"class":75,"line":136},[73,456,457],{},"cam.aspect = 1024.0f \u002F 768.0f;\n",[73,459,460],{"class":75,"line":386},[73,461,462],{},"dx_camera_update(&cam);\n",[57,464],{},[60,466,468],{"id":467},"网格mesh-geometry-material-transform","网格（Mesh = Geometry + Material + Transform）",[14,470,471,474,475,478],{},[35,472,473],{},"dx_mesh"," 封装了几何体 + 材质 + 变换，隐藏矩阵操作，仿 Three.js 的 ",[35,476,477],{},"Mesh","：",[64,480,482],{"className":66,"code":481,"language":68,"meta":69,"style":69},"typedef struct {\n    dx_geometry *geometry;  \u002F* 顶点数据 *\u002F\n    dx_material *material;  \u002F* 材质（可 NULL） *\u002F\n    float position[3];      \u002F* 平移 *\u002F\n    float rotation[3];      \u002F* 旋转（XYZ 欧拉角） *\u002F\n    float scale[3];         \u002F* 缩放 *\u002F\n} dx_mesh;\n\ndx_mesh* dx_create_mesh(dx_geometry *geo, dx_material *mat);\nvoid     dx_mesh_set_position(dx_mesh *m, float x, float y, float z);\nvoid     dx_mesh_set_rotation(dx_mesh *m, float x, float y, float z);\nvoid     dx_mesh_set_scale(dx_mesh *m, float x, float y, float z);\nvoid     dx_mesh_draw(dx_mesh *m);\nvoid     dx_free_mesh(dx_mesh *m);\n",[35,483,484,488,493,498,503,508,513,518,522,527,532,537,542,548],{"__ignoreMap":69},[73,485,486],{"class":75,"line":76},[73,487,109],{},[73,489,490],{"class":75,"line":112},[73,491,492],{},"    dx_geometry *geometry;  \u002F* 顶点数据 *\u002F\n",[73,494,495],{"class":75,"line":118},[73,496,497],{},"    dx_material *material;  \u002F* 材质（可 NULL） *\u002F\n",[73,499,500],{"class":75,"line":124},[73,501,502],{},"    float position[3];      \u002F* 平移 *\u002F\n",[73,504,505],{"class":75,"line":130},[73,506,507],{},"    float rotation[3];      \u002F* 旋转（XYZ 欧拉角） *\u002F\n",[73,509,510],{"class":75,"line":136},[73,511,512],{},"    float scale[3];         \u002F* 缩放 *\u002F\n",[73,514,515],{"class":75,"line":386},[73,516,517],{},"} dx_mesh;\n",[73,519,520],{"class":75,"line":392},[73,521,408],{"emptyLinePlaceholder":407},[73,523,524],{"class":75,"line":398},[73,525,526],{},"dx_mesh* dx_create_mesh(dx_geometry *geo, dx_material *mat);\n",[73,528,529],{"class":75,"line":404},[73,530,531],{},"void     dx_mesh_set_position(dx_mesh *m, float x, float y, float z);\n",[73,533,534],{"class":75,"line":411},[73,535,536],{},"void     dx_mesh_set_rotation(dx_mesh *m, float x, float y, float z);\n",[73,538,539],{"class":75,"line":417},[73,540,541],{},"void     dx_mesh_set_scale(dx_mesh *m, float x, float y, float z);\n",[73,543,545],{"class":75,"line":544},13,[73,546,547],{},"void     dx_mesh_draw(dx_mesh *m);\n",[73,549,551],{"class":75,"line":550},14,[73,552,553],{},"void     dx_free_mesh(dx_mesh *m);\n",[14,555,556,559,560,563],{},[35,557,558],{},"dx_mesh_draw"," 内部自动计算 ",[35,561,562],{},"world = S × Rx × Ry × Rz × T","，绑定材质，绘制几何体。可直接读写字段：",[64,565,567],{"className":66,"code":566,"language":68,"meta":69,"style":69},"mesh->position[0] = 2;    \u002F* X 位置 *\u002F\nmesh->rotation[1] = 0.5f; \u002F* Y 旋转 *\u002F\n",[35,568,569,574],{"__ignoreMap":69},[73,570,571],{"class":75,"line":76},[73,572,573],{},"mesh->position[0] = 2;    \u002F* X 位置 *\u002F\n",[73,575,576],{"class":75,"line":112},[73,577,578],{},"mesh->rotation[1] = 0.5f; \u002F* Y 旋转 *\u002F\n",[14,580,581,582,585,586,589],{},"网格通常由 ",[35,583,584],{},"dx_create_mesh"," 作为指针创建，",[35,587,588],{},"dx_free_mesh"," 释放（注意：不会释放 geometry\u002Fmaterial，共享引用需调用方管理）。",[64,591,593],{"className":66,"code":592,"language":68,"meta":69,"style":69},"obj.ry = 0.5f;         \u002F\u002F 绕 Y 转\nobj.rx = 0.1f;         \u002F\u002F 绕 X 转\nobj.sx = 2.0f;         \u002F\u002F X 方向放大 2 倍\n---\n\n## 几何体操作\n\n```c\ndx_geometry* dx_create_geometry(dx_vertex *verts, int vcount,\n                                unsigned short *indices, int icount);\n",[35,594,595,600,605,610,615,619,624,628,633,638],{"__ignoreMap":69},[73,596,597],{"class":75,"line":76},[73,598,599],{},"obj.ry = 0.5f;         \u002F\u002F 绕 Y 转\n",[73,601,602],{"class":75,"line":112},[73,603,604],{},"obj.rx = 0.1f;         \u002F\u002F 绕 X 转\n",[73,606,607],{"class":75,"line":118},[73,608,609],{},"obj.sx = 2.0f;         \u002F\u002F X 方向放大 2 倍\n",[73,611,612],{"class":75,"line":124},[73,613,614],{},"---\n",[73,616,617],{"class":75,"line":130},[73,618,408],{"emptyLinePlaceholder":407},[73,620,621],{"class":75,"line":136},[73,622,623],{},"## 几何体操作\n",[73,625,626],{"class":75,"line":386},[73,627,408],{"emptyLinePlaceholder":407},[73,629,630],{"class":75,"line":392},[73,631,632],{},"```c\n",[73,634,635],{"class":75,"line":398},[73,636,637],{},"dx_geometry* dx_create_geometry(dx_vertex *verts, int vcount,\n",[73,639,640],{"class":75,"line":404},[73,641,642],{},"                                unsigned short *indices, int icount);\n",[14,644,645,646,649],{},"创建自定义几何体。上传顶点和索引数据到 D3D11 的默认用途（",[35,647,648],{},"D3D11_USAGE_DEFAULT","）缓冲。",[64,651,653],{"className":66,"code":652,"language":68,"meta":69,"style":69},"dx_geometry* dx_create_box(float w, float h, float d,\n                           float r, float g, float b, float a);\n",[35,654,655,660],{"__ignoreMap":69},[73,656,657],{"class":75,"line":76},[73,658,659],{},"dx_geometry* dx_create_box(float w, float h, float d,\n",[73,661,662],{"class":75,"line":112},[73,663,664],{},"                           float r, float g, float b, float a);\n",[14,666,667],{},"创建立方体几何体。自动生成 8 个顶点和 36 个索引（12 个三角形），中心在原点。",[64,669,671],{"className":66,"code":670,"language":68,"meta":69,"style":69},"dx_geometry* dx_create_sphere(float radius,\n                              float r, float g, float b, float a);\n",[35,672,673,678],{"__ignoreMap":69},[73,674,675],{"class":75,"line":76},[73,676,677],{},"dx_geometry* dx_create_sphere(float radius,\n",[73,679,680],{"class":75,"line":112},[73,681,682],{},"                              float r, float g, float b, float a);\n",[14,684,685],{},"创建 UV 球体几何体（12 环 × 16 段），中心在原点。",[64,687,689],{"className":66,"code":688,"language":68,"meta":69,"style":69},"dx_geometry* dx_create_cylinder(float radius, float height,\n                                float r, float g, float b, float a);\n",[35,690,691,696],{"__ignoreMap":69},[73,692,693],{"class":75,"line":76},[73,694,695],{},"dx_geometry* dx_create_cylinder(float radius, float height,\n",[73,697,698],{"class":75,"line":112},[73,699,700],{},"                                float r, float g, float b, float a);\n",[14,702,703],{},"创建圆柱体几何体（16 段），中心在原点。",[64,705,707],{"className":66,"code":706,"language":68,"meta":69,"style":69},"dx_geometry* dx_create_pyramid(float w, float h, float d,\n                               float r, float g, float b, float a);\n",[35,708,709,714],{"__ignoreMap":69},[73,710,711],{"class":75,"line":76},[73,712,713],{},"dx_geometry* dx_create_pyramid(float w, float h, float d,\n",[73,715,716],{"class":75,"line":112},[73,717,718],{},"                               float r, float g, float b, float a);\n",[14,720,721],{},"创建四棱锥几何体（5 顶点 \u002F 6 三角形），中心在原点。",[64,723,725],{"className":66,"code":724,"language":68,"meta":69,"style":69},"dx_geometry* dx_create_plane(float w, float h,\n                             float r, float g, float b, float a);\n",[35,726,727,732],{"__ignoreMap":69},[73,728,729],{"class":75,"line":76},[73,730,731],{},"dx_geometry* dx_create_plane(float w, float h,\n",[73,733,734],{"class":75,"line":112},[73,735,736],{},"                             float r, float g, float b, float a);\n",[14,738,739],{},"创建平面几何体（4 顶点 \u002F 2 三角形），默认在 XY 平面、面向 +Z 方向、中心在原点。通过旋转可以变成地面（绕 X 转 -90°）或墙面。",[64,741,743],{"className":66,"code":742,"language":68,"meta":69,"style":69},"void dx_draw_geometry(dx_geometry *geo, int count, int start_index, int base_vertex);\n",[35,744,745],{"__ignoreMap":69},[73,746,747],{"class":75,"line":76},[73,748,742],{},[14,750,751],{},"绘制几何体。每次调用前必须设置好 world 矩阵。",[64,753,755],{"className":66,"code":754,"language":68,"meta":69,"style":69},"void dx_free_geometry(dx_geometry *geo);\n",[35,756,757],{"__ignoreMap":69},[73,758,759],{"class":75,"line":76},[73,760,754],{},[14,762,763],{},"释放几何体的顶点和索引缓冲，并释放几何体本身。",[57,765],{},[60,767,768],{"id":768},"光照",[64,770,772],{"className":66,"code":771,"language":68,"meta":69,"style":69},"void dx_set_ambient_light(float r, float g, float b, float intensity);\n",[35,773,774],{"__ignoreMap":69},[73,775,776],{"class":75,"line":76},[73,777,771],{},[14,779,780],{},"设置环境光颜色和强度（漫反射系数）。环境光均匀照亮所有物体，无方向感。",[64,782,784],{"className":66,"code":783,"language":68,"meta":69,"style":69},"void dx_set_directional_light(float dx, float dy, float dz,\n                               float r, float g, float b, float intensity);\n",[35,785,786,791],{"__ignoreMap":69},[73,787,788],{"class":75,"line":76},[73,789,790],{},"void dx_set_directional_light(float dx, float dy, float dz,\n",[73,792,793],{"class":75,"line":112},[73,794,795],{},"                               float r, float g, float b, float intensity);\n",[14,797,798,799,802,803,806,807,810,811,814],{},"设置方向光。",[35,800,801],{},"dx\u002Fdy\u002Fdz"," 是",[20,804,805],{},"指向光源","的方向向量（会被归一化），",[35,808,809],{},"r\u002Fg\u002Fb"," 是颜色，",[35,812,813],{},"intensity"," 是强度。",[64,816,818],{"className":66,"code":817,"language":68,"meta":69,"style":69},"void dx_set_point_light(float px, float py, float pz,\n                         float r, float g, float b, float intensity,\n                         float range);\n",[35,819,820,825,830],{"__ignoreMap":69},[73,821,822],{"class":75,"line":76},[73,823,824],{},"void dx_set_point_light(float px, float py, float pz,\n",[73,826,827],{"class":75,"line":112},[73,828,829],{},"                         float r, float g, float b, float intensity,\n",[73,831,832],{"class":75,"line":118},[73,833,834],{},"                         float range);\n",[14,836,837,838,841,842,845],{},"设置点光源。",[35,839,840],{},"px\u002Fpy\u002Fpz"," 是世界坐标位置，",[35,843,844],{},"range"," 是衰减距离。",[14,847,848,849,314,851,853],{},"光照在 ",[35,850,313],{},[35,852,317],{}," 之间、绘制之前设置：",[64,855,857],{"className":66,"code":856,"language":68,"meta":69,"style":69},"dx_begin(0.15f, 0.15f, 0.2f, 1);\n\ndx_set_ambient_light(0.4f, 0.4f, 0.4f, 1.0f);\ndx_set_directional_light(0.3f, -1, 0.5f, 1, 1, 1, 1.2f);\ndx_set_point_light(1.5f, 3, 2, 1, 0.8f, 0.6f, 0.8f, 6);\n\ndx_mesh_draw(mesh);\ndx_end();\n",[35,858,859,864,868,873,878,883,887,892],{"__ignoreMap":69},[73,860,861],{"class":75,"line":76},[73,862,863],{},"dx_begin(0.15f, 0.15f, 0.2f, 1);\n",[73,865,866],{"class":75,"line":112},[73,867,408],{"emptyLinePlaceholder":407},[73,869,870],{"class":75,"line":118},[73,871,872],{},"dx_set_ambient_light(0.4f, 0.4f, 0.4f, 1.0f);\n",[73,874,875],{"class":75,"line":124},[73,876,877],{},"dx_set_directional_light(0.3f, -1, 0.5f, 1, 1, 1, 1.2f);\n",[73,879,880],{"class":75,"line":130},[73,881,882],{},"dx_set_point_light(1.5f, 3, 2, 1, 0.8f, 0.6f, 0.8f, 6);\n",[73,884,885],{"class":75,"line":136},[73,886,408],{"emptyLinePlaceholder":407},[73,888,889],{"class":75,"line":386},[73,890,891],{},"dx_mesh_draw(mesh);\n",[73,893,894],{"class":75,"line":392},[73,895,896],{},"dx_end();\n",[57,898],{},[60,900,901],{"id":901},"纹理",[64,903,905],{"className":66,"code":904,"language":68,"meta":69,"style":69},"dx_texture* dx_create_texture(const char *filename);\n",[35,906,907],{"__ignoreMap":69},[73,908,909],{"class":75,"line":76},[73,910,904],{},[14,912,913,914,99],{},"从 BMP\u002FPNG\u002FJPG 文件创建纹理。返回纹理句柄，失败返回 ",[35,915,916],{},"NULL",[64,918,920],{"className":66,"code":919,"language":68,"meta":69,"style":69},"dx_texture* dx_create_texture_rgba(int w, int h, const unsigned char *rgba);\n",[35,921,922],{"__ignoreMap":69},[73,923,924],{"class":75,"line":76},[73,925,919],{},[14,927,928],{},"从内存 RGBA 像素数据创建纹理，用于程序生成的纹理。",[64,930,932],{"className":66,"code":931,"language":68,"meta":69,"style":69},"void dx_free_texture(dx_texture *tex);\n",[35,933,934],{"__ignoreMap":69},[73,935,936],{"class":75,"line":76},[73,937,931],{},[14,939,940],{},"释放纹理资源。",[64,942,944],{"className":66,"code":943,"language":68,"meta":69,"style":69},"void dx_bind_texture(dx_texture *tex, int slot);\n",[35,945,946],{"__ignoreMap":69},[73,947,948],{"class":75,"line":76},[73,949,943],{},[14,951,952,953,956,957,959],{},"将纹理绑定到着色器的指定插槽（",[35,954,955],{},"slot"," 从 0 开始）。绑定后后续绘制的物体会使用该纹理。传 ",[35,958,916],{}," 可解除绑定。",[14,961,423],{},[64,963,965],{"className":66,"code":964,"language":68,"meta":69,"style":69},"dx_texture *tex = dx_create_texture(\"checker.bmp\");\ndx_bind_texture(tex, 0);    \u002F\u002F 绑定到 slot 0\ndx_mesh_draw(mesh);         \u002F\u002F 使用纹理绘制\ndx_bind_texture(NULL, 0);   \u002F\u002F 解绑\n",[35,966,967,972,977,982],{"__ignoreMap":69},[73,968,969],{"class":75,"line":76},[73,970,971],{},"dx_texture *tex = dx_create_texture(\"checker.bmp\");\n",[73,973,974],{"class":75,"line":112},[73,975,976],{},"dx_bind_texture(tex, 0);    \u002F\u002F 绑定到 slot 0\n",[73,978,979],{"class":75,"line":118},[73,980,981],{},"dx_mesh_draw(mesh);         \u002F\u002F 使用纹理绘制\n",[73,983,984],{"class":75,"line":124},[73,985,986],{},"dx_bind_texture(NULL, 0);   \u002F\u002F 解绑\n",[57,988],{},[60,990,992],{"id":991},"gltf-加载","glTF 加载",[64,994,996],{"className":66,"code":995,"language":68,"meta":69,"style":69},"dx_mesh** dx_load_gltf(const char *path, int *out_count);\n",[35,997,998],{"__ignoreMap":69},[73,999,1000],{"class":75,"line":76},[73,1001,995],{},[14,1003,1004,1005,1008,1009,1012,1013,99],{},"从 glTF 文件加载网格，返回 ",[35,1006,1007],{},"dx_mesh*"," 数组。",[35,1010,1011],{},"out_count"," 返回网格数量。失败返回 ",[35,1014,916],{},[64,1016,1018],{"className":66,"code":1017,"language":68,"meta":69,"style":69},"void dx_free_geometries(dx_geometry **geos, int count);\n",[35,1019,1020],{"__ignoreMap":69},[73,1021,1022],{"class":75,"line":76},[73,1023,1017],{},[14,1025,1026,1027,1030],{},"释放 ",[35,1028,1029],{},"dx_load_gltf"," 返回的整个网格数组。",[14,1032,423],{},[64,1034,1036],{"className":66,"code":1035,"language":68,"meta":69,"style":69},"int count;\ndx_geometry **geos = dx_load_gltf(\"model.gltf\", &count);\nif (geos) {\n    for (int i = 0; i \u003C count; i++)\n        dx_mesh *m = dx_create_mesh(geos[i], NULL);\n    \u002F\u002F ...\n    dx_free_geometries(geos, count);\n}\n",[35,1037,1038,1043,1048,1053,1058,1063,1068,1073],{"__ignoreMap":69},[73,1039,1040],{"class":75,"line":76},[73,1041,1042],{},"int count;\n",[73,1044,1045],{"class":75,"line":112},[73,1046,1047],{},"dx_geometry **geos = dx_load_gltf(\"model.gltf\", &count);\n",[73,1049,1050],{"class":75,"line":118},[73,1051,1052],{},"if (geos) {\n",[73,1054,1055],{"class":75,"line":124},[73,1056,1057],{},"    for (int i = 0; i \u003C count; i++)\n",[73,1059,1060],{"class":75,"line":130},[73,1061,1062],{},"        dx_mesh *m = dx_create_mesh(geos[i], NULL);\n",[73,1064,1065],{"class":75,"line":136},[73,1066,1067],{},"    \u002F\u002F ...\n",[73,1069,1070],{"class":75,"line":386},[73,1071,1072],{},"    dx_free_geometries(geos, count);\n",[73,1074,1075],{"class":75,"line":392},[73,1076,1077],{},"}\n",[57,1079],{},[60,1081,1082],{"id":1082},"矩阵数学辅助",[14,1084,1085,1086,1089,1090,1093],{},"所有矩阵函数使用 ",[20,1087,1088],{},"row-major"," 约定，与 ",[35,1091,1092],{},"D3DXMATRIX"," 一致。",[64,1095,1097],{"className":66,"code":1096,"language":68,"meta":69,"style":69},"void dx_mat4_identity(dx_mat4 *m);\nvoid dx_mat4_mul(dx_mat4 *out, const dx_mat4 *a, const dx_mat4 *b);\nvoid dx_mat4_rotation_x(dx_mat4 *m, float angle);\nvoid dx_mat4_rotation_y(dx_mat4 *m, float angle);\nvoid dx_mat4_rotation_z(dx_mat4 *m, float angle);\nvoid dx_mat4_translation(dx_mat4 *m, float x, float y, float z);\nvoid dx_mat4_look_at_lh(dx_mat4 *m, const float eye[3],\n                        const float at[3], const float up[3]);\nvoid dx_mat4_perspective_fov_lh(dx_mat4 *m, float fov_y,\n                                float aspect, float zn, float zf);\n",[35,1098,1099,1104,1109,1114,1119,1124,1129,1134,1139,1144],{"__ignoreMap":69},[73,1100,1101],{"class":75,"line":76},[73,1102,1103],{},"void dx_mat4_identity(dx_mat4 *m);\n",[73,1105,1106],{"class":75,"line":112},[73,1107,1108],{},"void dx_mat4_mul(dx_mat4 *out, const dx_mat4 *a, const dx_mat4 *b);\n",[73,1110,1111],{"class":75,"line":118},[73,1112,1113],{},"void dx_mat4_rotation_x(dx_mat4 *m, float angle);\n",[73,1115,1116],{"class":75,"line":124},[73,1117,1118],{},"void dx_mat4_rotation_y(dx_mat4 *m, float angle);\n",[73,1120,1121],{"class":75,"line":130},[73,1122,1123],{},"void dx_mat4_rotation_z(dx_mat4 *m, float angle);\n",[73,1125,1126],{"class":75,"line":136},[73,1127,1128],{},"void dx_mat4_translation(dx_mat4 *m, float x, float y, float z);\n",[73,1130,1131],{"class":75,"line":386},[73,1132,1133],{},"void dx_mat4_look_at_lh(dx_mat4 *m, const float eye[3],\n",[73,1135,1136],{"class":75,"line":392},[73,1137,1138],{},"                        const float at[3], const float up[3]);\n",[73,1140,1141],{"class":75,"line":398},[73,1142,1143],{},"void dx_mat4_perspective_fov_lh(dx_mat4 *m, float fov_y,\n",[73,1145,1146],{"class":75,"line":404},[73,1147,1148],{},"                                float aspect, float zn, float zf);\n",[57,1150],{},[60,1152,1153],{"id":1153},"内部结构",[1155,1156,1157,1170],"table",{},[1158,1159,1160],"thead",{},[1161,1162,1163,1167],"tr",{},[1164,1165,1166],"th",{},"组件",[1164,1168,1169],{},"说明",[1171,1172,1173,1185,1195,1208,1222,1234,1242],"tbody",{},[1161,1174,1175,1179],{},[1176,1177,1178],"td",{},"Swap Chain",[1176,1180,1181,1182],{},"双缓冲，",[35,1183,1184],{},"DXGI_SWAP_EFFECT_DISCARD",[1161,1186,1187,1190],{},[1176,1188,1189],{},"Feature Level",[1176,1191,1192],{},[35,1193,1194],{},"D3D_FEATURE_LEVEL_11_0",[1161,1196,1197,1200],{},[1176,1198,1199],{},"Shader Model",[1176,1201,1202,314,1205],{},[35,1203,1204],{},"vs_5_0",[35,1206,1207],{},"ps_5_0",[1161,1209,1210,1213],{},[1176,1211,1212],{},"光栅化",[1176,1214,1215,1218,1219],{},[35,1216,1217],{},"D3D11_FILL_SOLID"," + ",[35,1220,1221],{},"D3D11_CULL_NONE",[1161,1223,1224,1227],{},[1176,1225,1226],{},"常量缓冲",[1176,1228,1229,1230,1233],{},"单个 ",[35,1231,1232],{},"register(b0)","，包含 world \u002F view \u002F projection + 光照参数",[1161,1235,1236,1239],{},[1176,1237,1238],{},"光照模型",[1176,1240,1241],{},"环境光 + 方向光漫反射 + 点光源漫反射衰减",[1161,1243,1244,1247],{},[1176,1245,1246],{},"顶点格式",[1176,1248,1249,1218,1252,1218,1255,1218,1258],{},[35,1250,1251],{},"POSITION",[35,1253,1254],{},"NORMAL",[35,1256,1257],{},"TEXCOORD",[35,1259,1260],{},"COLOR",[57,1262],{},[1264,1265,1266],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":69,"searchDepth":112,"depth":112,"links":1268},[1269,1270,1271,1272,1273,1274,1275,1276,1277,1278],{"id":62,"depth":112,"text":62},{"id":190,"depth":112,"text":190},{"id":287,"depth":112,"text":287},{"id":349,"depth":112,"text":349},{"id":467,"depth":112,"text":468},{"id":768,"depth":112,"text":768},{"id":901,"depth":112,"text":901},{"id":991,"depth":112,"text":992},{"id":1082,"depth":112,"text":1082},{"id":1153,"depth":112,"text":1153},"md",{},"\u002Fdocs\u002Fapi\u002Feduwin-d3d-api",{"title":5,"description":16},"docs\u002Fapi\u002Feduwin-d3d-api","A-wZPuJufv31uMaJ8D9Bz9iBY8Bcu6mrDhavI6fAkcM",1782488679847]