是什么导致杂散像素出现在我的SDL2程序中? [英] What could be causing stray pixels to appear in my SDL2 program?

查看:68
本文介绍了是什么导致杂散像素出现在我的SDL2程序中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到很多杂散像素附着到使用SDL2绘制的对象上.多余像素添加到的对象是线条,实心矩形和将TTF文本转换为纹理的对象. SDL_RenderFillRect()函数采用两个参数: SDL_Renderer * SDL_Rect * 指定显示矩形的位置.我使用该函数绘制矩形.我看不出我怎么可能做错了什么.每当有一个杂散像素时,它始终是附着在对象上的一个像素.例如,我的矩形将如下所示:

I'm seeing a lot of stray pixels attached to objects that I draw using SDL2. The objects the extra pixels get added to are lines, filled rectangles, and TTF text turned into textures. The SDL_RenderFillRect() function takes two arguments: an SDL_Renderer* and an SDL_Rect* to specify where to display the rectangle. I use that function for drawing rectangles. I don't see how I could be doing something wrong. Whenever there is a stray pixel, it's always one single pixel attached to the object. For instance, my rectangles will look like the following:

XXXXXXXXXXX
XXXXXXXXXXX
XXXXXXXXXXXX   <----stray pixel on the right-bottom

以上像素与实际图像的像素数不同,比例也不相同,但是是相同的想法.还有一个附加的像素.

The above is not the same number of pixels as the real image, nor the same scale, but it's the same idea. There is an extra attached pixel.

我会得到一些与线条相似的东西.像这样(由3行组成):

I'll get something similar with lines. Like this (composed of 3 lines):

                X   <--- stray pixel
XXXXXXXXXXXXXXXXX
X               X
X               X

对于文本,我会得到这样的东西:

For text, I'll get something like this:

XXXXXXXXX
    X
    X
    X

        X   <--- stray pixel

杂散像素始终显示在同一位置.对于文本,它们总是在那里.对于线条和盒子,它们有时只是在那里.

The stray pixels always show up in the same place. For text, they're always there. For lines and boxes, they are only sometimes there.

知道为什么会这样吗?会导致这种情况的原因是什么?

Any idea why this is happening? What are the sorts of things that can cause this?

推荐答案

我还无法提供一个最小的可重现示例.但是,我确实找到了至少一个变通办法(以及有关导致问题的原因的提示),希望这是暂时的.我发现,当我用标志 SDL_RENDERER_SOFTWARE 而不是 SDL_RENDERER_ACCELERATED 调用 SDL_CreateRenderer()时,杂散像素消失了.希望当我在屏幕上绘制更多内容时,我不会发现程序运行速度超级慢.但是这样做完全摆脱了杂散像素.因此,至少在目前,我对此感到非常高兴.

I have not yet been able to produce a minimal reproducible example. However, I did find at least a workaround (as well as a hint as to what is causing the problem), that is hopefully temporary. I found that the stray pixels went away when I called SDL_CreateRenderer() with flag SDL_RENDERER_SOFTWARE rather than SDL_RENDERER_ACCELERATED. Hopefully, I don't find my program running super slow as I draw more things on the screen. But doing this has completely gotten rid of the stray pixels. So, I am very happy about that, at least for right now.

如果有人对问题有更深入的了解,以及为什么我必须使用软件渲染来避免出现杂散像素,请编辑此答案或添加评论.

If anyone has anymore insight on the problem and why I am having to use software rendering to avoid stray pixels, please edit this answer or add a comment.

这篇关于是什么导致杂散像素出现在我的SDL2程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆