2014-06-11 33 views
0

如何發送來自C++的着色器值,我知道我可以使用統一類型,但是沒有因爲有必要修改每個頂點的值並且uniform是恆定的,我已經看到有一種「in」和「out」,但不支持OpenGL ES 2.0,您向我發送了一個如何傳遞這些信息的示例值給頂點着色器float,我向他們發送我正在使用的代碼的一部分。如何從C++向一個頂點着色器傳遞一個變量(不是統一的)float值OpenGL ES 2.0

attribute float cppValue; 
varying float valueV; 

void main() 
{ 
valueV= cppValue; 
} 

exampleValueCpp float = 1; 
glVertexAttribPointer (0, 1, GL_FLOAT, GL_FALSE, 0, & exampleValueCpp); 

UPDATE

我已經看到有一個函數「glVertexAttrib1f」和「glVertexAttrib1fv」修改屬性,但我認爲這隻能通過在glBegin和glEnd使用,這些功能已過時在OpenGLES 2.0或更高版本中,我是對的?,是不是可以發送一個不恆定的頂點着色器值?

回答

0

,如果你希望每個浮成爲每個頂點不同的,那麼你應該在那裏它們被收集到一個數組:

float* exampleValueCpp = new float[numVertex]; 
for(int i = 0;i<numVertex;i++){ 
    //fill values 
} 
glBindBuffer(GL_ARRAY_BUFFER,0);//use application memory 
glVertexAttribPointer (0, 1, GL_FLOAT, GL_FALSE, 0, exampleValueCpp); 

但是你也可以把它上傳到VBO並使用它像:

glGenBuffers(1, &cppBuffer); 
glBindBuffer(GL_ARRAY_BUFFER, cppBuffer); 

float* exampleValueCpp = new float[numVertex]; 
for(int i = 0;i<numVertex;i++){ 
    //fill values 
} 

glBufferData(GL_ARRAY_BUFFER, numVertex*sizeof(float), exampleValueCpp, GL_STATIC_DRAW); 
delete[] exampleValueCpp; 
glVertexAttribPointer (0, 1, GL_FLOAT, GL_FALSE, 0, 0);//last parameter is offset into the buffer 
相關問題