Topic: Bgi graphics

Hi Jeff,

I have some questions regarding your Bgi graphics library.

How can the following Bgi code be implemented in SF's Appgraphics?

What are the equivalent commands and format?

What is the difference between the Bgi and Appgraphics libraries?

program bgi_example
use bgi
use bgi_types, only: imagetype
implicit none
integer, parameter::scr_width = 800
integer, parameter::scr_height = 600
integer::midx, midy, i, ignore
integer::w
character(len=40)::drivername
integer, dimension(4,2)::pp
type(imagetype)::img
! Initgraph will use the default driver at 640x480
! gdriver = DETECT
! call initgraph(gdriver, gmode, "")
! Instead, we'll use the more modern initwindow call
w = initwindow(scr_width, scr_height, title="WinBGI Fortran Example")
i = graphresult()
if(i < 0) then
Print *, "An error occurred: ", i
stop
else
Print *, "Graphics ok!"
end if
call getdrivername(drivername)
Print *, "My driver is called "//trim(drivername)
midx = getmaxx() / 2;
midy = getmaxy() / 2;
! Added for fun
call arc(midx, midy, 0, 180, 150)
pp = 0
pp(1,:) = (/ 5, 100 /)
pp(2,:) = (/ 55, 100 /)
pp(3,:) = (/ 55, 130 /)
pp(4,:) = (/ 5, 130 /)
call drawpoly(4, pp)
call allocateimage(img, 100, 100)
do i = EMPTY_FILL, USER_FILL-1
! set the fill style
call setfillstyle(i, RED);
! draw the 3-d bar
call bar3d(midx-50, midy-50, midx+50, midy+50, 10, 1)
ignore = getch()
Print *, "Key Pressed: ", ignore
call copyimage(midx-50, midy-50, img)
call pasteimage(MOD((i-EMPTY_FILL)*100, scr_width), &
scr_height-100, img, COPY_PUT)
end do
call freeimage(img)
! clean up
call closegraph(ALL_WINDOWS)
Print *, "Window Closed"

Thanks again for your time and effort in developing these libraries.

Frank

Re: Bgi graphics

Frank,

The following code should work fine:

program bgi_example
use appgraphics
implicit none

    integer, parameter::scr_width = 800
    integer, parameter::scr_height = 600
    integer::midx, midy, i, ignore
    integer::w
    character(len=40)::drivername
    integer, dimension(4,2)::pp
    type(imagetype)::img
    
    w = initwindow(scr_width, scr_height, title="WinBGI Fortran Example")
    i = graphresult()
    if(i < 0) then
        Print *, "An error occurred: ", i
        stop
    else
        Print *, "Graphics ok!"
    end if

    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    ! Added for fun
    call arc(midx, midy, 0, 180, 150)

    pp = 0
    pp(1,:) = (/ 5, 100 /)
    pp(2,:) = (/ 55, 100 /)
    pp(3,:) = (/ 55, 130 /)
    pp(4,:) = (/ 5, 130 /)

    call drawpoly(4, pp)
    
    call allocateimage(img, 100, 100)
    do i = EMPTY_FILL, USER_FILL-1
        ! set the fill style
        call setfillstyle(i, creatergb(255, 0, 0))
        
        ! draw the 3-d bar
        call bar3d(midx-50, midy-50, midx+50, midy+50, 10, 1)
        
        ignore = getch()
        Print *, "Key Pressed: ", ignore
        
        call copyimage(midx-50, midy-50, img)
        
        call pasteimage(MOD((i-EMPTY_FILL)*100, scr_width), &
                        scr_height-100, img, COPY_PUT)
    end do

    call freeimage(img)
    
    call closewindow(ALL_WINDOWS)
    Print *, "Window Closed"

end program bgi_example

This simple example, however, revealed a couple of problems:

  • The named colors appear to be wrong

  • The copyimage and pasteimage functions might not be working

I'll have to look into those minor issues.

Generally, AppGraphics shares much of its drawing code with WinBGI, but it eliminates legacy oddities like the "16-color" limits and the concept of a graphics driver.

Jeff Armstrong
Approximatrix, LLC

Re: Bgi graphics

Frank,

The problems I mentioned in the last post are fixed in AppGraphics 1.2, which will be released with  Simply Fortran 2.21.

Jeff Armstrong
Approximatrix, LLC