Delphi OpenGL 绘图
我像这样设置我的窗口:
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (0, form1.Width, form1.height, 0, 0, 1);
glMatrixMode (GL_MODELVIEW);
glDisable(GL_DEPTH_TEST);
我的绘图例程如下所示:
tempdist:=0.3 / distance(i,0,1,2);
xunit:=1 div 90;
zunit:=1 div 74;
glBegin(GL_LINE_LOOP);
case players[i].isteam of
2:glcolor3f(1.0,0.0,0.0); //Terrorist
3:glcolor3f(0.0,0.0,1.0); //Counter-Terrorist
end;
glvertex2f((thetax / 100)*xunit,(thetaz / 100)*zunit);
glvertex2f((thetax / 100)*xunit+tempdist,(thetaz / 100)*zunit);
glvertex2f((thetax / 100)*xunit+tempdist,(thetaz / 100)*zunit+tempdist);
glvertex2f((thetax / 100)*xunit,(thetaz / 100)*zunit+tempdist);
glEnd();
SwapBuffers(wglGetCurrentDC);
没有任何绘图迹象。有什么帮助吗?
I'm setting up my window like this:
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (0, form1.Width, form1.height, 0, 0, 1);
glMatrixMode (GL_MODELVIEW);
glDisable(GL_DEPTH_TEST);
And my drawing routine looks like this:
tempdist:=0.3 / distance(i,0,1,2);
xunit:=1 div 90;
zunit:=1 div 74;
glBegin(GL_LINE_LOOP);
case players[i].isteam of
2:glcolor3f(1.0,0.0,0.0); //Terrorist
3:glcolor3f(0.0,0.0,1.0); //Counter-Terrorist
end;
glvertex2f((thetax / 100)*xunit,(thetaz / 100)*zunit);
glvertex2f((thetax / 100)*xunit+tempdist,(thetaz / 100)*zunit);
glvertex2f((thetax / 100)*xunit+tempdist,(thetaz / 100)*zunit+tempdist);
glvertex2f((thetax / 100)*xunit,(thetaz / 100)*zunit+tempdist);
glEnd();
SwapBuffers(wglGetCurrentDC);
No sign of drawing whatsoever. Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于我们不知道您的代码中的 thetax 值是多少,您是否有可能在剪切边界之外绘制?
使用 OpenGL 进行第一次绘图通常就成功了一半。我建议去 DelphiGL 并找到一个接近您想要的示例并从那里开始工作。该网站默认为德语,但有大量的英语翻译。特别是他们有一组有用的默认模板。
As we don't know what the value of thetax is from your code is it possible you're drawing outside the clipping boundary?
Getting your first drawing up with OpenGL is quite often half of the battle. I would suggest going to DelphiGL and finding an example that is close to what you want and working from there. The site is in German by default, but there's an extensive English translation. In particular they have a useful set of default templates.
我不知道,但是在与我很久以前编写的一些 opengl 代码进行比较时:
我还使用了不同的方式来设置 dc:
并完成
I don't know, but while comparing with some opengl code I made long ago:
I also used a different way of setting up dc:
and to finish
正确设置上下文非常困难。
对于具有良好性能的可重复使用的控件,您很可能需要一个具有自己的 DC 的控件,但如果您每次绘画时都可以获得一个,则可能没问题。
看一下 http://glscene。 cvs.sourceforge.net/viewvc/glscene/Source/Platform/GLWin32Viewer.pas?view=log 查看 GLScene 如何创建可与 OpenGL 一起使用的控件。
获取自己的 DC 的关键部分是重写 CreateParams 过程并添加:
然后您可以在 CreateWnd 中获取要使用的 DC,并在 DestroyWnd 中释放
一旦获得 DC,您需要确保 PixelFormat 支持OpenGL + 具有您想要的详细信息:
使用完 RC 后,您还应该通过调用 wglDeleteContext 进行清理。
Setting up the context correctly is quite hard.
For a re-usable control with decent performance, you'll most likely want a control with it's own DC, but if you can acquire one each time you paint, you might be okay.
Take a look at http://glscene.cvs.sourceforge.net/viewvc/glscene/Source/Platform/GLWin32Viewer.pas?view=log to see how GLScene creates a control that's usable with OpenGL.
The key part in acquiring it's own DC, is overriding the CreateParams procedure + adding:
You can then get the DC to use in CreateWnd, and release in DestroyWnd
Once you've got the DC, you'll need to make sure the PixelFormat supports OpenGL + has the details you want:
After you've finished using the RC, you should also clean up by calling wglDeleteContext.