【问题标题】:Pixmap circle border doesn't appear in libGDX html project像素图圆形边框未出现在 libGDX html 项目中
【发布时间】:2014-08-19 14:24:11
【问题描述】:

我正在使用 libGDX 编写我的第一个项目,我目前正在尝试在背景顶部绘制一个带有不透明边框的透明圆圈。 它在 android 和桌面项目中按需要工作。但是,该 html 项目不会呈现圆圈的边框。

圆圈是使用像素图创建的纹理。由于无法为 drawCircle 方法设置 strokewidth(为什么没有?;请参阅http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/Pixmap.html#drawCircle-int-int-int-),我将边框绘制为 fillCircle,其顶部有另一个圆圈:

  1. 创建纹理

    Pixmap pixmap = new Pixmap(radius * 2 + 1, radius * 2 + 1, Format.RGBA8888); Pixmap.setBlending(Blending.None); pixmap.setColor(new Color(1,1,1,1)); pixmap.fillCircle(radius, radius, radius); pixmap.setColor(new Color(0, 0, 0, 0.6f); pixmap.fillCircle(radius, radius, radius - borderWidth); texture = new Texture(pixmap); texture.setFilter(TextureFilter.Linear, TextureFilter.Linear); pixmap.dispose();

  2. 绘图

    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT  (Gdx.graphics.getBufferFormat().coverageSampling ? GL20.GL_COVERAGE_BUFFER_BIT_NV : 0));
    
    // tell the camera to update its matrices.
    camera.update();
    game.spriteBatch.setProjectionMatrix(camera.combined);
    
    // begin the drawing process
    game.spriteBatch.begin();
    drawBackground();
    
    //circle gets drawn here
    game.spriteBatch.draw(texture, 50, 50);
    
    //end drawing process
    game.spriteBatch.end();
    

有什么想法吗?

编辑:在 Ubuntu 14.04 上的 Chrome (35.0.1916.153) 和 Firefox (30.0) 上测试。谁能重现这个问题?

【问题讨论】:

  • 如果您生成的像素图没有黑色圆圈,是否会出现纯白色磁盘? (我怀疑不是。)
  • 当我忽略黑色圆圈时,会出现纯白色磁盘。
  • 这可能是实现像素图绘制的 GWT 后端中的错误。您可能会在 badlogic 论坛上获得更好的答案/解决方案。 (不过,如果你得到一个好的答案,请回来并把你的答案放在这里!)
  • 我已经在那里发布了我的问题,但到目前为止我还没有得到任何回复。

标签: java opengl gwt libgdx


【解决方案1】:

你需要在画圆之前禁用混合:

pixmap.setBlending(Pixmap.Blending.None);
pixmap.fillCircle(radius, radius, radius);

【讨论】:

    猜你喜欢
    • 2016-05-07
    • 2023-03-18
    • 1970-01-01
    • 2012-03-10
    • 2015-01-29
    • 2021-08-28
    • 1970-01-01
    • 1970-01-01
    • 2017-10-31
    相关资源
    最近更新 更多