Thread: Graphics problem with Borland C++

  1. #1
    Registered User
    Join Date
    Jun 2006
    Location
    Tennessee
    Posts
    12

    Graphics problem with Borland C++

    I'm using Borland C++ 5 and have downloaded lots of peoples source as examples. Everytime though that something has to be run in DOS the text is messed up. It will have the text and in between it it's like it's pixilated. Is there a way to correct this or is it just because these programs were written to be run in pure dos? I'm running this on windows XP. The graphics are fine it's just the text thats screwed up ! ? ! ? !

  2. #2
    ... arjunajay's Avatar
    Join Date
    May 2005
    Posts
    203
    Are you using a laptop/notebook ???
    Tried 'propeties' -> compatibility ???

  3. #3
    Registered User
    Join Date
    Jun 2006
    Location
    Tennessee
    Posts
    12
    I'm running this on a desktop PC. The graphics card is the one that came with the PC (I bought it back in 2000-1). I've tried different compatibility modes but no luck. I'm guessing it's maybe a driver issue with my graphics card? Maybe I ought to just suck it up and focus on 3-d Programming Anyhow I'd like to know if anyone knows of a way to get this to work. It's just inbetween the text that this "pixalation" (I can't thionk of any other way to describe it) happens. Oh, and numbers won't display but this isn't true for all of the programs I've compiled. Anyways this kind of sucks and like to know (if possible) how to fix it.

  4. #4
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    I have no idea what's causing the problem...

    I'm using Borland C++ 5... something has to be run in DOS...
    Is Borland 5 a true-DOS compiler? You can use a modern Windows compiler (Dev-C++ or Visual C++, etc.) to make text-based programs. These are called Win32 Console applications.

    If the example code is Standard C++, it should compile and run just fine. That's the whole idea of a standardized language and portable code! But, it's actually unlikely that any randomly downloaded code is standard compliant...

  5. #5
    ... arjunajay's Avatar
    Join Date
    May 2005
    Posts
    203

    Exclamation

    Quote Originally Posted by DougDbug
    I have no idea what's causing the problem...



    Is Borland 5 a true-DOS compiler? You can use a modern Windows compiler (Dev-C++ or Visual C++, etc.) to make text-based programs. These are called Win32 Console applications.

    If the example code is Standard C++, it should compile and run just fine. That's the whole idea of a standardized language and portable code! But, it's actually unlikely that any randomly downloaded code is standard compliant...
    I had I had an older version but it was turbo c++ I think ???
    It worked without problems.

  6. #6
    Registered User
    Join Date
    Jun 2006
    Location
    Tennessee
    Posts
    12
    Is Borland 5 a true-DOS compiler?

    It's not necessarily, but you can tell it to compile the code with the BGI library and create an EXE that will run in a DOS Shell. That's what I've been doing. I wanted to try and get it in a window and not a full screen to geta pic of what's going on. The prgrams run fine as far as graphics are concerned (they use graphics.h so I can't use Dev-C++ or VC) it's just text that gets weird and it's only inbetween the words of the text. Oh, these are not purely text based programs either. (ie. I had code for tetris and the blocks are fine, sound is fine, but the friggin' instructions on the LH side of the screen had that crazy pixel thing inbetween the words)

    arjunajay- are you aware of anyplace to download a Turbo C++ compiler I'd like to see if it would work with that. I've only been able to find Turbo C (no ++ )

    Anyhow, thanks for the replies !
    Last edited by B_Level; 06-10-2006 at 08:31 AM.

  7. #7
    Registered User
    Join Date
    Jun 2006
    Location
    Tennessee
    Posts
    12
    Code:
    //right click and set Target expert , platform = DOS(Standard), Libraries = BGI
    
    #include <stdio.h>
    #include <graphics.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <dos.h>
    #include <string.h>
    
    void double_h_line(int x1,int x2,int y);
    void double_v_line(int x1,int y1,int y2);
    void doublewindow(int x1,int y1,int x2, int y2);
    void new_doublewindow(int x1, int y1, int x2, int y2);
    
    void single_h_line(int x1,int x2,int y);
    void single_v_line(int x,int y1,int y2);
    void singlewindow(int x1,int y1,int x2,int y2,int ul,int ur);
    
    void mouse_call(int regax,int regbx,int regcx,int regdx);
    
    void first(void);
    void second(void);
    void third(void);
    void initialize(void);
    
    int globax, globbx, globcx, globdx;
    int in_int;
    
    void main(void)
    {
    
    do{
    //set the background then clear the screen
    textbackground(BLUE);
    clrscr();
    highvideo();
    textcolor(WHITE);
    doublewindow(2,2,79,24);
    
    //Editor title
    gotoxy(35,2);
    cprintf("ALL IN ONE (Graphics in BGI)");
    
    textbackground(LIGHTGRAY);
    
    textbackground(BLUE);
    gotoxy(30,5);
    cprintf("1.Move Object");
    gotoxy(30,10);
    cprintf("2.The eyes");
    gotoxy(30,15);
    cprintf("3.Digital Clock");
    gotoxy(30,20);
    cprintf("4. EXIT");
    
    in_int = getch();
    
    
    
    switch (in_int)
    {
    	case 49:
       	first();
          break;
       case 50:
    		second();
          break;
    
       case 51:
          third();
          break;
    
       case 52:
       	exit(0);
     }
      	}while(1);
    }
    
    void first(void)
    {
    initialize();
    
    
    	int gdriver = DETECT, gmode ,x ,y;
       char num;
       void *image;
       unsigned int imsize;
    
       initgraph(&gdriver, &gmode, "c:\\bc5\\bgi");
    
       setcolor(15);
       rectangle(0,0,639,479);
    
       setcolor(15);
       rectangle(4,4,635,474);
    
       // My image
       setcolor(BLUE);
       rectangle(50,35,100,200);
       setfillstyle(1,YELLOW);
       floodfill(99,68,BLUE);
       arc(51,34,270,360,48);
       arc(101,199,90,180,48);
    
       imsize = imagesize(48,34,101,201);
       image = malloc(imsize);
       getimage(48,34,101,201,image);
    
       settextjustify(CENTER_TEXT, CENTER_TEXT);
       setcolor(LIGHTRED);
       outtextxy(320,320, "Please press a key to continue. . .");
    
       getch();
    
       clearviewport();
    
       setcolor(15);
       rectangle(0,0,639,479);
    
       setcolor(15);
       rectangle(4,4,635,474);
       x=270;
       y=125;
       putimage(x,y,image, XOR_PUT);
    
       do{
       num=getch();
       // Move up
       if(num=='8')
      	 {
          setfillstyle(SOLID_FILL,BLACK);
         	bar(x,y,x+53,y+167);
         	putimage(x,y-=5,image,XOR_PUT);
          cprintf("ALL IN ONE BGI");
    
        }
    
       // Move Left
       if(num=='4')
      	 {
          setfillstyle(SOLID_FILL,BLACK);
        	bar(x,y,x+53,y+167);
       	putimage(x-=5,y,image,XOR_PUT);
    
      	 }
    
       // Move Right
       if(num=='6')
        {
          setfillstyle(SOLID_FILL,BLACK);
        	bar(x,y,x+53,y+167);
          putimage(x+=5,y,image,XOR_PUT);
    
        }
    
       // Move Down
       if(num=='2')
        {
          setfillstyle(SOLID_FILL,BLACK);
          bar(x,y,x+53,y+167);
        	putimage(x,y+=5,image,XOR_PUT);
    
        }
    
       // Move Down left
       else
        {
          setfillstyle(SOLID_FILL,BLACK);
        	bar(x,y,x+53,y+167);
        	putimage(x+1,y+1,image,XOR_PUT);
    
        }
    
        }while(num!=27);
    	getch();
       closegraph();
    
    }
    
    void second(void)
    {
    char ch='a';
    initialize();
    setbkcolor(LIGHTGRAY);
    mouse_call(1,0,0,0);
    do{
      delay(1000);
      //left eye
    	mouse_call(3,0,0,0);
       setfillstyle(1,RED);
       fillellipse(140, 250, 90, 50);
       setfillstyle(1,GREEN);
       fillellipse(140, 250, 50, 50);
       mouse_call(3,0,0,0);
       mouse_call(19,0,0,0);
        getpixel(globcx,globdx);
       if (RED == getpixel(globcx, globdx))
       {
       setfillstyle(1,random(15)+4);
       fillellipse(140, 250, 25, 50);
       }
      //right eye
       setfillstyle(1,RED);
       fillellipse(480, 250, 90, 50);
       setfillstyle(1,GREEN);
       fillellipse(480, 250, 50, 50);
       mouse_call(3,0,0,0);
        getpixel(globcx,globdx);
       if (RED == getpixel(globcx, globdx))
       {
       setfillstyle(1,random(15)+4);
       fillellipse(480, 250, 25, 25);
       fillellipse(140, 250, 25, 25);
       }
    
    	mouse_call(1,0,0,0);
    
    
    	if(kbhit())
       	ch = getch();
    
    }while(ch!=27);
    
    closegraph();
    return;
    }
    
    void third(void)
    {
    initialize();
    char buffer[80];
    char c;
    struct time t;
    do{
    
    delay(200);
    
    clearviewport();
    setcolor(WHITE);
    gettime(&t);
    sprintf(buffer, "%02d:%02d:%02d", t.ti_hour,t.ti_min,t.ti_sec);
    
    settextstyle(GOTHIC_FONT, HORIZ_DIR, 5);
    outtextxy(250,200,buffer);
    }while(!kbhit());
    getch();
    closegraph();
    }
    
    
    
    void initialize(void)
    {
    int gdriver=DETECT,gmode;
    initgraph(&gdriver,&gmode,"c:\\bc5\\bgi");
    }
    
    void mouse_call(int regax,int regbx,int regcx,int regdx)
    {
    union REGS inregs, outregs;
    
    inregs.x.ax=regax;
    inregs.x.bx=regbx;
    inregs.x.cx=regcx;
    inregs.x.dx=regdx;
    
    int86(0x33, &inregs, &outregs);
    
    globax=outregs.x.ax;
    globbx=outregs.x.bx;
    globcx=outregs.x.cx;
    globdx=outregs.x.dx;
    }
    
    void double_h_line(int x1,int x2,int y)
    {
    gotoxy(x1,y);
    
    for(int col=x1;col<=x2;col++)
    	{
       gotoxy(col,y);
       cprintf("%c",205);
       }
    }
    
    void double_v_line(int x,int y1,int y2)
    {
    gotoxy(x,y1);
    
    for(int row=y1;row<=y2;row++)
    	{
       gotoxy(x,row);
       cprintf("%c",186);
       }
    }
    
    void doublewindow(int x1,int y1,int x2,int y2)
    {
    //draws a double line window
    
    //upper line
    gotoxy(x1,y1);
    cprintf("%c",201);
    double_h_line(x1+1,x2-1,y1);
    
    //right line
    gotoxy(x2,y1);
    cprintf("%c",187);
    double_v_line(x2,y1+1,y2-1);
    
    //bottom line
    gotoxy(x2,y2);
    cprintf("%c",188);
    double_h_line(x1+1,x2-1,y2);
    
    //left line
    gotoxy(x1,y2);
    cprintf("%c",200);
    double_v_line(x1,y1+1,y2-1);
    gotoxy(x1+1,y1+1);
    
    }
    Here's a program that I compiled in Borland 5 with out a problem except that when I run it it has the pixalation problem that I've been explaining in one part. The initial menu that pops up is fine all the text is readable and looks normal. However if I choose option one, when the text "Please press a key to continue." appears in between each word is the "pixaltion" I've been talking about It's just really annoying and I was wondering if there was a way to get rid of it. Thanks.

  8. #8
    Registered User
    Join Date
    Jun 2006
    Location
    Tennessee
    Posts
    12
    I'll give this one last shot then let it die. Has anyone tried to compile the ^^^^^^^above ^^^^^^^ code, and if so did you have any problems as far as text display goes?

  9. #9
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Try running the executable through a DOS emulator. I personally like DOSBox.

    I have no idea why you are getting this problem under the console. Never seen a console behaving like that. But that dos.h include is probably why.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  10. #10
    Registered User
    Join Date
    Jun 2006
    Location
    Tennessee
    Posts
    12
    Thanks Mario F. I hadn't considered that I'm Running this on XP so running in on an emulator is def. worth trying. Hope that works if not . . . well it is Microsoft (like they really care)

  11. #11
    Registered User
    Join Date
    Jun 2006
    Location
    Tennessee
    Posts
    12
    Just tried out the program with dosbox and no problems. Evidently it was just the way XP emulates DOS that was screwing everything up. I'm Def. Happy Now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginning Game Programming Type Books
    By bumfluff in forum Game Programming
    Replies: 36
    Last Post: 09-13-2006, 04:15 PM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  3. Graphics Programming :: Approach and Books
    By kuphryn in forum Windows Programming
    Replies: 4
    Last Post: 05-11-2004, 08:33 PM
  4. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 05:18 AM
  5. Graphics Problem
    By drdroid in forum C++ Programming
    Replies: 5
    Last Post: 02-27-2002, 02:37 PM