OpenGL 中的每像素绘图
我曾经用“每像素”绘图编写小游戏, 我的意思是使用一些 SetPixel(x,y,color) 函数或类似的函数。
我对OpenGL也很感兴趣,但不太了解。
这是在 OpenGL 中进行每像素绘图的好(快)方法吗?
例如,使用纹理四边形作为精灵会很好, 或整个应用程序背景屏幕,可以 使用我自己的 SetPixel 例程设置不同的像素 我会写......或任何其他方式 - 但它应该是有效的 尽可能多
(特别是我对 OGL 的基本基础 1.0 版本感兴趣)
I used to write small games with 'per pixel' drawing,
I mean with some SetPixel(x,y,color) function or such.
I am also interested in OpenGL but do not know it much.
Is it a good (fast) way to do a per pixel drawing in OpenGL ?
It would be good for example to use textured quads as a sprites,
or whole application background screen, with possibility to
set distinct pixel with some kind of my own SetPixel routine
i would write... or any other way - but it should be efficient
as much as it cans
(especialy im interested in basic fundamenta 1.0 version of OGL)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以设置一个投影,将顶点坐标 1:1 映射到像素坐标:
从这里开始,顶点 X,Y 坐标以像素为单位,原点位于左下角。理论上,您可以将立即模式与 GL_POINT 原语一起使用。但将事情分批处理是一个更好的主意。不是单独发送每个点,而是创建一个包含您想要绘制的所有点的数组:
您可以 OpenGL 指向…………
并通过一次调用让它访问并绘制所有点:
You can set a projection that will map vertex coordinates 1:1 to pixel coordinates:
From here on, vertex X,Y coordinates are in pixels with the origin in the lower left corner. In theory you could use the immediate mode with GL_POINT primitives. But it's a much better idea to batch things up. Instead of sending each point indivisually create an array of all the points you want to draw:
This you can OpenGL point to…
…and have it access and draw it all with a single call:
你真的不想这样做。
没有好的或快速的方法可以做到这一点。由于速度的原因,它是非常不鼓励的。
尽管在 OGL 1 中并不容易(或在某些情况下可能),但正确的方法是使用像素着色器或混合模式。这是唯一正确的方法,其他任何方法都是对整个系统的破坏。
根据数据需要修改的方式,顶点颜色和混合模式可能能够解决某些用途。它不会单独对每个像素着色,但您可以更快地修改纹理。
为此,您可以绘制单像素四边形(尽管必须注意偏移它们并处理过滤以防止模糊),或者您可以获取纹理数据并稍后对其进行操作。两者都会慢得令人难以置信,但可以正常工作。
使用纹理数据可能更简单并且可能稍微快一些。
You really don't want to do this.
There is no good or fast way to do this. It is highly discouraged due to the speed.
The proper way, although not easy (or in some cases possible) in OGL 1, is to use pixel shaders or blend modes. That is the only correct way, anything else is hacking around the entire system.
Depending on how the data needs modified, vertex colors and blend modes may be able to solve the some uses. It won't tint each pixel individually, but you can modify the texture must faster.
To do it, you can draw single-pixel quads (although care must be taken to offset them and handle filtering to prevent blurring) or you can get texture data and manipulate it later. Both will be unbelievably slow, but could function.
Working with the texture data is probably simpler and may be slightly faster.