[英]How to create texture coordinates
我使用Blender創建3D模態。 我創建了.obj文件,並將其轉換為.h文件,但是.h文件只有glVertexPointer,glDrawArrays。 我使用了.png圖像文件。 但是,當圖像在跟蹤時,3D模式不會正確顯示。 是某種黑色。 如何使用Blender創建紋理坐標,或者如果我導入.obj文件,則任何其他軟件將創建紋理坐標
/*
created with obj2opengl.pl
source file : .\Sample.obj
vertices : 8428
faces : 14040
normals : 0
texture coords : 0
// include generated arrays
#import ".\Sample.h"
// set input data to arrays
glVertexPointer(3, GL_FLOAT, 0, SampleVerts);
// draw data
glDrawArrays(GL_TRIANGLES, 0, SampleNumVerts);
*/
unsigned int SampleNumVerts = 42120;
float SampleVerts [] = {
// f 2 1 3 4
-0.233114614641671, 0.446055325439014, 0.223483335097295,
0.266885385358329, 0.446055325439014, 0.223483335097295,
0.266885385358329, 0.446055325439014, -0.276516664902705,
// f 2 1 3 4
-0.233114614641671, 0.446055325439014, 0.223483335097295,
-0.233114614641671, 0.446055325439014, -0.276516664902705,
0.266885385358329, 0.446055325439014, -0.276516664902705,
// f 6 5 7 8
...........
}
您需要從Blender中導出帶有紋理坐標的模型(此處不是與之相關的主題。Blenders教程應為您解答)。 轉換為.h(不確定您曾經使用過的方法)時,請確保您沒有跳過UV /紋理坐標。 也將它們放在一個數組中,我將其稱為SampleUVs。
您應該在glVertexPointer之后在調用glDrawArrays之前添加此代碼:
glTexCoordPointer(3, GL_FLOAT, 0, SampleUVs);
這樣可以從數組SampleUVs獲得紋理坐標。 3代表x,y,z紋理坐標(僅將x,y更改為2)。
您還需要導入紋理並將其綁定到紋理。 我建議您正確閱讀一些有關基本模型加載和紋理化的教程。 周圍有很多,盡管這是我的最愛:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.