在决定尝试使用现代OpenGL进行编程之后,我留下了固定功能管道,并且我不完全确定要获得与之前相同的功能。使用现代OpenGL进行像素完美纹理映射
我想纹理地图四边形像素完美大小,匹配纹理大小。例如,128x128纹理映射到四边形128x128的大小。
这是我的顶点着色器。
#version 110
uniform float xpos;
uniform float ypos;
uniform float tw; // texture width in pixels
uniform float th; // texture height in pixels
attribute vec4 position;
varying vec2 texcoord;
void main()
{
mat4 projectionMatrix = mat4(2.0/600.0, 0.0, 0.0, -1.0,
0.0, 2.0/800.0, 0.0, -1.0,
0.0, 0.0, -1.0, 0.0,
0.0, 0.0, 0.0, 1.0);
gl_Position = position * projectionMatrix;
texcoord = (gl_Position.xy);
}
这是我的片段着色器:
#version 110
uniform float fade_factor;
uniform sampler2D textures[1];
varying vec2 texcoord;
void main()
{
gl_FragColor = texture2D(textures[0], texcoord);
}
我的顶点数据作为这样的,其中w和h是纹理的宽度和高度。
[
0, 0,
w, 0,
w, h,
0, h
]
我打开一个128x128的质地和与这些着色器我看到图像重复4次:http://i.stack.imgur.com/UY7Ts.jpg
可以在正确的道路的人提供建议,以便能够翻译和规模给予TW日,XPOS ,xpos制服?
Hello,Lefty!欢迎来到StackOverflow。请记住一些事项 - 请使用四个空格(或使用“{}”图标)缩进代码,以便格式正确。另外,当在OpenGL标签中发布时,在指定OpenGL版本时很有帮助。特别是因为你的代码样本听起来像OpenGL 2.0,这确实有用,但今天不是“现代”。 :) – Kos 2011-04-23 13:17:28
感谢您的答复。这是现代的OpenGL(> = 3?),因为我没有使用固定功能流水线,我的顶点数据是以数组形式提供的,纹理采样是使用着色器完成的。这就是说,我还是比较新的这个,所以纠正我,如果我错了:) – Lefty 2011-04-23 13:22:55
相关http://stackoverflow.com/questions/7922526/opengl-deterministic-rendering-between-gpu-vendor – 2016-07-13 12:50:34