winbgim.h

I have some problems when i try to set solor for an object for example:
The following section of code should draw rectangle with a border of black and interior of red, but it doesnt.

setcolor(BLACK);
rectangle(20,20,120,100);
setfillstyle(SOLID_FILL, RED);

Can u tell me where am i mistaking?

and how can i avoid blinking of screen in this example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<cstdlib>
#include<iostream>
#include<winbgim.h>
using namespace std;
int main()
{
    int gdriver=9;
    int gmode=2;
    initgraph(&gdriver,&gmode, "");
    cleardevice();
    setbkcolor(BLACK);
    setcolor(WHITE); 
    setviewport(5, 5, 500, 450, 1); 
    setcolor(WHITE); 
    rectangle(0, 0, 495, 199);   //border of this rectangle are still black
    while(!kbhit())
    {
    cleardevice();
    
    setcolor(WHITE);
    rectangle(mousex(),440,mousex()+20,430);
      floodfill(mousex()+1,441 ,WHITE); // since setfillstyle(SOLID_FILL, WHITE); not working and i think this is problem with blinking
    delay(1);
    }
    closegraph();
    return 0;
    }
	

Can i hide mouse somhow?
And if u have some links/examples with graphic i would love it!
Last edited on
Does the program compile?

Make sure you have downloaded and installed WinBGIm properly:
http://codecutter.org/tools/winbgim/
BGI Documentation
http://www.cs.colorado.edu/~main/cs1300/doc/bgi/index.html
or
http://www.csie.nuu.edu.tw/~nschou/Teaching/C++/Doc/Quincy/html/programmerHelp/winbgim/bgi/doc/index.html

Installation with Dev-C++:
http://www.onecore.net/dev-c-graphics.htm
http://www.onecore.net/winbgim-graphics.htm
http://apcsteacher.com/reference/cpp/dev_cpp_setup.htm

If you are not using Dev-C++, make sure to install the header files (conio.h and winbgim.h) in C:\MinGW\include\ and the library files (libconio.a and libbgi.a) in C:\MinGW\lib\ . (Personally, I would also make a hardlink to winbgim.h as graphics.h .)

Someone's example programs:
http://www.cs.colorado.edu/~karl/1300.fall05/Programs/


If you are compiling with Dev-C++, make sure you also added the link flags as per the instructions above.

If you are just compiling with MinGW at the command-line, you'll need to link with the libraries explicitly. For example, to compile a program ("myprog.c") that uses the BGI graphics, your compile command may look something like:

D:\prog\foo> gcc myprog.c -lbgi -lgdi32 -luser32



Finally, when using BGI, remember that you first have to initgraph() before you can use any graphics. The WinBGIm library gives you an alternative in initwindow(). Here's an example program (untested!):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <winbgim.h>

const char* message = "Press any key...";

int main()
  {
  int w, h;

  initwindow( 400, 300 );
  setbkcolor( WHITE );
  cleargraph();

  setcolor( BLACK );
  setfillstyle( SOLID_FILL, BLUE );
  setlinestyle( SOLID_LINE, 0, 5 );
  rectangle( 20, 20, 80, 80 );

  setcolor( LIGHTCYAN );
  w = textwidth(  message );
  h = textheight( message );
  outtextxy( 200 - (w / 2), 50 - (h / 2), message );

  getch();

  closegraph();
  return 0;
  }


Again, don't forget the documentation links above, which are an invaluable reference full of examples.

Hope this helps.
Argh, after that you'll have to spend a little time looking through the docs.
ok thanks mate this was realy helpful!!
Topic archived. No new replies allowed.