Topic: Simple Graphics Animation

I'm a beginner FORTRAN programmer.  I am really enjoying the excellent programming environment
provided by Simply FORTRAN. However, I've run into a bit of a roadblock with regard to
graphics.  I'm hoping someone can point me in the right direction.

I'd like to develop some numerical simulations and plot the results as the simulation proceeds
as a simple 2-dimensional animation on my monitor.  The planned program flow would be roughly
as follows:

(1) Initialize the simulation
(2) Initialize a display window (preferably 1920x1080 with full RGB colors).
(3) Advance the simulation a time step
(4) Convert the updated model state into a set of pixel coordinates which will be plotted as
points or used as endpoints of simple line segments.
(5) Clear a display write buffer and draw an updated set of 2-D points or lines
(6) Update display window with the new graphic page
(7) Loop back to step (3).

I've looked through the various graphics-related FORTRAN packages.  The Open GL interfaces
would probably work, but I think the complexity of the interface greatly exceeds my current
needs and programming ability.

The Win BGI package seems more appropriate. I played around with the parameters in the example
program provided for Simply FORTRAN and  I was able to get the screen resolution and colors I
want.  Unfortunately, the example is a C routine.  It is not clear to a beginner like myself
how I can invoke the various Win BGI routines and pass data (such as display  coordinates and
colors) from my FORTRAN main program.

Thanks,

    Greg M (howmiller)

Re: Simple Graphics Animation

Greg,

I think WinBGI seems like it would work well for what you're describing.  However, WinBGI is a C library.  It is rather simple, however, so creating a Fortran wrapper shouldn't be too difficult.  Unless you'd like to tackle it personally, I'll try to put together a thin wrapper in Fortran around WinBGI that will make it a bit more usable.  Does that sound like it might work to you?

When complete (a day or two, probably) the wrapper will be available through the package manager.

Jeff Armstrong
Approximatrix, LLC

Re: Simple Graphics Animation

Jeff,

I'd like to accept your kind offer.  As I indicated, I'm pretty much a beginner-- I would not know where to begin.

Hopefully, such a "wrapper" will be of use for other FORTRAN users.

Thanks very much.

Greg

Re: Simple Graphics Animation

I have a preliminary interface up and running.  You can see the source code at:

https://github.com/ArmstrongJ/WinBGI-Fortran

I should have a package ready shortly as well.

Jeff Armstrong
Approximatrix, LLC

Re: Simple Graphics Animation

Okay, the Fortran interface is now available (with example) from:

http://packages.simplyfortran.com/package/47.html

The interface isn't yet complete.  There is more work to be done, but most simple graphics functions should be working fine.  I'll add a bit more later, but it might be a week or two.

Jeff Armstrong
Approximatrix, LLC

Re: Simple Graphics Animation

Jeff,

As I understand it, at this point you have implimented a subset of the features of WinBGI in your FORTRAN interface.

I tried the new example program that you provided and it works fine on my system.

I tried a couple of functions that had worked in the C version, but do not work for me in the FORTRAN version.  Have I invoked these features incorrectly or do they remain unimplemented in the FORTRAN version so far?

Here are some detailed results:

(1) Call the 'initwindow' function to specify display window size:

    >In the original C version of WinBGI:

        initwindow(1800,1000);

        compiles and works as desired

    > In WinBGI-FORTRAN:

        call initwindow(1800,1000)

        Results in the following error messages:

C:\Program Files (x86)\Simply Fortran 2\mingw-w64\bin\gfortran.exe" -c -o "build\bgi_example.o" -g -march=native -m32 -

IC:/Users/user/AppData/Local/sfpm/32/include  -Jmodules ".\bgi_example.f90"
.\bgi_example.f90:2.4:

use bgi
    1
.\bgi_example.f90:28.30:

    call initwindow(1800,1000)
                              2
Error: 'initwindow' at (1) has a type, which is not consistent with the CALL at (2)
Error(E42): Last command making (build\bgi_example.o) returned a bad status
Error(E02): Make execution terminated


(2) Call 'setcolor' function to set the current drawing color to a specified RGB value:

    >In the original C version of WinBGI:

        setcolor(COLOR(240,150,100));
       
        compiles and produces the desired results
   
    > In WinBGI-FORTRAN:

        call setcolor(COLOR(240,150,100))

        Returns the following error messages:

"C:\Program Files (x86)\Simply Fortran 2\mingw-w64\bin\gfortran.exe" -c -o "build\bgi_example.o" -g -march=native -m32 -

IC:/Users/user/AppData/Local/sfpm/32/include  -Jmodules ".\bgi_example.f90"
    "C:\Program Files (x86)\Simply Fortran 2\mingw-w64\bin\gfortran.exe" -o "bar3d.exe" -static -m32 "build\bgi_example.o" -

LC:/PROGRA~2/SIMPLY~1/MINGW-~1/lib/ -LC:/Users/user/AppData/Local/sfpm/32/lib -lbgif -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32 -

lstdc++
build\bgi_example.o: In function `bgi_example':
C:\Users\user\Documents\Fortran\A -Greg Source\Win BGI  Fortran/./bgi_example.f90:29: undefined reference to `color_'
collect2.exe: error: ld returned 1 exit status
Error(E42): Last command making (bar3d.exe) returned a bad status
Error(E02): Make execution terminated


If this is simply a matter that these  particular features have not yet been implemented in WinBGI-FORTRAN, that's fine.  I'll be happy to wait until you have a chance to complete the interface  -- it's really great that you are willing to try to provide these useful extensions to the basic language.

If it would be helpful, I can supply a list of the WinBGI functions that would be of most use for my particular applications.

Once again, thanks for your help in this matter. 

Greg M.

Re: Simple Graphics Animation

Greg,

You are correct that I've only gotten a subset implemented thus far.  As a rule of thumb, the only things missing are going to be functions that interact with C structures (just haven't gotten to them yet) or any preprocessor macros.  Also, the text output isn't working yet.

The initwindow() function is implemented, but it requires all of its arguments at this time.  You'll notice that the original definition is:

    int initwindow(int width, int height, const char* title="Windows BGI", int left=0, int top=0, bool dbflag=false, closeflag=true);

At this time, it does require all arguments to be passed.  I'll change this in the future as I find it quite annoying as well. 

The COLOR() function is not yet implemented either.  I believe it is an actual library function although it appears as a preprocessor macro.  Another bit I haven't gotten to yet.

I plan on getting back to it in a week to finish it off completely.  Sorry for the delay.  It is a work in progress.

Jeff Armstrong
Approximatrix, LLC

Re: Simple Graphics Animation

Greg,

I've implemented the COLOR function (as rgbcolor) as well as some support functions.  The update (version 0.2) is now available via the package manager.

Additionally, the list of supported functions is available at https://github.com/ArmstrongJ/WinBGI-Fo … -Functions.

I'll continue working on supporting the remaining missing functions.

Jeff Armstrong
Approximatrix, LLC

Re: Simple Graphics Animation

Another update (version 0.3) is now available that fixes the initwindow functionality.  The function is declared as:

function initwindow (width, height, title, left, top, dbflag, closeflag)

The width and height parameters are mandatory, while the remaining parameters are now optional.  For example, to specify a window position as (100, 100) in screen coordinates, the following call would work:

w = initwindow(800, 600, left=100, top=100)

There was previously a bug in the interface related to the two logical flags, dbflag and closeflag that caused the function to fail under all circumstances.  It should be working fine now.

Jeff Armstrong
Approximatrix, LLC

Re: Simple Graphics Animation

Jeff,

I've tested several of the basic procedure calls and everything seems to work fine.  I'll let you know if I encounter any problems.

Thanks very much.  This is a great help to me.

Greg

Re: Simple Graphics Animation

Greg,

It's my pleasure.  I still have a few more functions to implement, and hopefully I can get to them this week.

Jeff Armstrong
Approximatrix, LLC