0

设置

System.Windows.Forms.Form用作窗口源。构造函数:

FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;

表单加载:

_Device = new Device(this, DeviceConfiguration.SelectConfiguration(Bits.Eight, Bits.Eight, Bits.Eight, Bits.Eight, Bits.Twentyfour, Bits.Eight, true, true), 1024, 768);
Debug.WriteLine(GL.GetString(GL.GL_EXTENSIONS));

base.OnLoad(e);

在加载方法中,选择了设备配置,这实际上是有效的。像这样的电话GL.GetString(GL.GL_EXTENSIONS)正在工作。所有 gl-methods 也被加载,因此支持所有使用的方法。


表格展示:

Application.Initialize(this);
RenderSettings = new RenderSettings(this);

Debug.WriteLine("After setup render settings: " + GL.GetErrorDescription());

_Textures[0] = Resources.LoadTexture("Resources\\Buttons\\btn_big_bg_normal.dds");
_Textures[1] = Resources.LoadTexture("Resources\\Buttons\\btn_big_bg_normal.dds");


base.OnShown(e);

_IsShown = true;

初始化使用的Application.Initialize(this)框架(由我编写)并且还在初始化一个默认着色器,它正在工作,而模型不工作。这会导致稍后渲染失败,因为返回的句柄无效。

框架

我有一个自己的 OpenGL 包装器,它包含所有参数的枚举,以启用开发,而无需多次查看 OpenGL 参考。例如方法glGenBuffers

[MethodGL]
public delegate void glGenBuffers(Int32 count, ArrayBufferHandle[] buffers);

ArrayBufferHandle定义:

/// <summary>
/// Represents a handle to a buffer
/// </summary>
[StructLayout(LayoutKind.Explicit, Size = 4)]
[ComVisible(true)]
public struct ArrayBufferHandle
{
    [FieldOffset(0)]
    UInt32 Handle;
    /// <summary>
    /// Determines if the buffer is valid
    /// </summary>
    public Boolean IsValid { get { return Handle > 0; } }
    /// <summary>
    /// Retrieves the default array buffer
    /// <br>which is used to reset bindings</br>
    /// </summary>
    public static ArrayBufferHandle Default { get { return new ArrayBufferHandle(); } }
    /// <summary>
    /// Retrieves the string representation of the current object
    /// </summary>
    /// <returns>The current object represented as string</returns>
    public override String ToString()
    {
        return String.Format("[ArrayBufferHandle Handle:{0} Valid:{1}]", Handle, IsValid);
    }
}

当然,着色器创建工作正常并使用如上所示的类型。

结论

对于我所面临的问题,我想我没有太多话要说。glGenBuffersglGenTextures返回零,我不知道为什么。该设置看起来像我已经使用过的其他设置。

当然,当不渲染任何模型时,窗口会以蓝色背景显示,并且在使用glGetError.

4

1 回答 1

0

首先:感谢Mārtiņš Možeiko带领我走向正确的方向。

事实证明,该方法void glGenBuffer(Int32 count, UInt32[] buffers)有效,但该方法void glGenBuffers(Int32 count, ArrayBufferHandle[] buffers)无效。两者都有一个 4 字节/元素数组,但 .NET 似乎处理它们不同。解决方案很简单:

void glGenBuffers(Int32 count, [Out]ArrayBufferHandle[] buffers)

Out向数组添加一个属性。

于 2012-10-05T16:03:46.577 回答