2011-01-15 6 views
3

私は一般的にOpenGLとモバイルプログラミングの初心者です。マルチテクスチャの問題(初心者)

私は2つのテクスチャを読み込み、異なる座標で1つのオブジェクト(私は1つのバケツのセットを意味します)にそれらを表示しようとしています。

私のアプローチ:私は間違って何をやっている

glGenTextures(2, &textures[0]); 
glEnableClientState(GL_TEXTURE_COORD_ARRAY); 
glActiveTexture(GL_TEXTURE0); 
glClientActiveTexture(GL_TEXTURE0); 
glEnable(GL_TEXTURE_2D); 
glBindTexture(GL_TEXTURE_2D, textures[0]); 
glTexCoordPointer(2, GL_SHORT, 0, mapTextCoords); 
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, map.width, map.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, [map getByteData]); 

glActiveTexture(GL_TEXTURE1); 
glClientActiveTexture(GL_TEXTURE1); 
glEnable(GL_TEXTURE_2D); 
glBindTexture(GL_TEXTURE_2D, textures[1]); 
glTexCoordPointer(2, GL_SHORT, 0, backgroundTextCoords); 
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, background.width, background.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, [background getByteData]); 

glEnableClientState(GL_VERTEX_ARRAY); 
glVertexPointer(2, GL_FLOAT, 0, mapVertices); 

?そして次に何をすべきか?

私は白いオブジェクト(全くテクスチャがありません)を得ました。

答えて

2

GL_TEXTURE_MIN_FILTERdefaultGL_NEAREST_MIPMAP_LINEARにする場合は、完全なミップマップセットを用意してください。

またはGL_TEXTURE_MIN_FILTERからGL_NEAREST/GL_LINEARに設定します。しようと、初期化するための

0

glGenTextures(1, &texA); 
glBindTexture(GL_TEXTURE_2D, texA); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_t, GL_REPEAT); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
glTexImage2D(GL_TEXTURE_2D, lod, GL_RGB, pixWidth, pixHeight, 0, GL_RGB, GL_FLOAT, pixelData); 
glGenerateMipmap(GL_TEXTURE_2D); 

は、特定のニーズのために必要に応じて上記を変更し、第二テクスチャのために繰り返します。

// Bind textures 
glActiveTexture(GL_TEXTURE0+i);  // set which texture unit will be affected by subsequent glBindTexture 
glBindTexture(GL_TEXTURE_2D, texA); // bind a 2D texture 
glActiveTexture(GL_TEXTURE0+i);  // set a different texture unit than above 
glBindTexture(GL_TEXTURE_2D, texB); // bind another 2D texture 

// Set texcoords for first texture 
glClientActiveTexture(GL_TEXTURE0+i); // set which texture unit will be affected by subsequent 
             // call to glTexCoordPointer (should match what you 
             // gave glActiveTexture for texA earlier) 
glEnableClientState(GL_TEXTURE_COORD_ARRAY); // enable texcoord attributes 
glTexCoordPointer(...);    // pass the texcoord array for texA 

// Set texcoords for second texture 
glClientActiveTexture(GL_TEXTURE0+i); // set which texture unit will be affected by subsequent 
             // call to glTexCoord pointer (should match what you 
             // gave glActiveTexture for texB earlier) 
glEnableClientState(GL_TEXTURE_COORD_ARRAY); 
glTexCoordPointer(...); // pass the texcoord array for texB 

は:

描画のために、試すなどGL_TEXTURE1GL_TEXTURE2を渡すことで何をやっているしないでくださいではなく、合格は、値の間であるGL_TEXTURE0+i 0および実装固有の結果GL_MAX_TEXTURE_COORDSが含まれます。