我正在尝试使用卫星图像和基本图像以及另一个只有数字的图像作为我在卫星顶部渲染的“贴花”图像。这是2张图片:
我在其中绘制地球的 drawInRect 如下所示:
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
// Clear the buffer and prepare to draw
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Enable the Earth texture
self.effect.texture2d0.name = _earthInfo.name;
self.effect.texture2d0.target = _earthInfo.target;
// Bind the earth vertex array
glBindVertexArrayOES(_earthVertexArray);
// Render the object with GLKit
[self.effect prepareToDraw];
// Draw elements from the index array and uv / vertex / normal info
glDrawElements(GL_TRIANGLES,Earth_polygoncount*3,GL_UNSIGNED_SHORT,0);
// Turn on Blending before displaying satellites
// so that the satellite image ( which has alpha )
// shows up OK
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
// Now billboard something
[self createBillboardAtLat:35 andLon:-97];
// Now billboard something
[self createBillboardAtLat:0 andLon:0];
// Now billboard something
[self createBillboardAtLat:-65 andLon:-137];
}
我尝试在“createBillboardAtLat”方法中使用 GLKBaseEffect 的 texture2d0 和 texture2d1 ( GLKTextureEnvModeDecal ) 绘制图像,如下所示:
// Get the current modelview matrix
GLKMatrix4 originalMat = self.effect.transform.modelviewMatrix;
GLKMatrix4 currMat = self.effect.transform.modelviewMatrix;
// Print the original matrix for comparison
//NSLog(@"Original Matrix:");
//[self printMatrix:currMat];
// Define the buffer designators
GLuint billboardVertexArray;
GLuint billboardVertexBuffer;
GLuint billboardIndexBuffer;
glGenVertexArraysOES(1, &billboardVertexArray);
glBindVertexArrayOES(billboardVertexArray);
// Now draw the billboard
glGenBuffers(1, &billboardVertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, billboardVertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(Billboard_vertex), Billboard_vertex, GL_STATIC_DRAW);
glGenBuffers(1, &billboardIndexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, billboardIndexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Billboard_index), Billboard_index, GL_STATIC_DRAW);
// u0,v0,normalx0,normaly0,normalz0,x0,y0,z0
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 8*sizeof(float), BUFFER_OFFSET(5));
glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 8*sizeof(float), BUFFER_OFFSET(0));
glEnableVertexAttribArray(GLKVertexAttribNormal);
glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 8*sizeof(float), BUFFER_OFFSET(2));
// Enable the Satellite texture
self.effect.texture2d0.name = _billBoardTextureInfo.name;
self.effect.texture2d0.target = _billBoardTextureInfo.target;
self.effect.texture2d0.enabled = YES;
// Set up the decal number texture
self.effect.texture2d1.name = _billBoardDecalTextureInfo.name;
self.effect.texture2d1.enabled = YES;
self.effect.texture2d1.envMode = GLKTextureEnvModeDecal;
// Bind the earth vertex array
glBindVertexArrayOES(billboardVertexArray);
但是,我的号码从来没有出现过!这是我构建后的结果:
如何让我的两个图像混合在一起?
// Enable the Satellite texture
self.effect.texture2d0.name = _billBoardTextureInfo.name;
self.effect.texture2d0.target = _billBoardTextureInfo.target;
self.effect.texture2d0.enabled = YES;
// Set up the decal number texture
self.effect.texture2d1.name = _billBoardDecalTextureInfo.name;
self.effect.texture2d1.enabled = YES;
self.effect.texture2d1.envMode = GLKTextureEnvModeDecal;
更新!
因此,如果我将 blendfunc 设置为此:
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
然后我看到贴花出现了,但数字只有大约 80% 不透明——当我移动它们时,我仍然可以看到下面的一些地球,当它们旋转时,后面没有地球,只是背景中的白色,它们消失!什么可能导致这种情况?