基于tao框架的c# opengl开发遇到一个简单的问题
想使用Devil来载入纹理,编写了一个实验代码
绘制代码为
private void Form1_Load(object sender, EventArgs e)
{
simpleOpenGlControl1.InitializeContexts();
simpleOpenGlControl1.SwapBuffers();
Il.ilInit();
Ilu.iluInit();
Ilut.ilutInit();
Ilut.ilutRenderer(Ilut.ILUT_OPENGL);
simpleOpenGlControl1.SizeChanged += new EventHandler(simpleOpenGlControl1_SizeChanged);
// _textureManager.LoadTexture("map", "ccd-bkg.jpg");
// Texture texture = _textureManager.Get("map");
//Gl.glEnable(Gl.GL_TEXTURE_2D);
//Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture.Id);
PlotGL();
}
private void PlotGL()
{
Gl.glColor4f(1.0f, 1.0f, 1.0f, 0.1f);
Gl.glBegin(Gl.GL_QUADS);
Gl.glVertex3f(0, 0, 0);
Gl.glVertex3f(0.2f, 0, 0);
Gl.glVertex3f(0.8f, 0.6f, 0);
Gl.glVertex3f(0, 1, 0);
Gl.glEnd();
}
如果红色那行代码注释掉,绘制没有问题,都是白色的四边形
但一旦载入纹理后,四边形变成褐色了,不知为什么
public void LoadTexture(string textureId, string path)
{
int devilId = 0;
Il.ilGenImages(1, out devilId);
Il.ilBindImage(devilId); // set as the active texture.
if (!Il.ilLoadImage(path))
{
System.Diagnostics.Debug.Assert(false,
"Could not open file, [" + path + "].");
}
Ilu.iluFlipImage();
int width = Il.ilGetInteger(Il.IL_IMAGE_WIDTH);
int height = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT);
int openGLId = Ilut.ilutGLBindTexImage();
System.Diagnostics.Debug.Assert(openGLId != 0);
Il.ilDeleteImages(1, ref devilId);
_textureDatabase.Add(textureId, new Texture(openGLId, width, height));
}