Silverfrost Forums

Welcome to our forums

GIF file from %og graphics ?

30 Sep 2014 2:58 #14755

I'm looking for a possibility to create a gif-file from my OpenGL line graphics window.

Any experience?

1 Oct 2014 7:26 #14756

I am not familiar with OpenGL, but to dump an active window (either %gr or virtual window) I use export_image@. (screen, window, region; it's all a bit confusing, but not %og region!) This is fairly flexible as it supports .gif, .jpg and also .png. I would recommend you look at .png, which is effectively the replacement for .gif and has a much better colour palette.

Dan may have a comment on the restrictions of dumping a %og region. I think there are restrictions as to what you can do with a %og region but a possible option might be to create another background graphics region via create_graphics_region@ then if it is possible, copy the %og region to this region. Once copied, this region could be selected then exported with export_image@. Background or virtual regions work well once you have all the coding bugs removed, although check on the memory usage. I had a look in the documentation, but could not find what routines would access a %og region.

John

1 Oct 2014 2:37 #14757

You should search for the Clearwin+ thread 'Graphics region export' which was started in 2010.

John Horspool (who sadly has passed away) was an expert in %og, and there he tells you how to do the graphics export. It is more or less as John C says.

Eddie

13 Oct 2014 7:56 #14807

John,

I tried:

    ma = winio@ ('%pv&')
    ma = winio@ ('%^og[double,depth16]  &', iBasicSize, iBasicSize, cb_CreateMainGLwin)  ! Create main openGL window
    MA = WINIO@ ('%lc&', iGraphicHandle)
    :
    :
    iTempHandle = 4711
    MA = CREATE_GRAPHICS_REGION@ (iTempHandle, iCurrDrawSizeX, iCurrDrawSizeY)
    MA = SELECT_GRAPHICS_OBJECT@ (iGraphicHandle)
    MA = COPY_GRAPHICS_REGION@   (iTempHandle,     0, 0, iCurrDrawSizeX, iCurrDrawSizeY,   & 
         &                        iGraphicHandle,  0, 0, iCurrDrawSizeX, iCurrDrawSizeY, 13369376)  ! CC0020

Select and copy functions return zero (error) ??

13 Oct 2014 10:36 #14808

I think that you cannot use %lc (I may be wrong) in this context but you should use a grave accent modifier and use a device handle that you supply like in %gr. There is some information in the CWPLUS.ENH file (item 224) that is relevant if you want to explore it.

Note that this is just a guess.

I struggled with understanding handles, and once wrote a post 'When is a handle not a handle?' It turns out that some handles are given to you by Windows, but some (like the one for %gr) are supplied by you the programmer.

Eddie

13 Oct 2014 1:35 #14812

Using %lc or %`og makes no difference for the handle. It is available in both cases after creating the OpenGL window.

I have read item 224 and tried

 CALL SET_OPENGL_CONTEXT@

instead of

SELECT_GRAPHICS_OBJECT@

--> No success, no change.

Erwin

13 Oct 2014 2:03 #14815

Ah well, it was worth a try. Apologies that it wasn't helpful.

Another approach might be to use a printer driver that creates GIFs and other file formats, and install it, then use the OpenGL print functionality. The first such printer driver I found with a Google search was this one:

http://www.pdfill.com/freewriter_image.html

It has the benefit of being free!

Eddie

14 Oct 2014 7:24 #14823

As long as I have no access to the graphics window, I can neither copy to file nor print.

Erwin

14 Oct 2014 6:25 #14828

I don't understand 'no access to the OpenGL window' - I thought you could create it and write to it.

The procedure for printing appears to be to start the printer with:

I=OPEN_GL_PRINTER@ ...

(or OPEN_GL_PRINTER1@)

then go through the graphics creation routines again (just like on the screen window), then use

I=PRINT_OPENGL_IMAGE@

to finish the print. The printer driver I pointed to will give you a file in the image format you select instead of a hard copy on a physical printer.

Eddie

15 Oct 2014 12:39 #14838

Hi Eddie

It would be great if you could make a running example. I get only the error message 'No OpenGL buffers are open' when I redraw.

Erwin

15 Oct 2014 3:49 #14840

John, Paul,

from #179 in file cwplus.enh I understand, there is no OpenGL graphic in memory, therefor it cannot be copied.

Any idea how to get the graphic into a GRAPHICS_REGION that can be copied?

It's a very important point for me to save the graphic to file or to paste buffer using Ctrl+s or Ctrl+c like in my five other graphic programs created using %gr.

Erwin

15 Oct 2014 6:49 #14844

Sorry but I have not worked with OpenGL. I can only look at the documentation and examples.

15 Oct 2014 7:10 #14845

I'm rather busy until the weekend, but I'll have a go.

Did you look at all the other posts on OpenGL in the forum? I thought that this one from John Horspool was likely to be helpful:

https://forums.silverfrost.com/Forum/Topic/1822&start=0&postdays=0&postorder=asc&highlight=opengl

Eddie

15 Oct 2014 8:06 #14848

I had a go at modifying the Silverfrost 'Teapots.for' OpenGL demo, incorporating John Horspool's code for using a DIB block. I put the modified code here:

https://dl.dropboxusercontent.com/u/76596632/TP.for

It succeeds (for me at least) in creating a BMP file, at the original size of the %og area, and as that has a %pv pivot, after resizing, the bitmap reflects that resized area (although the array of teapots doesn't get any bigger). Apologies that my modifications are not very elegant.

As for GIF - then I'm in the dark! (I don't use OpenGL, or GIF files). However, with a 'printer' driver that writes to different file formats, I imagine that DIB_PRINT@ would create them. You are also on your own creating bitmap files with a different size than the %og control. Sorry.

Eddie

16 Oct 2014 11:29 #14862

I use the trick of J.Horspool to make BMPs. Trick uses put_dib_block which Paul may make capable of other graphics formats if he already not done that (i have not try). For simple access i repost it here

!!===============================================================
! thanks to John Horspool for these subs
!
	integer function SaveOpengl_Bitmap() 
      include <clearwin.ins>,nolist 
      include <opengl.ins>,nolist 

      integer wOpGL,hOpGL 
      common /OpenGL_image_size/wOpGL,hOpGL 
        wOpGL=clearwin_info@('OPENGL_WIDTH')
        hOpGL=clearwin_info@('OPENGL_DEPTH')
        call do_bitmap(wOpGL,hOpGL) 
      SaveOpengl_Bitmap=2 
      end 

!-----------------------------------------------
      subroutine do_bitmap(wOpGL,hOpGL) 
      include <clearwin.ins>,nolist 
      include <opengl.ins>,nolist 
      integer wOpGL,hOpGL,ierr,koff,kount,i,j,k 
      CHARACTER*1 ImageData(3*(wOpGL+3)*hOpGL), ImageDib(3,wOpGL,hOpGL) 
      CHARACTER*128 file_name 
      logical exst 

      ImageData=' ' 
      ImageDib =' ' 

      call glReadPixels(0,0,wOpGL,hOpGL,
     * GL_RGB,GL_UNSIGNED_BYTE,ImageData) 

      koff=mod(wOpGL,4) 

      kount=0 

        do j=1,hOpGL 
            do i=1,wOpGL 
              do k=1,3 
                kount=kount+1 
                ImageDib(k,i,hOpGL-j+1)=ImageData(kount) 
              end do 
            end do 
          kount=kount+koff 
        end do 

      file_name='Opengl   .bmp' 

      k=0 
5     k=k+1 

      write(file_name(7:9),'(I3)')k 

      if (file_name(7:7).eq.' ') file_name(7:7)='0' 
      if (file_name(8:8).eq.' ') file_name(8:8)='0' 

      INQUIRE(FILE=file_name,EXIST=EXST) 
      IF (EXST) go to 5 

      call put_dib_block@(file_name,ImageDib,wOpGL,hOpGL,
     * 0,0,wOpGL,hOpGL,24,ierr) 
      return 
      end

I3

17 Oct 2014 5:28 #14866

Just a small remark to the source code before: The construction to get the full number of digits (leading zeros)

      write(file_name(7:9),'(I3)')k 
       if (file_name(7:7).eq.' ') file_name(7:7)='0' 
       if (file_name(8:8).eq.' ') file_name(8:8)='0'

can be simplified by

      write(file_name(7:9),'(I3.3)')k

Wilfried

20 Oct 2014 7:45 #14898

Wonderful; it's really working.

Thanks Eddie and Dan !

Erwin

20 Oct 2014 8:52 #14899

Erwin,

I try not to take credit for other people's work: in this case instead of me you owe credit to the late John Horspool and the guy at Silverfrost who wrote the 'Teapots' example (and Dan). As you asked for GIF originally, and our examples to BMP (with JPG also supported according to the documentation), then please let us know if you succeed in getting the image in other formats with Clearwin+, and onto the clipboard (and how!). Then, maybe Paul will implement the approach as standard routines in the Clearwin+ library.

Eddie

20 Oct 2014 1:15 #14901

I tried hard to create my GIF file, but up to now without success.

    CALL Put_DIB_Block@ (BMP_FileName, ImageDIB, iSizeX, iSizeY, 0, 0, iSizeX, iSizeY, 24, iErr) 

    iBMP_Handle = Import_BMP@ (BMP_FileName, iErr)

    CALL EXPORT_GIF@ (iBMP_Handle, '3dView_Graph.gif', iErr)

After creating the BMP file I read it again with import_bmp@. I received a handle and error code zero. export_gif@ however, returns error code 11 ?

All other trials e.g. with %gr and dib_paint@, select_graphics_object@ and export_image@ failed as well.

What else can I try?

Erwin

20 Oct 2014 3:10 #14903

Erwin, this 'workaround' may help - at least, it works with several BMP images I used for testing:

      winapp 
      program test 
      implicit none

      include <windows.ins>

      integer*4     i,hdl,rows,cols,bit,rtcode

      call get_dib_size@('graphics.bmp',cols,rows,bit,rtcode)
      hdl = import_bmp@('graphics.bmp',rtcode)
      i = create_graphics_region@(2L,cols,rows)
      i = select_graphics_object@(2L)
      i = dib_paint@(0,0,hdl,0,0)
      i = export_image@('graphics.gif')
      i = delete_graphics_region@(2L)
      end

Wilfried

Please login to reply.