如何在我的 C++ 程序中获取和使用头文件 <graphics.h>?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7860569/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 17:37:14  来源:igfitidea点击:

How I can get and use the header file <graphics.h> in my C++ program?

c++graphics

提问by CompilingCyborg

I have been searching to get the source code of the header file <graphics.h>and its associated library in order to integrate it with my C++ program.

我一直在寻找头文件<graphics.h>及其相关库的源代码,以便将其与我的 C++ 程序集成。

At the same time, I am interested in those cross-platform libraries that works on more than one compiler. Just to be more explicit, I am talking about those libraries that are used for drawing shapes, lines, and curves in C++.

同时,我对那些适用于多个编译器的跨平台库感兴趣。更明确地说,我说的是那些用于在 C++ 中绘制形状、线条和曲线的库。

回答by ammar26

<graphics.h>is very old library. It's better to use something that is new

<graphics.h>是非常古老的图书馆。最好使用新的东西

Here are some 2D libraries (platform independent) for C/C++

下面是一些用于 C/C++ 的 2D 库(平台无关)

SDL

SDL

GTK+

GTK+

Qt

Qt

Also there is a free very powerful 3D open source graphics library for C++

还有一个免费的非常强大的 C++ 3D 开源图形库

OGRE

食人魔

回答by Calmarius

There is a modern port for this Turbo C graphics interface, it's called WinBGIM, which emulates BGI graphics under MinGW/GCC.

这个 Turbo C 图形界面有一个现代端口,称为WinBGIM,它在 MinGW/GCC 下模拟 BGI 图形。

I haven't it tried but it looks promising. For example initgraphcreates a window, and from this point you can draw into that window using the good old functions, at the end closegraphdeletes the window. It also has some more advanced extensions (eg. mouse handling and double buffering).

我还没有尝试过,但看起来很有希望。例如initgraph创建一个窗口,从这一点开始,您可以使用旧函数绘制到该窗口中,最后closegraph删除该窗口。它还具有一些更高级的扩展(例如鼠标处理和双缓冲)。

When I first moved from DOS programming to Windows I didn't have internet, and I begged for something simple like this. But at the end I had to learn how to create windows and how to handle events and use device contexts from the offline help of the Windows SDK.

当我第一次从 DOS 编程转向 Windows 时,我没有互联网,我乞求像这样简单的东西。但最后我必须从 Windows SDK 的离线帮助中学习如何创建窗口以及如何处理事件和使用设备上下文。

回答by Clifford

<graphics.h>is not a standard header. Most commonly it refers to the header for Borland's BGI API for DOS and is antiquated at best.

<graphics.h>不是标准标题。最常见的是它指的是用于 DOS 的 Borland 的 BGI API 的标头,并且充其量是过时的。

However it is nicely simple; there is a Win32 implementation of the BGI interface called WinBGIm. It is implemented using Win32 GDI calls - the lowest level Windows graphics interface. As it is provided as source code, it is perhaps a simple way of understanding how GDI works.

然而,它非常简单;有一个名为WinBGIm的 BGI 接口的 Win32 实现。它是使用 Win32 GDI 调用实现的 - 最低级别的 Windows 图形界面。由于它是作为源代码提供的,因此它可能是理解 GDI 工作原理的一种简单方法。

WinBGIm however is by no means cross-platform. If all you want are simple graphics primitives, most of the higher level GUI libraries such as wxWidgets and Qt support that too. There are simpler libraries suggested in the possible duplicate answers mentioned in the comments.

然而,WinBGIm 绝不是跨平台的。如果您只需要简单的图形基元,那么大多数更高级别的 GUI 库(例如 wxWidgets 和 Qt)也都支持。在评论中提到的可能的重复答案中建议了更简单的库。

回答by Cheers and hth. - Alf

[graphics.h] appears to something once bundled with Borland and/or Turbo C++, in the 90's.

[graphics.h] 似乎是 90 年代曾经与 Borland 和/或 Turbo C++ 捆绑在一起的东西。

http://www.daniweb.com/software-development/cpp/threads/17709/88149#post88149

http://www.daniweb.com/software-development/cpp/threads/17709/88149#post88149

It's unlikely that you will find any support for that file with modern compiler. For other graphics libraries check the list of "related" questions (questions related to this one). E.g., "A Simple, 2d cross-platform graphics library for c or c++?".

您不太可能使用现代编译器找到对该文件的任何支持。对于其他图形库,请检查“相关”问题列表(与此相关的问题)。例如,“一个用于 c 或 c++ 的简单的 2d 跨平台图形库?” .

Cheers & hth.,

干杯 & hth.,