为 Linux 开发一个简单的窗口应用程序
好的,我想为 Linux(例如带有 Gnome 的 Ubuntu)编写一个简单的 C 应用程序,它将执行以下操作:
- 打开一个窗口
- 使用主循环在该窗口中绘制一些内容,例如当前循环编号。我不想使用控件,而是直接在窗口表面上绘制
- 关闭窗口& 我可以在 Windows 中执行该应用程序
,但我不知道如何在 Linux 中执行此操作。
谢谢!
Okay, I'd like to write a simple C app for Linux (say Ubuntu with Gnome) that would do the following:
- Open a Window
- Draw something in that window using a main loop, e.g. the current loop number. I don't want to use controls, but to draw directly on the window surface
- Close the window & the app
I can do that in Windows, but I've no idea how I could do that in Linux.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
除非你想要一个成熟的 GUI(在这种情况下我推荐 Qt 或 GTK),然后 SDL 是一个非常流行且极其简单的免费跨平台库,为您提供绘图界面和一些简单的 IO 设施。它本身是 C 语言,但与大量其他语言有绑定。
Unless you want a full-blown GUI (in which case I'd recommend Qt or GTK), then SDL is a very popular and extremely simple free cross-platform library that gives you a drawing surface and some simple IO facilities. It's natively C, but has bindings to a large number of other languages.
有各种用于 X11 编程的“Hello World”示例。
使用 GTK+:
http://library.gnome.org/devel/gtk-tutorial/2.13 /c39.html
使用 Qt:
http://doc.qt.nokia.com/latest/tutorials-widgets -toplevel.html
使用wxWidgets:
http://www.wxwidgets.org/docs/tutorials/hello.htm
还有更多的工具包:Fox、FLTK、Tk、EFL ...
到目前为止,这些都是跨平台的,所以让我们看一下特定于 X11 的示例:
这是使用 Xlib:
http://en.literateprograms.org/Special:Downloadcode/Hello_World_(C ,_Xlib)
这是使用 Xcb:
http://xcb.freedesktop.org/tutorial/basicwindowsanddrawing/
There are various "Hello World" examples for X11 programming.
Using GTK+:
http://library.gnome.org/devel/gtk-tutorial/2.13/c39.html
Using Qt:
http://doc.qt.nokia.com/latest/tutorials-widgets-toplevel.html
Using wxWidgets:
http://www.wxwidgets.org/docs/tutorials/hello.htm
There are a lot more toolkits: Fox, FLTK, Tk, EFL ...
So far these have all been cross-platform, so let's have a look at X11-specific exampls:
This is using Xlib:
http://en.literateprograms.org/Special:Downloadcode/Hello_World_(C,_Xlib)
And this is using Xcb:
http://xcb.freedesktop.org/tutorial/basicwindowsanddrawing/
如果你只想画一些东西,为什么不直接使用 OpenGL 和 GLUT。后者提供了使用 OpenGL 上下文创建窗口的简单方法。
设置 GLUT 应用程序非常简单,并且有很多教程,例如 Lighthouse3d.com。本教程适用于 Visual Studio,但将其转换为在 Linux 上编译应用程序并不困难。
或者,您也可以使用 Qt,这是一个更高级且易于使用的 GUI 工具包,并且不一定需要您编写 OpenGL 代码。
If you only want to draw something, why not just use OpenGL and GLUT. The latter provides simple methods to create a window with an OpenGL context.
Setting up a GLUT application is very straighforward and there are lots of tutorials out there , e.g. Lighthouse3d.com. This tutorial works with visual studio, but it's not hard to translate this to compiling an application on Linux.
Alternatively, you could also work with Qt, which is a more advanced and easy to use GUI toolkit, and which would not necessarily require you to write OpenGL code.
既然你提到了 C,如果你想使用 GTK+ 作为一个不错的小编辑器,可以使用 Glade将控件绘制到窗口上。
或者,如果您可以访问 C++ 编译器,则可以查看 Qt,它提供了类似的功能。
Since you mentioned C, there is Glade if you want to make use of GTK+ for a nice little editor that allows you to draw controls onto a window.
Alternatively if you have access to a C++ compiler you can have a look at Qt which provides similar functionality.
好吧,如果您熟悉在 Windows 中制作 GUI 应用程序,我会猜测您已经使用 .net 或类似的东西完成了它。一个简单的过渡是使用单声道。跨平台 .NET 开发平台 - http://mono-project.com/Main_Page
还有一个使用的各种 gui 工具包: http://www.mono-project.com/Gui_Toolkits
Well, if you're familiar with making gui apps in windows I'm going to take a guess that you've done it with .net or something similar. An easy transition would be to use mono. A cross platform .NET development platform - http://mono-project.com/Main_Page
There's also has a variety gui toolkits to use: http://www.mono-project.com/Gui_Toolkits
如果你想直接在窗口上绘制,你考虑过X11吗?
它不会像使用 GTK 或 Qt 这样的工具包那么好,但它大约是您可以在窗口系统中获得的最低级别。
我没有任何直接 X11 编程的经验,所以我不能推荐任何起始材料。
If you want to draw directly onto the window, have you considered X11?
It's not going to be as nice as working with a toolkit like GTK or Qt, but it's about as low level as you can get in the windowing system.
I don't have any experience with programming straight X11, so I can't recommend any starting material.