我正在使用 Tao Framework 来处理 OpenGL。我正在尝试加载纹理并将其显示在表单上。图像似乎已正确加载(生成纹理 ID 且未发生错误),但未正确显示。
这是我加载纹理的代码
public static class TextureManager
{
static TextureManager()
{
Il.ilInit();
Il.ilEnable(Il.IL_ORIGIN_SET);
}
public static int LoadTexture(string url)
{
int texObject = -1;
int imageId;
Il.ilGenImages(1, out imageId);
Il.ilBindImage(imageId);
if (Il.ilLoadImage(url))
{
int width = Il.ilGetInteger(Il.IL_IMAGE_WIDTH);
int height = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT);
Gl.glGenTextures(1, out texObject);
Gl.glPixelStorei(Gl.GL_UNPACK_ALIGNMENT, 1);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, texObject);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_REPEAT);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_REPEAT);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
Gl.glTexEnvf(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_REPLACE);
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGB, width, height, 0, Gl.GL_RGB, Gl.GL_UNSIGNED_BYTE, Il.ilGetData());
Il.ilDeleteImages(1, ref imageId);
}
return texObject;
}
}
以及绘制它的代码:
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
Gl.glClearColor(255, 255, 255, 1);
Gl.glLoadIdentity();
Gl.glEnable(Gl.GL_TEXTURE_2D);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, mGlTextureObject);
Gl.glPushMatrix();
Gl.glTranslated(0, -1, -10);
Gl.glRotated(rot, 0, 1, 0);
Gl.glBegin(Gl.GL_QUADS);
Gl.glNormal3f(0, 0, 1);
Gl.glTexCoord2f(0, 0); Gl.glVertex3d(0, 0, 0);
Gl.glTexCoord2f(1, 0); Gl.glVertex3d(1, 0, 0);
Gl.glTexCoord2f(1, 1); Gl.glVertex3d(1, 1, 0);
Gl.glTexCoord2f(0, 1); Gl.glVertex3d(0, 1, 0);
Gl.glEnd();
Gl.glPopMatrix();
Gl.glDisable(Gl.GL_TEXTURE_2D);
AnT.Invalidate();
表格只是空白。但是,如果我启用闪电,那么这里显示的是:
我正在加载的图像是在 Paint 中创建的简单 bmp 图像 100x100。