我正在研究字体生成解决方案, 并面对质地问题。 我将动态地创建质地图集, 然后用它们的质地坐标绘制每封信的图示 。
这里映射“ t” 字母的结果 :( 生成的纹理在顶部, 我画的在底部)
It seem that the issue is that size of the primitive and texture region is not matching that s why openGL trying to resize it. I m using GL_NEAREST on both Min and Mag when loading / rendering texture
此处的转换代码如下:
glBegin(GL_TRIANGLE_STRIP);
float twidth = 7.f / 512.f;
float theight = 11.f / 512.f;
float width = 7.f;
float height = 11.f;
float w = width / 2.f;
float h = height / 2.f;
float x = 100;
float y = 100;
float tx = 135.f / 512.f;
float ty = 0;
glTexCoord2f(tx, ty);
glVertex2f(x - w, y-h);
glTexCoord2f(tx + twidth, ty);
glVertex2f(x + w, y-h);
glTexCoord2f(tx, ty + theight);
glVertex2f(x - w, y+h);
glTexCoord2f(tx + twidth, ty + theight);
glVertex2f(x + w, y+h);
glEnd();
这里的初始化代码 :
glViewport(0,0,width,height);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
// Set up the GL state.
glClearColor(1, 1, 1, 1);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
//glDisable(GL_BLEND);
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, height, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
纹理装入代码 :
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 512, 512,
0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, &texBinary[0]);