简体   繁体   English

无法在Raspberry Pi上用C ++绘制

[英]Unable to Draw in C++ on Raspberry Pi

I have, thanks to some help, managed to get the program below to compile and run but although it keeps on chugging away I cannot see anything drawn on the Pi's screen. 多亏了一些帮助,我设法将下面的程序编译并运行了,但是尽管它一直在忙碌着,但我在Pi的屏幕上看不到任何东西。

I don't think that it is a problem unique to the use of openvg and ajstarks code as, during the problem I had compiling the test progam , I tried a different way of writing images (sorry, all I remember was that it was low level and didn't need the includes for openvg). 我不认为这是使用openvg和ajstarks代码所独有的问题,因为在该问题中,我编译了测试程序 ,尝试了另一种写图像的方式(对不起,我只记得它很低)级别,并且不需要包含openvg)。 It took a bit of searching and re-writing to get it to compile and when it did the same thing happened. 进行了一些搜索和重新编写后才能进行编译,并且当它执行相同操作时发生了。

I persevered for a while, but got no where. 我坚持了一段时间,但无处可去。 There were some references to some sort of limitation with Raspberry Pi and X Windows leading to the same problem. 有一些参考提到了Raspberry Pi和X Windows的某种限制会导致相同的问题。 You draw something but it doesn't display. 您绘制了一些东西,但是它没有显示。 Given that there were several comments suggesting that openvg worked, I went back to that and (thanks to a guy called Ross) eventually worked out why I couldn't compile the code. 鉴于有一些意见表明openvg可以正常工作,我回到了这一点,并且(感谢一个叫Ross的人)最终弄清楚了为什么我不能编译代码。

So now I am at a point where I can compile code that others have got to run successfully, but it doesn't draw anything on the screen. 因此,现在我可以编译其他人必须成功运行的代码,但它不会在屏幕上绘制任何内容。 I know that the code runs - it chews CPU cycles (well the official demo does, mine less so although it's still definitly going) and the code can be quit with 我知道代码可以运行-它咀嚼CPU周期(官方演示确实如此,虽然可以确定运行,但挖掘得更少了),并且可以退出该代码

Another method of working with graphics has come across the same no-output-display problem, so I think the problem is somewhere on my Pi but I have drawn a blank on how to address the X Windows (or it might have been X11, wish I had kept the tabs open!) not wanting to draw issue. 使用图形的另一种方法也遇到了相同的无输出显示问题,所以我认为问题出在我的Pi上,但我在如何解决X Windows上画了一个空白(希望它可能是X11)我一直打开选项卡!)不想画问题。

Any help greatly appreciated, thanks in advance! 任何帮助,不胜感激,在此先感谢!

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

extern "C" {
#include "VG/openvg.h"
#include "VG/vgu.h"
#include "fontinfo.h"
#include "shapes.h"
}

using namespace std;

int main (void) {

int width, height;
        VGfloat w2, h2, w;
    char s[3];

    init(&width, &height);                                      // Graphics initialization

    w2 = (VGfloat)(width/2);
    h2 = (VGfloat)(height/2);
    w  = (VGfloat)w;

    Start(width, height);                                       // Start the picture
    Background(0, 0, 0);                                        // Black background
    Fill(44, 77, 232, 1);                                       // Big blue marble
    Circle(w2, 0, w);                                           // The "world"
    Fill(255, 255, 255, 1);                                     // White text
    TextMid(w2, h2, "hello, world", SerifTypeface, width/10);   // Greetings
    End();                                                      // End the picture
    fgets(s, 2, stdin);                                         // Pause until RETURN]
    finish();                                                   // Graphics cleanup
    exit(0);
}

Ok... 好...

Thanks to a stroke of luck I have found the answer and it's odd. 多亏了运气,我找到了答案,这很奇怪。 To me anyway... 反正对我来说

In case anyone else encouters the problem, here is the (partial) solution which leads to another question to be posted shortly. 万一其他人遇到问题,这里是(部分)解决方案,这会导致另一个问题很快就会发布。

I am trying to run a programming club in my school and it's not practical to physically connect the Pi's to kb, mouse and monitor so they all auto-run VNC and we connect to the machines using Ultra-VNC. 我试图在学校里运行一个编程俱乐部,将Pi物理连接到kb,鼠标和显示器是不切实际的,因此它们都可以自动运行VNC,而我们使用Ultra-VNC连接到计算机。 The programs are written in a shared directory and Eclipse C++ runs on the host; 这些程序被写在一个共享目录中,并且Eclipse C ++在主机上运行。 therefore all program output is viewed via VNC. 因此,所有程序输出均通过VNC查看。

I had been continuing to try to solve the problem and at one point connected a keyboard and mouse and noticed that they seemed to be recognised (laser came on, Caps Lock toggled, etc.) but they didn't do anything when moved/typed on. 我一直在继续尝试解决问题,有一次我连接了键盘和鼠标,并注意到它们似乎可以被识别(出现了激光,按下了Caps Lock键等),但是在移动/打字时它们什么也没做上。

Eventually the penny began to teater on the edge as I got increasingly confused as to why no one else was having this problem. 最终,随着我越来越困惑为什么没有其他人遇到这个问题,一分钱便开始在边缘冒出来。 Is seemed odd that no one else had the issue and then I began to wonder more about the kb/mouse issue. 没有人遇到这个问题似乎很奇怪,然后我开始对kb / mouse问题产生更多的疑问。

I tried plugging the HDMI output into a monitor at home (shool ones are still analogue d-sub!) and lo and behold, the physical kb and mouse worked. 我尝试将HDMI输出插入家用显示器(学校的仍然是模拟d-sub!),瞧瞧,物理kb和鼠标都能正常工作。 Then it got really strange! 然后真的很奇怪!

Somehow I have 2 desktops running at the same time. 不知何故,我有2个台式机同时运行。 The physical keyboard and mouse control one and VNC controls the other. 物理键盘和鼠标控制一个,而VNC控制另一个。 Interestingly, VNC has the title Pi's X Desktop suggesting that the graphics problem might be something to do with X, but I am not sure for the reason below. 有趣的是,VNC的标题为Pi的X桌面,表明图形问题可能与X有关,但由于以下原因,我不确定。

If I start a terminal window on 'Physical' desktop, it doesn't show up on 'VNC' desktop and vice versa - they seem to be independent, although that's not quite true. 如果我在“物理”桌面上启动终端窗口,则该窗口不会显示在“ VNC”桌面上,反之亦然-它们似乎是独立的,尽管并非如此。

When I run the test file on 'Physical' desktop, it works fine and can be controlled only using the physical kb. 当我在“物理”桌面上运行测试文件时,它工作正常,并且只能使用物理kb进行控制。 When I run it on 'VNC' desktop, it can be controlled only with the VNC kb but the output displays on the physical screen. 当我在“ VNC”桌面上运行它时,只能用VNC kb对其进行控制,但输出将显示在物理屏幕上。

I really don't get this! 我真的不明白!

So, this answers the original question as the program does run on the Pi. 因此,由于程序确实在Pi上运行,因此可以回答原始问题。

Off to post (hopefully a final) question on how to either get VNC to show the 'Physical' desktop or how to target the graphics output to the 'correct' desktop. 下一个问题(希望是最后一个问题),发布有关如何使VNC显示“物理”桌面或如何将图形输出定向到“正确”桌面的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM