显卡所处理的信息最终都要输出到显示器上,显卡的输出接口就是电脑与显示器之间的桥梁,它负责向显示器输出相应的图像信号。CRT显示器因为设计制造上的原因,只能接受模拟信号输入,这就需要显卡能输入模拟信号。VGA接口就是显卡上输出模拟信号的接口,VGA(Video Graphics Array)接口,也叫D-Sub接口。虽然液晶显示器可以直接接收数字信号,但很多低端产品为了与VGA接口显卡相匹配,因而采用VGA接口。VGA接口是一种D型接口,上面共有15针空,分成三排,每排五个。VGA接口是显卡上应用最为广泛的接口类型,绝大多数的显卡都带有此种接口。
目前大多数计算机与外部显示设备之间都是通过模拟VGA接口连接,计算机内部以数字方式生成的显示图像信息,被显卡中的数字/模拟转换器转变为R、G、B三原色信号和行、场同步信号,信号通过电缆传输到显示设备中。对于模拟显示设备,如模拟CRT显示器,信号被直接送到相应的处理电路,驱动控制显像管生成图像。而对于LCD、DLP等数字显示设备,显示设备中需配置相应的A/D(模拟/数字)转换器,将模拟信号转变为数字信号。在经过D/A和A/D2次转换后,不可避免地造成了一些图像细节的损失。VGA接口应用于CRT显示器无可厚非,但用于连接液晶之类的显示设备,则转换过程的图像损失会使显示效果略微下降。
#include"stdio.h"#include"dos.h"#include<conio.h>#include<math.h>#include<math.h>#include<graphics.h>unsigned long pre_cale_y2[480];typedef unsigned char byte;union REGS reg;struct SREGS inreg;typedef struct{byte red;byte grn;byte blu;}rgb;
typedef rgb palette_Register[256];
void set_palette(palette_Register hue){reg.x.ax=0x1012;segread(&inreg);inreg.es=inreg.ds;reg.x.bx=0;reg.x.cx=256;reg.x.dx=(int)&hue[0];int86x(0x10,®,®,&inreg);}void init_palette_2(palette_Register color){int i;for(i=0;i<36;i++){color[i].red=0;color[i].grn=0;color[i].blu=(int)(1.8*i+0.5);}for(i=36;i<72;i++){color[i].red=0;color[i].grn=(int)(1.8*(i-36)+0.5);color[i].blu=0;}for(i=72;i<108;i++){color[i].red=0;color[i].grn=(int)(1.8*(i-72)+0.5);color[i].blu=(int)(1.8*(i-72)+0.5);}for(i=108;i<144;i++){color[i].red=(int)(1.8*(i-108)+0.5);color[i].grn=0;color[i].blu=0;}for(i=144;i<180;i++){color[i].red=(int)(1.8*(i-144)+0.5);color[i].grn=0;color[i].blu=(int)(1.8*(i-144)+0.5);}for(i=180;i<216;i++){color[i].red=(int)(1.8*(i-180)+0.5);color[i].grn=(int)(1.8*(i-180)+0.5);color[i].blu=0;}for(i=216;i<252;i++){color[i].red=(int)(1.8*(i-216)+0.5);color[i].grn=(int)(1.8*(i-216)+0.5);color[i].blu=(int)(1.8*(i-216)+0.5);}}void precale(){unsigned int j;for(j=0;j<480;j++){pre_cale_y2[j]=640*j;}}void plot(int x,int y,char color){long L_offset;int offset,page;char far *address;precale();if((x<640)&&(y<480)){L_offset=pre_cale_y2[y]+x;page=(L_offset>>16);offset=L_offset&65535;outportb(0x3c4,0xe);outportb(0x3c5,(page&0xf)^0x2);address=(char far *)(0xa0000000L+offset);*address=color;}}void put_pix(int x,int y,char color,char inten){char col;col=((35+1)*(color-1)+inten)&255;plot(x,y,col);}main(){int i,j;palette_Register color;precale();reg.h.ah=0;reg.h.al=0x13;int86(0x10,®,®);init_palette_2(color);set_palette(color);for(i=0;i<300;i++)for(j=0;j<35;j++)put_pix(i,j,3,j);getchar();closegraph();}
