I was helped by John Horspool to solve my problem: 'save bitmap from my OpenGL Window to file on my hard disk'.
I prepared a small program witch draws red sphere on yello background. The program should save conten of window to disk as a bitmap file called Junk_BMP.bmp. I have bitmap but there is only black square nothing more. There is something wrong! Are there anybody who would correct the program to achieve the goal (saving bitmap to file).
Leszek Flis
PROGRAM STENCIL
include <clearwin.ins>,nolist
include <opengl.ins> ,nolist
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! parameters for opengl window !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! parameter (kw_ogl=400,kh_ogl=400)
integer i,koff,kount,k,j
integer opengl_proc
external opengl_proc
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Coded by JohnHorspool to is needed to save bitmap file !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CHARACTER1 ImageData(3(kw_ogl+3)*kh_ogl),ImageDib(3,kw_ogl,kh_ogl)
i=winio@('%es%ca[Saving BITMAP]%sp%ww[no_border]%pv%^og[depth32,stencil]',0,0,kw_ogl,kh_ogl,opengl_proc)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! MAIN part Coded by JohnHorspool - is needed to save bitmap file !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ImageData=' ' ImageDib =' '
call glReadPixels(0,0,kw_ogl,kh_ogl,GL_RGB,GL_UNSIGNED_BYTE,ImageData)
koff=mod(kw_ogl,4)
kount=0
do j=1,kh_ogl
do i=1,kw_ogl
do k=1,3
kount=kount+1
ImageDib(k,i,kh_ogl-j+1)=ImageData(kount)
end do
end do
kount=kount+koff
end do
call put_dib_block@('Junk_bmp.bmp',ImageDib,kw_ogl,kh_ogl,0,0,kw_ogl,kh_ogl,24,ierr)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! MAIN part Coded by JohnHorspool - is needed to save bitmap file !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
CALL glutMainLoop
END
! Subroutines ! Draw a sphere subroutine display() include <opengl.ins>,nolist
call glClearColor(1.0,1.0,0.0,1.0)
call glClear(OR(GL_COLOR_BUFFER_BIT,GL_DEPTH_BUFFER_BIT))
call glColor3f(1.0,0.0,0.0)
call auxSolidSphere (1.0d0)
call glFlush()
end
! Whenever the window is reshaped, redefine the ! coordinate system and redraw the stencil area. subroutine myReshape(width,height)
INCLUDE <opengl.ins>,nolist
INTEGER width,height
REAL*8 r
r=1.0
IF (height==0) height=1
CALL glViewport(0, 0, width, height)
CALL glMatrixMode(GL_PROJECTION)
CALL glLoadIdentity()
IF(width<=height) then
CALL glOrtho(-r,r,-r*height/width,r*height/width,-r,r)
ELSE
CALL glOrtho(-r*width/height,r*width/height,-r,r,-r,r)
ENDIF
CALL glMatrixMode(GL_MODELVIEW)
CALL glLoadIdentity()
end
integer function opengl_proc()
include <clearwin.ins>,nolist
include <opengl.ins>,nolist
integer w,h
character*256 reason
reason=clearwin_string@('CALL_BACK_REASON')
if(reason.eq.'SETUP')then
call glEnable(GL_DEPTH_TEST)
else if(reason.eq.'RESIZE')then
w=clearwin_info@('OPENGL_WIDTH')
h=clearwin_info@('OPENGL_DEPTH')
call myReshape(w,h)
else if(reason.eq.'DIRTY')then
call display()
end if
opengl_proc=2
end