简体   繁体   English

Quad Texture怪异行为OpenGL旧GPU

[英]Quad Texture weird behaviour OpenGL old GPU

I'm programming a Pascal project (using Lazarus) for school and I experienced some weird behaviour when the project was executed on one of the school computers. 我正在为学校编写一个Pascal项目(使用Lazarus),当在学校的一台计算机上执行该项目时,我遇到了一些奇怪的行为。

It ran completely fine on my laptop from 2011 with an NVidia 650M. 从2011年开始,在配备NVidia 650M的笔记本电脑上,它运行良好。 The school computers drivers are outdated, so it falls back to Windows GDI, which basically is a software implementation for OpenGL 1.1. 学校计算机的驱动程序已过时,因此可以使用Windows GDI,它基本上是OpenGL 1.1的软件实现。 So maybe the graphics card is not the cause of the problem. 因此,也许显卡不是问题的原因。

Also it may be important to mention that this ONLY happens when using the GL_NEAREST method for both mag and min filters. 同样可能需要提及的是,仅对mag和min过滤器使用GL_NEAREST方法时,只会发生这种情况。 The problem doesn't occurr when using GL_LINEAR for MAG and GL_NEAREST for MIN for example. 例如,对于MAG使用GL_LINEAR,对于MIN使用GL_NEAREST,则不会发生此问题。

This is the code that loads the texture(s): 这是加载纹理的代码:

tex := LoadTGA(filename);
if tex.iType = 2 then
begin
  glGenTextures(1, @(Result.textureID));
  glBindTexture(GL_TEXTURE_2D, Result.textureID);

  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

  if tex.bpp = 3 then glFormat := GL_BGR
  else glFormat := GL_BGRA;

  glTexImage2D(GL_TEXTURE_2D, 0, tex.bpp, tex.w, tex.h, 0, glFormat, GL_UNSIGNED_BYTE, tex.data);

  FreeMem(tex.data);
end;

This is the code that renders the quad: 这是呈现四边形的代码:

glColor3ub(255, 255, 255);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, q.surface.textureID);
glBegin(GL_QUADS);
  glTexCoord2f(0, 1); glVertex3f(q.points[0].x, q.points[0].y, q.points[0].z);
  glTexCoord2f(1, 1); glVertex3f(q.points[1].x, q.points[1].y, q.points[1].z);
  glTexCoord2f(1, 0); glVertex3f(q.points[2].x, q.points[2].y, q.points[2].z);
  glTexCoord2f(0, 0); glVertex3f(q.points[3].x, q.points[3].y, q.points[3].z);
glEnd;
glDisable(GL_TEXTURE_2D);

The texture has the format 32x32 pixels. 纹理的格式为32x32像素。

Update: As it turns out, colored quads experience a similiar bug as well. 更新:事实证明,彩色四边形也遇到类似的错误。 In the pic with the colored quads, it seems like GDI is doing clipping first and THEN applying the color. 在带有彩色四边形的图片中,似乎GDI首先进行裁剪,然后再应用颜色。 Should be the other way around. 应该相反。 Now we just have to find out why. 现在我们只需要找出原因。 I painted the edges of the clipping triangles in the lower picture, et voila, you can see exactly where the texture is "inconsistent" 我在下面的图片中绘制了剪裁三角形的边缘,瞧,您可以确切地看到纹理“不一致”的位置

Pictures: 图片: 错误1错误2错误3错误4

It is very hard to guess. 很难猜测。 The problem is probably related to difference in texture interpolation implemented in Nvidia and ATI drivers. 该问题可能与Nvidia和ATI驱动程序中实现的纹理插值的差异有关。 Using GL_LINEAR you use different interpolation method and the "seam" is not visible. 使用GL_LINEAR可以使用不同的插值方法,并且“接缝”不可见。 Some ideas: 一些想法:

  • Try filling quad with solid color, eg yellow, and check if separate triangles are also visible then. 尝试用纯色(例如黄色)填充四边形,然后检查是否也可以看到单独的三角形。
  • Create your quad using two triangles (6 vertices) not GL_QUADS . 使用两个三角形(6个顶点)而不是GL_QUADS创建四边形。
  • Do you pass vertices in counter clockwise order? 是否按逆时针方向传递顶点?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM