例如,在 Windows 窗体中使用 SimpleOpenGLControl 组件,我试图画一条线。或任何其他无纹理的东西。使用 glcolor3b、3ub、3d、3f 函数,它们具有 4 个参数的类似物 - 没有任何反应。颜色保持不变,我无法管理这种颜色。在一个项目中它像绿色,在另一个项目中像浅灰色。现在我知道问题在于我的背景类,在方法 LoadTextureForModel 中:
public class Background : Visible
{
public Background(string Path)
{
LoadTextureForModel(Path);
}
public override void Display()
{
MyGlutUser.DrawRect((int)TextureObj(), new FPoint(0, 0),
MyGlutUser.WorldW + 100, MyGlutUser.WorldH + 100);
}
}
public abstract class Visible
{
public abstract void Display();
public String PathToImage
{ get; set; }
public RGBubColor Color
{ get; set; }
protected int imageID;
public int ImageID
{
get
{
return imageID;
}
set
{
imageID = value;
}
}
protected int mGlTextureObject { get; set; }
public FPoint Location
{ get; set; }
public static int Counter = 0;
public int TextureObj()
{
return mGlTextureObject;
}
public void LoadTextureForModel(string FileName)
{
PathToImage = FileName;
Il.ilGenImages(1, out imageID);
Il.ilBindImage(imageID);
if (Il.ilLoadImage(PathToImage))
{
int width = Il.ilGetInteger(Il.IL_IMAGE_WIDTH);
int height = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT);
int bitspp = Il.ilGetInteger(Il.IL_IMAGE_BITS_PER_PIXEL);
switch (bitspp) // в зависимости оп полученного результата
{
case 24:
mGlTextureObject = MakeGlTexture(Gl.GL_RGB, Il.ilGetData(), width, height);
break;
case 32:
mGlTextureObject = MakeGlTexture(Gl.GL_RGBA, Il.ilGetData(), width, height);
break;
}
Il.ilDeleteImages(1, ref imageID);
}
}
画线代码:
public static void DrawLine(FPoint p1, FPoint p2)
{
Gl.glBegin(Gl.GL_LINES);
Gl.glVertex2d(p1.x, p1.y);
Gl.glVertex2d(p2.x, p2.y);
Gl.glEnd();
}
public static void DrawLine(RGBubColor Color, FPoint p1, FPoint p2)
{
Gl.glColor3d((double)Color.r / 255.0, (double)Color.g / 255.0, (double)Color.b / 255.0);
DrawLine(p1, p2);
}
public struct RGBubColor
{
public byte r; public byte g; public byte b;
public RGBubColor(byte r, byte g, byte b)
{
this.r = r;
this.g = g;
this.b = b;
}
};
调用:
GlutUser.DrawLine(new RGBubColor(127, 0, 0), 5, new FPoint(0, 0), new FPoint(500, 500));
我需要一种方法来修复我的 LoadTextureForModel 函数。