请选择 进入手机版 | 继续访问电脑版
设为首页收藏本站

ESFKAMI

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz

ESFX

ESF: Xenoverse

ESF123

ESF1.2.3

EVM2.1

EVM2.1

ECXSSJ

ECX: TeamSSJ

ECX2.2

ECX RC2

ECX2.3

ECX RC3

查看: 972|回复: 0

[教程|Tutorial]3D世界中绘制纹理|World Draw Texture

[复制链接]

211

主题

216

帖子

1130

积分

ESFKAMI

Rank: 8Rank: 8

积分
1130
发表于 2017-7-13 13:17:18 | 显示全部楼层 |阅读模式
[CN]
首先#include <com_model.h>,之后Hook HUD_DrawNormalTriangles函数,方法是在LoadClient里pExportFunc->HUD_DrawNormalTriangles = HUD_DrawNormalTriangles;

接下来一切都可以在HUD_DrawNormalTriangles函数里面进行了:
先用gEngfuncs.pfnSPR_Load读取一张纹理,然后gEngfuncs.GetSpritePointer获取纹理指针,写在一行就是:
  1. model_t *MyTexture = (struct model_s *)gEngfuncs.GetSpritePointer( gEngfuncs.pfnSPR_Load( "sprites/320hud3.spr" ) );
复制代码
再接着就是用gEngfuncs.pTriAPI->SpriteTexture对纹理进行绑定然后设定一下渲染方案:


[EN]
Include com_model.h, and hook the function  HUD_DrawNormalTriangles when load client. (pExportFunc->HUD_DrawNormalTriangles = HUD_DrawNormalTriangles;)


Use gEngfuncs.pfnSPR_Load to load a texture, and use gEngfuncs.GetSpritePointer to get the pointer:

  1. model_t *MyTexture = (struct model_s *)gEngfuncs.GetSpritePointer( gEngfuncs.pfnSPR_Load( "sprites/320hud3.spr" ) );
复制代码
Then use gEngfuncs.pTriAPI->SpriteTexture to bind the texture and set render solution:





[CN]
1.绘制出一个三角形
使用TRI_TRIANGLES来绘制三角形,使用TRI_QUADS来绘制四边形,使用TRI_QUAD_STRIP来连续绘制四边形从而拼出一个正方体。使用pTriAPI->Vertex3f指定出三个顶点坐标(直接使用世界坐标就行了),使用pTriAPI->TexCoord2f分配纹理


[EN]
1.Draw a Triangle
Use TRI_TRIANGLES to draw triangles, use TRI_QUADS to draw squares, use TRI_QUAD_STRIP to piece a cube. use pTriAPI->Vertex3f to point the vertexes(you can just write the world coordinates), use pTriAPI->TexCoord2f to set texture coordinates.





Preview:



2.绘制出一个正方形|Draw a Square:

Preview:



3.绘制出一个正方体|Draw a Cube:
顶点路径|Vertex Paths:

  1. gEngfuncs.pTriAPI->Begin( TRI_QUAD_STRIP );// 绘制四边形带[]
  2. // >> 正方体右面[]
  3. gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 1.0f );
  4. gEngfuncs.pTriAPI->Vertex3f( 250.0f, 250.0f, -250.0f );


  5. gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 0.0f );
  6. gEngfuncs.pTriAPI->Vertex3f( 250.0f, 250.0f, 250.0f );


  7. gEngfuncs.pTriAPI->TexCoord2f( 1.0f, 1.0f );
  8. gEngfuncs.pTriAPI->Vertex3f( 250.0f, -250.0f, -250.0f );


  9. gEngfuncs.pTriAPI->TexCoord2f( 1.0f, 0.0f );
  10. gEngfuncs.pTriAPI->Vertex3f( 250.0f, -250.0f, 250.0f );

  11. // >> 正方体后面[]
  12. gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 1.0f );
  13. gEngfuncs.pTriAPI->Vertex3f( -250.0f, -250.0f, -250.0f );

  14. gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 0.0f );
  15. gEngfuncs.pTriAPI->Vertex3f( -250.0f, -250.0f, 250.0f );
  16. gEngfuncs.pTriAPI->End();// 结束绘制[]

  17. gEngfuncs.pTriAPI->Begin( TRI_QUAD_STRIP );// 绘制四边形带[]
  18. // >> 正方体底面[]
  19. gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 1.0f );
  20. gEngfuncs.pTriAPI->Vertex3f( 250.0f, 250.0f, -250.0f );


  21. gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 0.0f );
  22. gEngfuncs.pTriAPI->Vertex3f( 250.0f, -250.0f, -250.0f );


  23. gEngfuncs.pTriAPI->TexCoord2f( 1.0f, 1.0f );
  24. gEngfuncs.pTriAPI->Vertex3f( -250.0f, 250.0f, -250.0f );


  25. gEngfuncs.pTriAPI->TexCoord2f( 1.0f, 0.0f );
  26. gEngfuncs.pTriAPI->Vertex3f( -250.0f, -250.0f, -250.0f );

  27. // >> 正方体左面[]
  28. gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 1.0f );
  29. gEngfuncs.pTriAPI->Vertex3f( -250.0f, 250.0f, 250.0f );

  30. gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 0.0f );
  31. gEngfuncs.pTriAPI->Vertex3f( -250.0f, -250.0f, 250.0f );
  32. gEngfuncs.pTriAPI->End();// 结束绘制[]

  33. gEngfuncs.pTriAPI->Begin( TRI_QUAD_STRIP );// 绘制四边形带[]
  34. // >> 正方体前面[]
  35. gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 1.0f );
  36. gEngfuncs.pTriAPI->Vertex3f( 250.0f, 250.0f, -250.0f );


  37. gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 0.0f );
  38. gEngfuncs.pTriAPI->Vertex3f( -250.0f, 250.0f, -250.0f );


  39. gEngfuncs.pTriAPI->TexCoord2f( 1.0f, 1.0f );
  40. gEngfuncs.pTriAPI->Vertex3f( 250.0f, 250.0f, 250.0f );


  41. gEngfuncs.pTriAPI->TexCoord2f( 1.0f, 0.0f );
  42. gEngfuncs.pTriAPI->Vertex3f( -250.0f, 250.0f, 250.0f );

  43. // >> 正方体顶面[]
  44. gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 1.0f );
  45. gEngfuncs.pTriAPI->Vertex3f( 250.0f, -250.0f, 250.0f );

  46. gEngfuncs.pTriAPI->TexCoord2f( 0.0f, 0.0f );
  47. gEngfuncs.pTriAPI->Vertex3f( -250.0f, -250.0f, 250.0f );
  48. gEngfuncs.pTriAPI->End();// 结束绘制
复制代码

Preview:



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|ESFKAMI    

GMT+8, 2018-4-25 06:31 , Processed in 0.250792 second(s), 21 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表