Turbo C为用户提供了一个功能很强的画图软件库http://kcliu.nyist.net/ts4.htm

本文介绍了使用TurboC进行图形编程的基础知识,包括Borland图形接口(BGI)的组成部分,图形系统的初始化过程,以及如何正确配置和使用图形驱动程序以确保图形程序能够顺利运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

                  图形程序运行的条件

Turbo C为用户提供了一个功能很强的画图软件库,它又称为BorLand图形接口(BGI),它包括图形库文件(graphics.lib),图形头文件(graphics.h)和许多图形显示器(图形终端)的驱动程序(如CGA.BGIEGAVGA.BGI等)。还有一些字符集的字体驱坳程序(如goth.chr黑体字符集等)。编写图形程序时用到的一些图形库函数均在graphics.lib 中,执行这些函数时,所需的有关信息(如宏定义等)则包含在graphics.h头文件中。因此用户在自已的画图源程序中必须包括graphics.h头文件,在进行目标程序连接时,要将graphics.lib连接到自己的目标程序中去。

                  图形系统的初始化

   在编制图形程序时,进入图形方式前,首先要在程序中对使用的图形系统初始化,即要用什么类型的图形显示适配器的驱动程序,采用什么模式的图形方式(也就是相应程序的入口地址),以及该适配器驱动程序的寻找路径名。所用系统的显示适配器一定要支持所选用的显示模式,否则将出错。Turbo.C提供了一个图形系统初始化函数initgraph可完成这些功能。

图形系统的初始化函数

void far initgraph(int far *driver, int far *mode, char for path-for-driver);当我们使用的存储模式为tiny(微型)、 small(小型)或medium(中型)时,不需要远指针,因而可以将初始化函数调用格式写成如下形式(该说明适用于后面所述的任一函数):  intitgrapg(&graphdriver, &graphmode,,””);  其中驱动程序目录路径为空字符“”时,表示就在当前目录下,参数graphmode用所示的模式号或标示符来定义,参数graphdriver是一个枚举变量{DETECT,CGA,VGA,…},一般: graphdriver=DETECT

一旦执行了初始化,显示器即被设置成相应模式的图形方式。下面是某画图程序的开始部分,它包括对图形系统的初始化:

#include”graphics.h”

main()

{

int graphdriver=DETECT;

int graphmode;

intgraph(& graphdriver, & graphmode,””);

上面初始化过程中,将由DETECT检测所用适配器类型,并将当前目录下相应的驱动程序装入,并采用最高分辩率显示模式作为graphmode的值。如检测到为CGA适配器时,则graphmode等于4或为CGAHI,若检测到VGA适配器,则graphmode等于2或为VGAHI

       图形程序运行的条件

由于图形程序运行并显示图象直接与显示器有关,而如何控制驱动显示器进行显示,Tubro C并没有向用户提供这种技术,而这也是不必要的,因它与显示器硬件结构息息相关,编程者并不需要知道这些东西,否则太复杂了!但用户的图形程序要能运行并显示,则必须要包含有驱动显示器的这种程序。不同种类的显示器因硬件结构不同,因而驱动程序也不同,这些驱动程序已经在Tubro C系统盘上提供。在用户的图形程序中,进行图形系统初始化时,即执行函数。

initgraph(&graphdriver,&graphmode,char path-for-driver);

时,程序就按照path-for-driver所指的路径将图形驱动程序装入内存。这样,以后的图形功能才能被支持。若在所指路径下找不到相应显示器的驱动程序,或没有对驱动程序进行装入操作,则运行图形程序时,就会在屏幕上显示出错信息:

BGI  Error: Graphics not initialized(use”initgraph”)

Tubro C20安装在软盘上时,没有安装上图形驱动程序(如CGABGIEGAVGA.BGI等),所以必须在工作盘上复制上这些文件,否则图形程序就无法运行,而出现上述的错误信息。

那么,能不能不用egavga.bgi而运行图形程序,用以下步骤就可以:

/tc/bgiobj egavga

/tc/tlib lib/graphics.lib+egavga.obj

编程序时在用initgraph()之前先调用registerbgidriver(EGAVGA_driver);

 

 
(base) lxy@lxy-Legion-Y9000P-IAH7H:~$ sudo add-apt-repository ppa:apt-fast/stable sudo apt update sudo apt install apt-fast [sudo] lxy 的密码: 源: 'deb https://ppa.launchpadcontent.net/apt-fast/stable/ubuntu/ jammy main' 描述: This PPA contains tested (stable) builds of apt-fast. Project: https://github.com/ilikenwf/apt-fast 更多信息:https://launchpad.net/~apt-fast/+archive/ubuntu/stable 正在添加源。 按 [ENTER] 继续,或按 Ctrl-c 取消。 Adding deb entry to /etc/apt/sources.list.d/apt-fast-ubuntu-stable-jammy.list Adding disabled deb-src entry to /etc/apt/sources.list.d/apt-fast-ubuntu-stable-jammy.list Adding key to /etc/apt/trusted.gpg.d/apt-fast-ubuntu-stable.gpg with fingerprint BC5934FD3DEBD4DAEA544F791E2824A7F22B44BD 命中:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy InRelease 获取:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates InRelease [128 kB] 获取:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports InRelease [127 kB] 获取:4 https://dl.google.com/linux/chrome/deb stable InRelease [1,825 B] 获取:5 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security InRelease [129 kB] 获取:7 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/main amd64 DEP-11 Metadata [114 kB] 错误:4 https://dl.google.com/linux/chrome/deb stable InRelease 由于没有公钥,无法验证下列签名: NO_PUBKEY 32EE5355A6BC6E42 获取:8 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/restricted amd64 DEP-11 Metadata [212 B] 获取:9 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/universe amd64 DEP-11 Metadata [359 kB] 获取:10 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/multiverse amd64 DEP-11 Metadata [940 B] 获取:11 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports/main amd64 DEP-11 Metadata [7,064 B] 获取:12 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports/restricted amd64 DEP-11 Metadata [212 B] 获取:13 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports/universe amd64 DEP-11 Metadata [24.2 kB] 获取:14 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports/multiverse amd64 DEP-11 Metadata [212 B] 获取:15 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security/main amd64 DEP-11 Metadata [54.6 kB] 获取:16 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security/restricted amd64 DEP-11 Metadata [208 B] 获取:17 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security/universe amd64 DEP-11 Metadata [125 kB] 获取:18 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security/multiverse amd64 DEP-11 Metadata [208 B] 命中:6 https://packages.microsoft.com/repos/code stable InRelease 获取:19 https://ppa.launchpadcontent.net/apt-fast/stable/ubuntu jammy InRelease [18.3 kB] 忽略:20 https://deepin-wine.i-m.dev InRelease 获取:21 https://ppa.launchpadcontent.net/apt-fast/stable/ubuntu jammy/main amd64 Packages [536 B] 命中:22 https://deepin-wine.i-m.dev Release 获取:23 https://ppa.launchpadcontent.net/apt-fast/stable/ubuntu jammy/main i386 Packages [536 B] 获取:24 https://ppa.launchpadcontent.net/apt-fast/stable/ubuntu jammy/main Translation-en [272 B] 忽略:25 https://deepin-wine.i-m.dev Release.gpg 已下载 1,090 kB,耗时 3秒 (364 kB/s) 正在读取软件包列表... 完成 W: 校验数字签名时出错。此仓库未被更新,所以仍然使用此前的索引文件。GPG 错误:https://dl.google.com/linux/chrome/deb stable InRelease: 由于没有公钥,无法验证下列签名: NO_PUBKEY 32EE5355A6BC6E42 W: 无法下载 https://dl.google.com/linux/chrome/deb/dists/stable/InRelease 由于没有公钥,无法验证下列签名: NO_PUBKEY 32EE5355A6BC6E42 W: 部分索引文件下载失败。如果忽略它们,那将转而使用旧的索引文件。 命中:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy InRelease 命中:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates InRelease 命中:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports InRelease 命中:4 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security InRelease 获取:6 https://dl.google.com/linux/chrome/deb stable InRelease [1,825 B] 错误:6 https://dl.google.com/linux/chrome/deb stable InRelease 由于没有公钥,无法验证下列签名: NO_PUBKEY 32EE5355A6BC6E42 命中:5 https://packages.microsoft.com/repos/code stable InRelease 命中:7 https://ppa.launchpadcontent.net/apt-fast/stable/ubuntu jammy InRelease 忽略:8 https://deepin-wine.i-m.dev InRelease 命中:9 https://deepin-wine.i-m.dev Release 忽略:10 https://deepin-wine.i-m.dev Release.gpg 正在读取软件包列表... 完成 正在分析软件包的依赖关系树... 完成 正在读取状态信息... 完成 有 275 个软件包可以升级。请执行 ‘apt list --upgradable’ 来查看它们。 W: 校验数字签名时出错。此仓库未被更新,所以仍然使用此前的索引文件。GPG 错误:https://dl.google.com/linux/chrome/deb stable InRelease: 由于没有公钥,无法验证下列签名: NO_PUBKEY 32EE5355A6BC6E42 W: 无法下载 https://dl.google.com/linux/chrome/deb/dists/stable/InRelease 由于没有公钥,无法验证下列签名: NO_PUBKEY 32EE5355A6BC6E42 W: 部分索引文件下载失败。如果忽略它们,那将转而使用旧的索引文件。 正在读取软件包列表... 完成 正在分析软件包的依赖关系树... 完成 正在读取状态信息... 完成 下列软件包是自动安装的并且现在不需要了: apport-symptoms gdb libbabeltrace1 libboost-regex1.74.0 libc6-dbg libdebuginfod-common libdebuginfod1 libipt2 libsource-highlight-common libsource-highlight4v5 nvidia-firmware-535-535.183.01 python3-systemd 使用'sudo apt autoremove'来卸载它(它们)。 将会同时安装下列软件: aria2 libaria2-0 libc-ares2 libssh2-1 建议安装: aptitude zsh fish 下列【新】软件包将被安装: apt-fast aria2 libaria2-0 libc-ares2 libssh2-1 升级了 0 个软件包,新安装了 5 个软件包,要卸载 0 个软件包,有 275 个软件包未被升级。 需要下载 1,661 kB 的归档。 解压缩后会消耗 5,948 kB 的额外空间。 您希望继续执行吗? [Y/n] y 获取:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/main amd64 libc-ares2 amd64 1.18.1-1ubuntu0.22.04.3 [45.1 kB] 获取:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 libssh2-1 amd64 1.10.0-3 [109 kB] 获取:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 libaria2-0 amd64 1.36.0-1 [1,086 kB] 获取:4 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 aria2 amd64 1.36.0-1 [381 kB] 获取:5 https://ppa.launchpadcontent.net/apt-fast/stable/ubuntu jammy/main amd64 apt-fast all 1.11.1-1~ubuntu22.04.1 [38.5 kB] 已下载 1,661 kB,耗时 2秒 (1,075 kB/s) 正在预设定软件包 ... 正在选中未选择的软件包 libc-ares2:amd64。 (正在读取数据库 ... 系统当前共安装有 240215 个文件和目录。) 准备解压 .../libc-ares2_1.18.1-1ubuntu0.22.04.3_amd64.deb ... 正在解压 libc-ares2:amd64 (1.18.1-1ubuntu0.22.04.3) ... 正在选中未选择的软件包 libssh2-1:amd64。 准备解压 .../libssh2-1_1.10.0-3_amd64.deb ... 正在解压 libssh2-1:amd64 (1.10.0-3) ... 正在选中未选择的软件包 libaria2-0:amd64。 准备解压 .../libaria2-0_1.36.0-1_amd64.deb ... 正在解压 libaria2-0:amd64 (1.36.0-1) ... 正在选中未选择的软件包 aria2。 准备解压 .../aria2_1.36.0-1_amd64.deb ... 正在解压 aria2 (1.36.0-1) ... 正在选中未选择的软件包 apt-fast。 准备解压 .../apt-fast_1.11.1-1~ubuntu22.04.1_all.deb ... 正在解压 apt-fast (1.11.1-1~ubuntu22.04.1) ... 正在设置 libc-ares2:amd64 (1.18.1-1ubuntu0.22.04.3) ... 正在设置 libssh2-1:amd64 (1.10.0-3) ... 正在设置 libaria2-0:amd64 (1.36.0-1) ... 正在设置 aria2 (1.36.0-1) ... 正在设置 apt-fast (1.11.1-1~ubuntu22.04.1) ... 正在处理用于 man-db (2.10.2-1) 的触发器 ... 正在处理用于 libc-bin (2.35-0ubuntu3.10) 的触发器 ... (base) lxy@lxy-Legion-Y9000P-IAH7H:~$ sudo apt-fast install ttf-mscorefonts-installer 正在读取软件包列表... 完成 正在分析软件包的依赖关系树... 完成 正在读取状态信息... 完成 ttf-mscorefonts-installer 已经是最新版 (3.8ubuntu2)。 下列软件包是自动安装的并且现在不需要了: apport-symptoms gdb libbabeltrace1 libboost-regex1.74.0 libc6-dbg libdebuginfod-common libdebuginfod1 libipt2 libsource-highlight-common libsource-highlight4v5 nvidia-firmware-535-535.183.01 python3-systemd 使用'sudo apt autoremove'来卸载它(它们)。 升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 275 个软件包未被升级。
最新发布
07-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值