【问题标题】:Using Texture as label in WhirlyGlobe在 WhirlyGlobe 中使用纹理作为标签
【发布时间】:2011-12-06 07:29:34
【问题描述】:

WhirlyGlobe 是一个非常有用的框架,我想显示国家标志而不是每个国家的名称。 在查看 LabelLayer.h 时,似乎可以用图片覆盖从 Text 标签生成的 icontexture:

@interface SingleLabel : NSObject  {      
NSString *text;      
WhirlyGlobe::GeoCoord loc;      
NSDictionary *desc;  // If set, this overrides the top level description
WhirlyGlobe::SimpleIdentity iconTexture;  // If non-zero, this is the texture to use as an icon  }  

但我没有找到任何使用标签进行图片显示的方法。
有人可以帮我理解如何用图片标签替换文本标签吗?

以下@Mousebird 第一个答案是我已经实现的:

// This describes how our labels will look
    NSDictionary *labelDesc = 
    [NSDictionary dictionaryWithObjectsAndKeys:
     [NSNumber numberWithBool:YES],@"enable",
     [UIColor clearColor],@"backgroundColor",
     [UIColor whiteColor],@"textColor",
     [UIFont boldSystemFontOfSize:16.0],@"font",
     [NSNumber numberWithInt:4],@"drawOffset",
     [NSNumber numberWithFloat:0.08],@"height",
     [NSNumber numberWithFloat:0.08],@"width",
     nil];

    // Build up an individual label
    NSMutableArray *labels = [[[NSMutableArray alloc] init] autorelease];
    SingleLabel *texLabel = [[[SingleLabel alloc] init] autorelease];
    Texture *theTex = new Texture(@"icon", @"png");
    theTex->setUsesMipmaps(true);
    texLabel.text = @"";
    texLabel.iconTexture = theTex->getId();
    theScene->addChangeRequest(new AddTextureReq(theTex));
    [texLabel setLoc:GeoCoord::CoordFromDegrees(5, -3)];
    [labels addObject:texLabel];
    [self.labelLayer addLabels:labels desc:labelDesc];

还是一个问题,纹理加载到内存中但没有出现。将字符串作为文本在标签的第一个字符上创建一个空白方块

【问题讨论】:

  • icon.png 每边是 2 的幂吗?

标签: iphone ios opengl-es textures


【解决方案1】:

抱歉耽搁了。我需要为 stackoverflow 设置某种提要。

无论如何,简短的回答是没有一个很好的方法来做到这一点。我正在为客户添加标记,但要到 1.2 才会发布。现在,您应该能够使标签显示纹理。这就是您在此处显示的 iconTexture。

要创建纹理,请执行以下操作:

Texture *theTex = new Texture(@"nameoftexture", @"png");  
theTex->setUsesMipmaps(true);  
theTexId = theTex->getId();  
scene->addChangeRequest(new AddTextureReq(theTex));  

然后使用它:

singleLabel.text = @"";  
singleLabel.iconTexture = theTexId;  

【讨论】:

  • 谢谢,非常感谢您花时间回答。我已经实现了您的代码,但标签中仍然没有纹理。我在第一个问题中更新的代码。
  • 添加一些文字以便于查找。可能只是尺寸问题。
猜你喜欢
  • 1970-01-01
  • 2020-04-03
  • 2013-03-28
  • 2015-06-30
  • 2021-05-09
  • 2012-02-10
  • 2019-07-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多