我正在尝试使用卫星图像和基本图像以及另一个只有数字的图像作为我在卫星顶部渲染的“贴花”图像。以下是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];
}
我尝试使用GLKBaseEffect的texture2d0和texture2d1(GLKTextureEnvModeDecal)在'createBillboardAtLat'方法中绘制我的图像,如下所示:
// 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;
UPDATE!
所以如果我将blendfunc设置为:
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
然后我看到贴花出现但是数字只有大约80%不透明 - 当我移动它们时我仍然可以看到下面的一些地球,当它们旋转时它们也可以看到没有地球但是只有白色的背景,他们消失了!什么可能导致这种情况?