c++ 中的直线

发布于 2024-12-12 08:30:49 字数 70 浏览 0 评论 0原文

Windows 提供哪些库来绘制线条?我只对 2D 库感兴趣,而不是 OpenGL 或 DirectX。我正在 C++ 工作。

What libraries does Windows provide to draw lines? I am only interested in 2D libraries, not OpenGL or DirectX. I am working in C++.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冷了相思 2024-12-19 08:30:49
cout << ".------------------------------------------------------------." << endl;

cout << ".\n\
         |\n\
         |\n\
         |\n\
         |\n\
         |\n\
         |\n\
         |\n\
         |\n\
         |\n\
         |\n\
         ." << endl;

编辑:忘记了点。

编辑2:对角线:

for( int i=0; i<10; i++ )
{
    for( int j=0; j<10; j++ )
    {       
        if( i == j )
        {
            for( int k=0; k<i; k++ )
            {
                cout << " ";
            }

            if( i == 0 || i == 9 )
            {
                cout << ".\n";
            }
            else
            {
                cout << "\\\n";
            }
        }
    }       
}
cout << ".------------------------------------------------------------." << endl;

cout << ".\n\
         |\n\
         |\n\
         |\n\
         |\n\
         |\n\
         |\n\
         |\n\
         |\n\
         |\n\
         |\n\
         ." << endl;

EDIT: Forgot the dots.

EDIT 2: Diagonal:

for( int i=0; i<10; i++ )
{
    for( int j=0; j<10; j++ )
    {       
        if( i == j )
        {
            for( int k=0; k<i; k++ )
            {
                cout << " ";
            }

            if( i == 0 || i == 9 )
            {
                cout << ".\n";
            }
            else
            {
                cout << "\\\n";
            }
        }
    }       
}
棒棒糖 2024-12-19 08:30:49

取决于您的平台。

在 Windows 中,您可以使用 GDI 或 GDI+。

对于 Mac OS,我确信 Carbon 和 Cocoa 都提供了这个功能 - 尽管我承认对这两个 API 知之甚少。

Qt 提供跨平台绘图库,可在任何 Linux、Windows 或 Mac 上运行。

编辑:

Direct2D 是 Windows 的另一个 C++ 选项。它也是完全硬件加速的,这很酷。至于在全屏窗口上绘图,与在常规窗口中绘图没有什么不同。您只需要一些额外的代码即可最大化窗口并将其设置为全屏模式。

Depends on your platform.

In Windows you could use GDI or GDI+.

For Mac OS I'm sure both Carbon and Cocoa provide this feature - though I confess to having little knowledge of either API.

Qt provides cross-platform drawing libraries that will work on any of Linux, Windows or Mac.

EDIT:

Direct2D is another C++ option for Windows. It's fully hardware accelerated too which is cool. As for drawing on a fullscreen window, it's no different than drawing in a regular window. You'll just need some extra code to maximize the window and set it to fullscreen mode.

缱倦旧时光 2024-12-19 08:30:49

这取决于。你用的是什么系统?你想怎么画它? 3D 还是 2D?你想要全屏吗?

老实说,OpenGL 与 GLUT 这样的库一起使用非常容易。设置完成后,所需要的就是

glBegin(GL_LINES);
    //Vertex pair
    glVertex2f(...);
    glVertex2f(...);
glEnd();

(纯粹主义者会因为我使用 3.0 标准中不存在的 OpenGL 形式而对我大喊大叫,但我认为这不是一个需要长期向前兼容的主要项目)。

我想到的另外两个快速库:

  1. SDL
    听起来像您的库:它有快速设置、大量教程,而且是纯 C 语言。不幸的是,您必须使用另一个库(即 SDL_Draw)来实际绘制线条。
  2. 快板
    几年前我使用过这个库,但从那以后就没有使用过。我的记忆是它在形式和功能上很像SDL。它在 Windows 上运行良好,但不像 OS X 上的 SDL 那么容易。Allegro 确实(!)有一个内置的线条绘制函数,称为 line()(喜欢这个简洁性)。

It depends. What system are you on? How would you like to draw it? In 3D or 2D? Do you want fullscreen?

Honestly, OpenGL is pretty easy to use with a library like GLUT. After you set it up, all it takes is

glBegin(GL_LINES);
    //Vertex pair
    glVertex2f(...);
    glVertex2f(...);
glEnd();

(Purists will yell at me for using a form of OpenGL that isn't around in the 3.0 standard, but I assume this isn't a major project needing forward-compatibility for a long time).

Two other quick libraries that come to mind:

  1. SDL
    Sounds like your library: it has quick setup, lots of tutorials, and it's plain C. Unfortunately, you'll have to use another library (i.e. SDL_Draw) to actually draw the line.
  2. Allegro
    I used this library a few years ago, but not since then. My recollection is that it's a lot like SDL in form and function. It works well on Windows, but is not as easy as SDL on OS X. Allegro does(!) have a built in line drawing function called line() (gotta love that brevity).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文