Menu

No effect with bkcolor() of <winbgim.h>

2006-01-03
2012-09-26
  • Daniel Benavides

    Hello all:
    Im working with the winbgim library, that I downloaded form the Update Packages tool. First I recompiled it in order to generate the static library (no problem with that), and could run a great quantity of examples and they run as expected.
    But when I tried to use the setbkcolor() function it seems not to work, because the expected result is that all the screen color changes, an example of this is taken form the winbgim doc site:
    http://www.cs.colorado.edu/~main/bgi/doc/getbkcolor.html
    Please note that I changed setcolor(EGA_BLUE) to BLUE to the function parameter in the original example, so when the for loop reaches 15 in bkcolor, the message is displayed in BLUE.

    Daniel Benavides.

    include <winbgim.h>

    include <stdlib.h>

    include <stdio.h>

    include <conio.h>

    int main(void)
    {
    / _select driver and mode that supports multiple background colors/
    int gdriver = EGA, gmode = EGAHI, errorcode;
    int bkcol, maxcolor, x, y;
    char msg[80];

    / initialize graphics and local variables /
    initgraph(&gdriver, &gmode, "");

    / read result of initialization /
    errorcode = graphresult();
    if (errorcode != grOk) { / an error occurred /

      printf(&quot;Graphics error: %s\n&quot;, grapherrormsg(errorcode));
      printf(&quot;Press any key to halt:&quot;);
      getch();
      exit(1);               /* terminate with an error code */
    

    }

    / maximum color index supported /
    maxcolor = getmaxcolor();

    / for centering text messages /
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    x = getmaxx() / 2;
    y = getmaxy() / 2;

    / loop through the available colors /
    for (bkcol=0; bkcol<=maxcolor; bkcol++) {

      /* clear the screen */
      cleardevice();
    
      /* select a new background color */
      setbkcolor(bkcol);
    
      /* output a messsage */
      if (bkcol == WHITE)
         setcolor(BLUE);
      sprintf(msg, &quot;Background color: %d&quot;, bkcol);
      outtextxy(x, y, msg);
      getch();
    

    }

    / clean up /
    closegraph();
    return 0;
    }

    My compile log, under a Console GDI project:

    Compiler: Default compiler
    Building Makefile: "C:\Documents and Settings\DANIEL\Escritorio\example\Makefile.win"
    Executing make...
    make.exe -f "C:\Documents and Settings\DANIEL\Escritorio\example\Makefile.win" all
    g++.exe main.o -o "example.exe" -L"L:/Dev-Cpp/lib" -lbgi -lgdi32 -luser32

    Execution terminated
    Compilation successful

     
    • Nobody/Anonymous

      seems to work here. every time i hit a key the window color the text color and the background color of the text changes.

       
    • Nobody/Anonymous

      Well, Im a little confused because in my PC (Win XP) I get a new message each time I hit a key, but the color still the same (black).
      Im using Dev-C++ 4.9.9.2.
      I dont know what could be the cause.
      Appreciate your help.

      Daniel Benavides

       
    • Daniel Benavides

      Sorry about no logging me in my last post.
      I was wondering if could be the driver of my video card.
      Even when I put "gdriver = DETECT;" I obtain the same result (no back color changes).
      Thanks.

      Daniel Benavides

       
    • Anonymous

      Anonymous - 2006-01-05

      The documentation for WinBGIm for initgraph() (http://www.cs.colorado.edu/%7Emain/cs1300/doc/bgi/initgraph.html) has a 'Windows Note':

      'The winbgim version of initgraph uses its parameters only to determine the size of the window that will be created. For example, initgraph(CGA, CGAC3) will create a 320 x 200 window. As an alternative, the user may call initwindow(width, height) instead of initgraph.'

      So the values you are passing have no effect they are there primarily to support legacy code applications from a time before re-sizable windows.

      Have you tried using the RGB color model instead of BGI basic colours?

      Clifford

       
    • Daniel Benavides

      Hi all:
      I was trying to get work the setbkcolor() function and found in the winbgim.cpp a little mistake.
      Please take a look of this example, run it, and if you have downloaded the original Console GDI package from the Dev-C tool, the result should be that both functions below used, getbkcolor() and setbkcolor(), return the same, but its not the case.

      Daniel Benavides

      include <winbgim.h>

      include <stdio.h>

      include <conio.h>

      include <iostream.h>

      int main(void)
      {
      int bkcolor, x, y;
      char msg[40];
      int realcolor, maxcolor;

      initwindow(400,400);
      maxcolor=getmaxcolor();
      x= 200; y=200;
      / loop through some available colors /
      for (bkcolor=0; bkcolor<=maxcolor; bkcolor++) {

        /* clear the screen */
        cleardevice();
      
        setbkcolor( bkcolor);
        sprintf( msg, &quot;Actually set color #: %d&quot;, bkcolor );
        outtextxy(x, y, msg);
        getch();
      
        /* output a text messsage when back ground is Blue */
        if (getbkcolor() == bkcolor ){       
                         //setcolor(BLUE);                                     
               cout&lt;&lt;&quot;\n The color match &quot;&lt;&lt;bkcolor; 
        }
      
        realcolor=getbkcolor();
        sprintf( msg, &quot;The got getbkcolor #: %d&quot;, realcolor );
        outtextxy(x, y, msg);
        getch();
      

      }
      / clean up /
      closegraph();
      getch();
      return 0;
      }

       
    • Daniel Benavides

      The problem in winbgim.cpp source is in its function source:
      void setbkcolor(int color)//
      {... bkcolor ...}
      The problem is here, the above function does not work, because in its body the parameter is not used.

      Besides getbkcolor(), seems to dont work properly too, well, thats because the bkcolor global variable is overwritten by the function parameter, so its no changed really, and its not a good idea put bkcolor as parameter to match the body of the function.
      You can try the changed code of the both corrected functions and see the difference with the original code of winbgim.cpp


      void setbkcolor(int colors)//The problem is here
      {
      // Version 3.2: Color may now be a bgi color (0 to MAXCOLORS) or an RGB color.

      if (IS_BGI_COLOR(colors))
      {
          SetBkColor(hdc[0], PALETTEINDEX(BG+colors));
      SetBkColor(hdc[1], PALETTEINDEX(BG+colors));
      DeleteObject(hBackgroundBrush);
          hBackgroundBrush = CreateSolidBrush(PALETTEINDEX(BG+colors));
          bkcolor= BG+colors;
      }
      else
      {
      SetBkColor(hdc[0], RGB_COLOR(colors));
      SetBkColor(hdc[1], RGB_COLOR(colors));
      DeleteObject(hBackgroundBrush);
          hBackgroundBrush = CreateSolidBrush(RGB_COLOR(colors));
      bkcolor=  colors;      
      }
      

      }

      int getbkcolor()
      {
      // or an RGB color.
      return bkcolor - 15;
      }

      The -15 value, is a correction to the value, you can see what happens if getbkcolor() is not changed and compiling the static library.

      Daniel Benavides

       
      • Nobody/Anonymous

        the win32 version should support more than 16 colors of old bgim.

        you had the old version somehow. the newest version works.

        it should have 3.5 at the additions at the top of the source.

         
    • Anonymous

      Anonymous - 2006-01-08

      Wher did you get WinBGIm from - it is open source and there are several versions knocking around which may have 'fixes':

      http://www.cs.colorado.edu/%7Emain/cs1300/doc/bgi/bgi.html
      http://www.codecutter.net/tools/winbgim/
      http://www14.brinkster.com/aditsu/console/

      Clifford

       
    • Daniel Benavides

      Well I Got it from Dev C 4.9.9.2 update tool in
      Menu - Tools -> Check For Updates/Packages
      Devpack server: Dev-C++ Primary server
      Group: Games & Graphics
      Update: Console GDI

      Yes of course is open source, this project is about that.

       
      • Nobody/Anonymous

        actually clifford meant that winbgim is open source.

        note every devpak wraps open source, and certianly not as open source as winbgim.

        do not make the assumption that just because you dled something in the form of a devpak that it is open source at all let alone gpl or some specific license.

         
    • Daniel Benavides

      The above code works well (the RE6 post), but with the below correction is better.
      This starts in the line 851, of the winbgim.cpp, source that is installed in \DevCpp\include\


      void setbkcolor(int colors)
      {
      // Version 3.2: Color may now be a bgi color (0 to MAXCOLORS) or an RGB color.
      bkcolor=colors;
      if (IS_BGI_COLOR(colors))
      {
      SetBkColor(hdc[0], PALETTEINDEX(BG+colors));
      SetBkColor(hdc[1], PALETTEINDEX(BG+colors));
      DeleteObject(hBackgroundBrush);
      hBackgroundBrush = CreateSolidBrush(PALETTEINDEX(BG+colors));

      }
      else
      {
      SetBkColor(hdc[0], RGB_COLOR(colors));
      SetBkColor(hdc[1], RGB_COLOR(colors));
      DeleteObject(hBackgroundBrush);
          hBackgroundBrush = CreateSolidBrush(RGB_COLOR(colors));
      }
      

      }

      int getbkcolor()
      {
      // or an RGB color.
      return bkcolor;
      }---------------
      My (RE5) example (correcting the changed less and greater than symbols and quots), it works fine and it shows the property of the library:
      "Also only future drawing will use the new background color (anything currently drawn in the old background color will stay in the old color)" of the winbgim documentation site:
      http://www.cs.colorado.edu/%7Emain/cs1300/doc/bgi/setbkcolor.html
      This correction works with RGB colors too.

      Hey thanks all; is very helpful the posts of Clifford and all of you that post and read this topic. Sorry, if I dont got it all of your comments.

      Daniel Benavides
      Bogota, Colombia.

      Daniel Benavides

       
      • Nobody/Anonymous

        well maybe you should send the devpak repositry project an updated devpak?

        you went through the trouble of fixing it why not share the fix by defualt?

         
    • Daniel Benavides

      Yes, this bug was already fixed in the version of the site:
      http://www14.brinkster.com/aditsu/console/

      But I agree with the lasts post, it should be the most recent in the Dev-C++ primary dev pack server.

      Daniel Benavides

       
    • Anonymous

      Anonymous - 2006-01-09

      'Yes of course is open source, this project is about that. '

      I am not sure why you are making that point. I was merely pointing out that because it is open source, not all copies of the source are the same, therefore you might find a working version elsewhere.

      Clifford

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.