2013-02-08 77 views
0

所以我使用glBegin(GL_QUADS)創建了一個四邊形,然後繪製頂點,現在我想將紋理座標數組傳遞給我的着色器,以便我可以將紋理應用到我的四邊形。使用glVertexAttribPointer的openGL

所以我有一些麻煩得到正確的語法。

首先,我做的值

GLfloat coords[4][2]; 
coords[0][0] = 0; 
coords[0][1] = 0; 
coords[1][0] = 1; 
coords[1][1] = 0; 
coords[2][0] = 1; 
coords[2][1] = 1; 
coords[3][0] = 0; 
coords[3][1] = 1; 

,然後的二維數組我試圖把它變成我的着色器,我有VEC 2 texcoordIn

一個屬性
GLint texcoord = glGetAttribLocation(shader->programID(), "texcoordIn"); 
glEnableVertexAttribArray(texcoord); 
glVertexAttribPointer(texcoord, ???, GL_FLOAT, ???, ???, coords); 

所以我很困惑,我應該把參數放到我用'???'標記的glVertexAttribPointer中我也想知道是否允許我像第一個那樣將紋理座標表示爲二維數組。

回答

0

正確的價值觀是

glVertexAttribPointer(
texcoord, 
2, /* two components per element */ 
GL_FLOAT, 
GL_FALSE, /* don't normalize, has no effect for floats */ 
0, /* distance between elements in sizeof(char), or 0 if tightly packed */ 
coords); 

,我也想知道,如果我甚至允許表示紋理座標的二維數組,就像我在第一時間做了。

如果你按照上面所做的方式編寫它,即使用靜態分配的數組,那麼是的,因爲C標準聲明元素將緊緊地放在內存中。但是,如果使用指針的動態分配指針數組,則不會。

+0

感謝您的幫助!我仍然遇到麻煩。它似乎並不像我的2d'coord'數組實際上在做任何事情(四元組變成空白)。我很自信,我的內部着色器代碼是正確的。 – user1782677 2013-02-09 01:21:55

+0

@ user1782677:如果您發佈着色器的代碼,唯一的辦法就是說明。 – datenwolf 2013-02-09 01:24:23