首先,你不能使用雙精度浮點數,因爲這些不被幾乎所有的GPU.So支持,只是改變你的結構的成員飄起然後......
定義在GLSL相同結構。
struct myVertStruct
{
float x, y, z; // for spacial coords
float nx, ny, nz; // for normals
float u, v; // for texture coords
float a, b; // just a couple of custom properties
} myStructName;
然後,實例化在c結構陣列/ C++,創建VBO,分配的內存,然後將其綁定到着色器:當綁定屬性
struct myVertStruct
{
float x, y, z; // for spacial coords
float nx, ny, nz; // for normals
float u, v; // for texture coords
float a, b; // just a couple of custom properties
};
GLuint vboID;
myVertStruct myStructs[100]; // just using 100 verts for the sake of the example
// .... fill struct array;
glGenBuffers(1,&vboID);
然後:
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glVertexAttribPointer(0, sizeof(myVertStruct) * 100, GL_FLOAT, GL_FALSE, 0, &struct);
glBindBuffer(GL_ARRAY_BUFFER, 0);
...然後將您的vbo綁定到您使用上面使用的glsl段創建的着色器程序。
第1步:*停止使用雙打*。第2步:以與其他屬性相同的方式執行此操作。 '正常'沒什麼特別的。另外,'vec3 normal'是一個頂點着色器*輸出*,而不是一個屬性。所以你的問題很困惑。 – 2013-02-27 01:52:40
您正在使用哪種OpenGL版本? OpenGL 2和OpenGL 3+的代碼略有不同。另外,正如@NicolBolas已經提到的,「變化」不是頂點着色器輸入的選項。 – 2013-02-27 08:09:57