显示列表不会运行
我正在尝试创建一个工具,该工具将在 openGL 中绘制形状,然后在 Windows 窗体中修改该形状的属性值。因此,如果我的形状是矩形,我将创建一个表单,允许用户控制矩形的大小、颜色等。我已经用托管 c++ 编写了 openGL 代码,并用 c# 编写了表单,由于其中一些形状变得更加复杂,我决定为它们制作显示列表(出于性能和可预测性目的)。
我在形状的构造函数中定义显示列表,并在渲染方法中调用显示列表。
我的问题是我的显示列表根本无法运行。将渲染显示列表外部渲染的部分,但不会渲染显示列表内的部分。
这是我的过程的一些示例代码:
//c# side
GLRectangle rect
public CSharpRectangle() {
rect = new GLRectangle();
}
//managed c++ side
public GLRectangle() {
width = 50;
height = 50;
//initialize more values
rectDL = glGenLists(1);
glNewList(rectDL, GL_COMPILE);
renderRect();
glEndList();
}
public render() {
//Draw border
glBegin(GL_LINE_LOOP);
glVertex2f(0, 0);
glVertex2f(width, 0);
glVertex2f(width, height);
glVertex2f(0, height);
glEnd();
//Draw interior
glCallList(rectDL);
}
private renderRect() {
glRectf(0,0,width,height);
}
在这个例子中,将渲染矩形的边框,但矩形本身不会被渲染...如果我用简单的方法调用替换显示列表,则矩形会渲染得很好。有谁知道为什么会发生这种情况?
I am trying to create a tool that will draw a shape in openGL and then modify the values of the properties of that shape in a windows form. So if my shape is a rectangle, I will create a form that will allow the user to control the size, color etc of the rectangle. I have written the openGL code in managed c++ and the form in c#, and as some of these shapes got more complicated I decided to make display lists for them (for both performance and predictability purposes).
I define the display list in the constructor for the shape and I call the display lists in the render method.
My issue is that my display lists won't run at all. The parts that I render outside of a display list will be rendered, but the parts inside the display list will not be rendered.
Here's some sample code of my process:
//c# side
GLRectangle rect
public CSharpRectangle() {
rect = new GLRectangle();
}
//managed c++ side
public GLRectangle() {
width = 50;
height = 50;
//initialize more values
rectDL = glGenLists(1);
glNewList(rectDL, GL_COMPILE);
renderRect();
glEndList();
}
public render() {
//Draw border
glBegin(GL_LINE_LOOP);
glVertex2f(0, 0);
glVertex2f(width, 0);
glVertex2f(width, height);
glVertex2f(0, height);
glEnd();
//Draw interior
glCallList(rectDL);
}
private renderRect() {
glRectf(0,0,width,height);
}
In this example, the border of the rectangle would be rendered, but the rectangle itself won't be rendered... if I replace the display list with simply a method call, the rectangle is rendered fine. Does anyone know why this might be happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想捐出我的2分钱。
您问题中的代码对我来说似乎是正确的,因此您的应用程序中可能还有其他内容使您的显示列表无法运行。
我唯一能想到的是编译显示列表时(实际上是执行 GlRectangle 构造函数时)没有当前上下文。那么,该例程是否在调用 glMakeCurrent 的同一线程中执行?该例程是在 glMakeCurrent 之后调用的吗?
此外,在每个 OpenGL 例程之后检查 glGetError 以验证操作。如果它返回错误,您可以知道代码中出了什么问题。
I want to give my 2 cents.
The code in your question seems correct to me, so probably there something else in your application that make your display list not runnable.
The only thing I can think is there's no current context when compiling the display list (indeed when executing GlRectangle constructor). So, is that routine executed in the same thread which have called glMakeCurrent? Is that routine called after glMakeCurrent?
Further, check with glGetError after each OpenGL routine in order to validate the operation. In the case it returns an error, you can know what's wrong in your code..
你可能得不到你想要的东西的原因很简单,因为它已经不存在了。在我阅读 openGL 红皮书时,我注意到显示列表在 openGL 3.1 及更高版本中已被弃用(意味着简单地删除),并通过谷歌搜索确认了这一点。我不记得原因了,但我相信是因为它扰乱了 VAO 和 VBO。因此,如果您使用高于 opengl 3.1 的版本,您将不会再获得显示列表。
The reason you may not get what you want is simply because it isn't there anymore. In time I was reading openGL Red book, I've noticed that display lists were deprecated in openGL 3.1 and higher (means simply removed) and googling for that confirmed it. I don't remember reason anymore, but I believe because it was messing with VAOs and VBOs. So if you are using higher than opengl 3.1 you won't get display lists anymore.