OpenGL-使用非规范化的texcoords [英] OpenGL - Use non normalized texcoords
问题描述
默认情况下,OpenGL使用归一化的TexCoords,这意味着该值必须在0到1([0..1])之间. Vertex
的常见实现必须看起来像这样:
By default, OpenGL uses normalized TexCoords, which mean the value must be between 0 and 1 ([0..1]). the common implementation of Vertex
must be look something like this:
// Common Implementation of Vertex
Vertex v = new Vertex(
// Position
new Vector2(0f, 500f),
// 'Normalized' TexCoords [0..1]
new Vector2(0f, 1f),
// Color of Vertex
Color.White
);
// Or in immediate mode..
// It's the same, we still need to specify between 0 and 1 ([0..1])
GL.TexCoord2(1f, 0f);
但是,在OpenGL中是否可以使用非规范化的texcoord(因此以像素格式指定,这意味着该值必须在0到大小([0..size])之间?
However, is it possible to use non normalized texcoord (so it specified in pixel format, which mean the value must be between 0 and size ([0..size])) in OpenGL?
推荐答案
我仍然不知道为什么GL.Ortho
(在MatrixMode.Texture
中时)没有给我预期的结果.
I still can't figure out why GL.Ortho
(while in MatrixMode.Texture
) isn't give me intended result..
所以最后,我最终手动计算了矩阵:
So finally, I ended up with calculating matrix manually:
// Initialize identity matrix
Matrix4 matrix = new Matrix4
(1f, 0f, 0f, 0f,
0f, 1f, 0f, 0f,
0f, 0f, 1f, 0f,
0f, 0f, 0f, 1f);
// Or use Matrix4.Identity (in OpenTK case), that should be equal(?)
// Convert to normalized
matrix[0, 0] = 1f / textureWidth;
matrix[1, 1] = 1f / textureHeight;
// Apply the matrix to texture matrix
GL.MatrixMode(MatrixMode.Texture);
GL.LoadMatrix(ref matrix);
这篇关于OpenGL-使用非规范化的texcoords的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!