本文介绍了从一个没有窗户的Linux终端启动的OpenGL应用程序直的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一会究竟是如何去获得一个OpenGL应用程序从终端(Ubuntu服务器9.04)全屏运行直?我已经开发了我的服务器上可视化诊断的应用程序,但是,我不能完全确定让它在一个没有窗户的环境中运行的最佳方式。

How exactly would one go about getting an OpenGL app to run fullscreen straight from the terminal (Ubuntu Server 9.04)? I've developed an application for visual diagnostics on my server, but, I'm not totally sure the best way to get it to run in a windowless environment.


在理想情况下,我会运行我的程序:

Ideally, I would run my program:

./visualdiagnostics

和有推出的OpenGL应用程序。然后,通过一个简单的按Ctrl + X 键绑定,我就杀了应用程序并返回到终端。

and have that launch the OpenGL app. Then, via a simple Ctrl+X key binding, I'll kill the app and go back to the terminal.


我是否需要安装X11,然后以某种方式从程序中启动它?什么是最好的方式来检测,如果它已经运行,并启动/如果有必要停止它?

Do I need to install X11 and then somehow launch it from within the program? What would be the best way to detect if it's already running and, start/stop it if necessary?

和FYI:不,我的的试图让这个跑过来腻子或什么...我有一个监控器直接挂接到服务器。服务器已安装了正确的视频驱动程序。

And FYI: No, I'm not trying to get this to run over Putty or anything... I have a monitor hooked straight up to the server. The server has proper video drivers installed.

推荐答案

有几个部分你的任务。请记住,一些本可以非常发行专用;但因为你说的Ubuntu,我们将讨论Ubuntu的!

There are several parts to your task. Keep in mind that some of this can be very distro-specific; but since you said Ubuntu we'll talk Ubuntu!

你也标记了这个问题-c但是我开始了与一个共同的Linux模式:同一个的Bash shell脚本包装的本地应用程序。也许,一旦你得到的东西运行良好,如果你有你可能会折叠这些功能成C。

Also you tagged this question C however I am starting off with a common Linux pattern: a native application with a Bash shell script wrapper. Perhaps once you get things working well you might fold that functionality into C if you have to.

存在root用户可以有很大的帮助。有些事情是工作。

Being root can help a lot. Some things that work.


  1. 指派,Xorg的

  2. 检查 /var/lib/gdm/:0.Xauth 是否存在。这将在那里即使没有人登录,但GDM正在运行。

  3. 的ls -l /家庭/ * /。XAUTHORITY (即使你不是根用户,你至少可以确认是否的的正在运行[X]。

  1. pgrep Xorg
  2. Check whether /var/lib/gdm/:0.Xauth exists. This will be there even if nobody has logged in but GDM is running.
  3. ls -l /home/*/.Xauthority (Even if you're not root you can at least confirm whether you are running X.

您并未特别提及,但如果你是根在控制台上,或者如果您要运行的应用程序的谁已经登录相同的用户,这是pretty容易。

Piggybacking an existing X session

You did not specifically mention it but if you are root at the console, or if you want to run the app as the same user who is already logged in, it's pretty easy.

您必须得到显示 XAUTHORITY 环境变量的权利,一旦你做,你可以使用现有的X显示。

You have to get the DISPLAY and XAUTHORITY environment variables right, and once you do you can use the existing X display.

有关显示你可能只是假设 0 或你能找到一个现有的X程序(的X会话管理器是GNOME标准)和读取其环境从/ proc / PID / ENVIRON。变量是由空字节分隔的key = value格式。举例来说,如果它的PID为12345:

For DISPLAY you might just assume :0 or you could find an existing X program (x-session-manager is the GNOME standard) and read its environment from /proc/PID/environ. Variables are in key=value format delimited by a null byte. For example, if its PID is 12345:

cat /proc/12345/environ \
  | ruby -ne 'puts $_.split("\0").select {|e| e.starts_with? "DISPLAY=" }'

有关 XAUTHORITY 你可以得到同样的方式。或者,如果你preFER猜测,​​它几乎总是 /home/whoever/.Xauthority

For XAUTHORITY you could get it the same way. Or if you prefer guessing, it's almost always /home/whoever/.Xauthority

一旦你有两个变量,运行X code是容易的,例如:

Once you have those two variables, running X code is easy, for example:

env DISPLAY=:0 XAUTHORITY=/home/brian/.Xauthority ./visualdiagnostics

停止X

如果你是根这个人是很容易: /etc/init.d/gdm停止 killall的Xorg 也可以工作。

如果你是用户,杀死你自己的的Xorg X-会话管理器过程。 (我欢迎别人输入的规范办法做到这一点。也许有些DBUS发送消息?)

If you are a user, kill your own Xorg or x-session-manager process. (I'd welcome input from others for the canonical way to do this. Maybe some dbus-send message?)

我会建议 xinit ,其人生目标是火X和刚好运行一个程序。

I would recommend xinit whose goal in life is to fire X and run exactly one program.

例如: xinit ./visualdiagnostics

您也可以告诉xinit什么分辨率运行X时可能会或可能不会对你很重要。 (这一点在下面的全屏幕部分重要。)

You can also tell xinit what resolution to run X at which may or may not be important to you. (This becomes important in the full-screen section below.)

这个问题是你不会有任何的窗口管理器—没有最大化和最小化按钮。这不只是化妆品。通常一个应用程序是无用的,因为一个弹出窗口无法移动或您无法专注于正确的输入字段。但是,如果您有特殊的应用程序也可能是足够了(见下面的全屏幕)。

The problem with this is you will have no window manager— no maximize and minimize buttons. It's not just cosmetic. Usually an app is useless because a popup window cannot be moved or you cannot focus on the right input field. However if you have a special app it could be sufficient (see full-screen below).

下一步将是我的一切问题的答案:另一个shell脚本包装的!一些简单的启动窗口管理器,然后成为你的程序应该工作。

The next step would be my answer to everything: another shell script wrapper! Something simple that starts the window manager and then becomes your program should work.

#!/bin/bash
#
# Start visualdiagnostics once xinit calls me.

/usr/bin/metacity& # Or ratpoison, or fluxbox, or compiz, etc.
exec ./visualdiagnostics

对exec(成为)主程序是很重要的,因为一旦第一个程序退出时,X将关闭。

It's important to exec (become) the main program because once that first program exits, X will shut down.

我不是这个特定的100%。一些想法:

I am not 100% certain on this. Some ideas:


  • 尝试标准的X -geometry 参数设置为0,0的左上角和+ X +为你的水平和垂直大小年。你怎么知道的大小?要么你硬codeD它,当你启动 xinit 或你可以问X服务器。 xwininfo -root 会告诉你,有一个Xlib的API调用,将做到这一点—检查xwininfo源我猜

  • 您的应用程序本身可以要求最大化和/或调整,以填补屏幕。我不熟悉,但它绝对是X的API中。

  • 一些更配置窗口管理器可以pre-配置为运行你已经最大化。这可能是我个人会先检查。您的包装脚本可以创建一个 $ HOME / .fluxboxrc 只是呼应了一些硬codeD CONFIGS>该文件。

  • Try the standard X -geometry parameters to set 0,0 as the upper-left corner and +x+y for your horizontal and vertical size. How do you know the size? Either you hard-coded it when you launched xinit or you could ask the X server. xwininfo -root will tell you and there is an xlib API call that would do that too—check the xwininfo source I guess.
  • Your app itself can request maximization and/or resizing to fill the screen. I'm not familiar but it is definitely in the X API.
  • Some of the more configurable window managers can be pre-configured to run you maximized already. This is probably what I personally would check first. Your wrapper script could create a $HOME/.fluxboxrc just by echoing some hard-coded configs > the file.

其他是正确的。 X不是严格必需的正弦的OpenGL可以针对一个帧缓冲中运行。但是考虑■如何无处不是多少工作已经进入自动化它的分布,我可能会投入我的精力,因为它可能会更容易长期的,即使它是一个有点令人费解在X路线。

The others are right. X is not strictly necessary sine OpenGL can run against a framebuffer. However considering how ubiquitous X is and how much work has gone into automating it for distributions, I would probably invest my effort into the X route as it might be easier long-term even though it's a little convoluted.

(顺便说一句,我的真诚希望的,当你说终端你的意思是你在文控制台,不是的gnome-terminal 这将是可怕的!)

(By the way, I sincerely hope when you say "terminal" you mean you are at the text console, not gnome-terminal that would be awful! :)

这篇关于从一个没有窗户的Linux终端启动的OpenGL应用程序直的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 19:59