- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在 LibGDX 中截取我的桌面应用程序时遇到了一个相当奇怪的行为。我重新制作了一个小程序来重现这个只呈现黑色背景和红色矩形的“错误”。这些图像是结果:
左边是window的截屏工具的截图,这是运行程序的样子。右边是我在下面发布的截图代码。澄清一下,我希望程序的屏幕截图获得左图的结果,而透明度不会变得很奇怪。
这是我的渲染代码,不要介意坐标。因为我可以看到矩形被完美渲染,所以错误出现在渲染方法中对我来说毫无意义。但我还是要发布它。
@Override
public void render() {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0);
Gdx.gl.glEnable(GL20.GL_BLEND);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
shape.begin(ShapeType.Filled);
shape.setColor(Color.BLACK);
shape.rect(0, 0, 300, 300);
shape.setColor(1f, 0f, 0f, 0.5f);
shape.rect(100, 100, 100, 100);
shape.end();
Gdx.gl.glDisable(GL20.GL_BLEND);
}
这是截图的代码:
public static void screenshot() {
Pixmap pixmap = getScreenshot(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
PixmapIO.writePNG(new FileHandle(Gdx.files.getLocalStoragePath() + "screenshots/test.png"), pixmap);
pixmap.dispose();
}
private static Pixmap getScreenshot(int x, int y, int w, int h) {
final Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(x, y, w, h);
// Flip the pixmap upside down
ByteBuffer pixels = pixmap.getPixels();
int numBytes = w * h * 4;
byte[] lines = new byte[numBytes];
int numBytesPerLine = w * 4;
for(int i = 0; i < h; i++) {
pixels.position((h - i - 1) * numBytesPerLine);
pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
}
pixels.clear();
pixels.put(lines);
return pixmap;
}
我去研究了一下,我只找到了这个topic ,这是完全相同的问题。不过,它的信息略少,也没有答案。我希望你们中有人能解开这个谜。
最佳答案
我的问题已于 2017 年 2 月 23 日 由 Tenfour04 回答但由于他没有兴趣将他的解决方案作为答案发布,所以我这样做是为了解决这个问题。非常感谢他。我所做的是将 getPixels()
返回的 ByteBuffer
中的每四个元素(alpha 值)设置为 (byte) 255
(不透明) 这是我的结果:
private static Pixmap getScreenshot(int x, int y, int width, int height) {
final Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(x, y, width, height);
ByteBuffer pixels = pixmap.getPixels();
for(int i = 4; i < pixels.limit(); i += 4) {
pixels.put(i - 1, (byte) 255);
}
int numBytes = width * height * 4;
byte[] lines = new byte[numBytes];
int numBytesPerLine = width * 4;
for(int i = 0; i < height; i++) {
pixels.position((height - i - 1) * numBytesPerLine);
pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
}
pixels.clear();
pixels.put(lines);
pixels.clear();
return pixmap;
}
关于java - LibGDX 屏幕截图奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41384790/
libGDX Array类的javadoc说:一个可调整大小,有序或无序的对象数组。如果是无序的,则此类在删除元素时避免了内存复制(最后一个元素移动到删除的元素的位置)。 去除元素的改进是此类的唯一优
声音API似乎缺少指示声音播放完毕的功能。还有其他方法可以确定声音是否完成了吗? 最佳答案 据我所知,OpenAL和Android的底层声音后端甚至都没有内部跟踪信息,尽管Music API具有的is
我在应用程序启动时执行了此代码 val resolver = InternalFileHandleResolver() asset.setLoader(FreeTypeFontGenerator::c
我想要获取点 1 和点 2 之间相对于中心点的角度。如何使用 Vector2 执行此操作? Vector2 center = new Vector2((float)Gdx.graphics.getWi
我正在尝试渲染平滑的可缩放位图字体。检查后question answers之一提到使用距离场字体。 我正在按照 LibGDX wiki article 中提到的方式进行操作关于距离场字体。但是我无法让
我已经寻找答案大约 2 个小时了,但还没有找到我想要的答案。我的问题是,是否可以以及如何绘制圆形纹理,以便在圆形之外,纹理将是透明的,这甚至可能吗? 提前致谢!到目前为止,该网站提供了很大的帮助! 最
我用 libgdx 开始了一个项目,我有一个 GameStateManager 用于我的 GameStates 菜单和播放。 如果我运行该项目,它会显示菜单,然后我可以单击一个按钮来打开 Play G
我正在使用 libgdx。我需要缩放和定位文本。假设我想绘制 30 像素高的 X,并且我希望它位于屏幕中间。我想在不同的位置和不同的比例画更多的人。 有什么办法可以实现吗?我在任何地方都找不到解决方案
我正在 Libgdx 中制作纹理打包机,其中如果我使用打包机 2,048 * 2,048 的大小,只制作一个大小为 3.14 Mb 的打包机图像,如果我使用打包机的大小 1,024 * 1,024 那
我在每一帧中都进行了大量的三角函数计算。 Java 的 Math 函数是否比 Libgdx 的 MathUtils 更快? 或者我可以使用任何其他比这两个都更快的库吗? 最佳答案 com.badlog
你好,对于 LibGDX 来说有点新,目前在 pc 上的全屏模式存在问题,我想要做的是每当有人按下一个键时将我的游戏设置为全屏,而当我在 main 方法中输入一些东西时,这不会做任何事情桌面启动器.j
几年前我开始开发我的游戏,中间有很大的停顿。那时没有 gradle,只有简单的 java 安装应用程序。如何找到所使用的 LibGDX 版本? 最佳答案 干得好: Gdx.app.log("Gdx v
我正在尝试使用 libGDX 实现一个简单的动画,但目前我遇到了一件事。假设我有一堆 Sprite 需要一些时间才能完成。例如,大约 30 个 Sprite 像这个链接:https://github.
如何在游戏过程中更改窗口标题?我找不到任何方法。例如,我想在标题栏中显示我得了多少分。 最佳答案 尝试这个 : Gdx.graphics.setTitle(""+yourScore); 祝你好运 !
我正在使用 LibGdx 中的声音接口(interface)来播放 mp3 音频文件。 And when choose to loop playing the sound more than one
所以我在 LibGDX 中制作游戏,我使用 AssetManager 加载我的所有 Assets 。 我只是不确定哪种是正确的使用方法。 目前我正在第一个屏幕之前加载所有游戏 Assets 。 然后我
我一直在寻找来自 libgdx SVN 的 skinpacker,但没有成功。 然后我知道它不再存在。所以,问题是如何创建一个 skin.json 文件以在我的 libgdx 项目中使用。你知道有什么
我正在制作连点类型的游戏,我必须在屏幕上触摸的位置画一条线,所以我使用矢量来存储我触摸的各个点。 我用过 if(Gdx.input.isTouched()) { touchpos.set(Gd
我查看了测试项目中的默认皮肤文件。 我不明白为什么 uiskin.png 里面有字体图片。 uiskin.atlas 文件还包含拆分字段,我不明白为什么需要它以及如何使用它。 我在哪里可以找到所有事情
我到处搜索,但没有引用。 我想用this着色器从 shadertoy 到我的 libgdx 项目,所以我尝试首先从以下位置导入简单着色器:https://www.shadertoy.com/view/
我是一名优秀的程序员,十分优秀!