forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

OpenGL not working at all
Goto page 1, 2  Next
 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
ursuselasticus



Joined: 26 Mar 2005
Posts: 71

PostPosted: Sun Feb 18, 2007 7:45 pm    Post subject: OpenGL not working at all Reply with quote

Hello,

trying my luck with openGL from FTN95 with the following piece of code:

Code:

WINAPP
program GLWindow
   
    include <opengl.ins>
    include <windows.ins>
   
   character*20 title
   
   title = 'MyGLExercise'   
   iwin=winio@('%ca@&',title)            ! Define Caption
    iwin=winio@('%og&',600,400)            ! Open GL
   iwin = winio@('%sp&',0,0)            ! set window position
    iwin=winio@('%lw',iwindow)            ! leave window open

!    Init OpenGL
   
   call glShadeModel (GL_SMOOTH)
    call glClearColor (0.0, 0.0, 1.0, 0.0)   ! clear screen to blue
    call glClearDepth (1.0)
    call glEnable (GL_DEPTH_TEST)
    call glDepthFunc (GL_LEQUAL)
    call glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)

! Clear GL Window

      call glClear(ior(GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT))
    call glLoadIdentity()

!   draw triangle
   
   call glTranslatef(-1.5,0.0,-6.0)
    call glcolor3f(1.0,0.0,0.0)            ! Set color to red
    call glBegin(GL_TRIANGLES)
       call glVertex3f(0.0,1.0,0.0)
        call glVertex3f(-1.0,-1.0,0.0)
        call glVertex3f(1.0,-1.0,0.0)
   call glEnd()

!   draw square
   
   call glTranslatef(3.0,0.0,0.0)
    call glBegin(GL_QUADS)
       call glVertex3f(-1.0, 1.0, 0.0)       
       call glVertex3f( 1.0, 1.0, 0.0)       
       call glVertex3f( 1.0,-1.0, 0.0)       
       call glVertex3f(-1.0,-1.0, 0.0)
   call glEnd()             
   
   call sleep@(5.0)   

end   


I would expect

- openGL window to open - okay
- clear it to blue - not okay, remains black
- display of triangle and quad in red - not okay.

What did I miss ??

Norbert
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7924
Location: Salford, UK

PostPosted: Mon Feb 19, 2007 8:26 am    Post subject: Reply with quote

Don't know but try the following simple example from the help file...

PROGRAM Simple
INCLUDE <clearwin.ins>,nolist
INCLUDE <opengl.ins>,nolist
REAL t1,t2
INTEGER i, ctrl
i=winio@('%es%ca[Simple OpengGL Sample]&')
i=winio@('%sp%ww[no_border]%og[static]%lw',
& 0, 0, 500, 500, ctrl)
CALL glClearColor (0.0, 0.0, 0.0, 0.0)
CALL glClear(GL_COLOR_BUFFER_BIT)
CALL glColor3f(1.0, 1.0, 1.0)
CALL glMatrixMode(GL_PROJECTION)
CALL glLoadIdentity()
CALL glOrtho(-1d0, 1d0, -1d0, 1d0, -1d0, 1d0)
CALL glBegin(GL_POLYGON)
CALL glVertex2f(-0.5, -0.5)
CALL glVertex2f(-0.5, 0.5)
CALL glVertex2f( 0.5, 0.5)
CALL glVertex2f( 0.5, -0.5)
CALL glEnd()
CALL glFlush()
END
Back to top
View user's profile Send private message AIM Address
JohnHorspool



Joined: 26 Sep 2005
Posts: 270
Location: Gloucestershire UK

PostPosted: Mon Feb 19, 2007 11:02 am    Post subject: Reply with quote

Norbert,

After hacking about a little with your code, I got this that works:-

WINAPP
program GLWindow

INCLUDE <clearwin.ins>,nolist
INCLUDE <opengl.ins>,nolist

character*20 title

iwindow=0

title = 'MyGLExercise'
iwin=winio@('%ca@&',title) ! Define Caption
iwin=winio@('%og&',600,400) ! Open GL
iwin = winio@('%sp&',0,0) ! set window position
iwin=winio@('%lw',iwindow) ! leave window open

! Init OpenGL

call glShadeModel (GL_SMOOTH)
call glClearColor (0.0, 0.0, 1.0, 0.0) ! clear screen to blue
call glClearDepth (1.0)
call glEnable (GL_DEPTH_TEST)
call glDepthFunc (GL_LEQUAL)
call glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)

! Clear GL Window

call glClear(ior(GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT))
call glLoadIdentity()

! draw triangle

call glcolor3f(1.0,0.0,0.0) ! Set color to red
call glBegin(GL_TRIANGLES)
call glVertex3f(1.0,1.0,0.0)
call glVertex3f(0.0,-1.0,0.0)
call glVertex3f(1.0,-1.0,0.0)
call glEnd()

! draw square

call glcolor3f(0.0,1.0,0.0) ! Set color to green
call glBegin(GL_QUADS)
call glVertex3f(-0.5, 0.5, 0.0)
call glVertex3f( 0.5, 0.5, 0.0)
call glVertex3f( 0.5,-0.5, 0.0)
call glVertex3f(-0.5,-0.5, 0.0)
call glEnd()

CALL glFlush()

end

The most significant changes I made were:-

i). replace windows.ins with clearwin.ins
ii). add the glflush call to the end (you must call this otherwise the opengl commands never get issued)


I hope this helps, it is well worth perservering with OpenGL, the results are excellent.

cheers
John Laughing
Back to top
View user's profile Send private message Visit poster's website
ursuselasticus



Joined: 26 Mar 2005
Posts: 71

PostPosted: Mon Feb 19, 2007 12:01 pm    Post subject: Reply with quote

Thanks Paul and John,

... but still there must be some point that I am missing.

- John: I introduced your modifications, I even did cut and paste your code into my Plato. The improvement is, that now clearing the screen to blue works fine, but I still do get neither triangle nor square. Did this work on your system ? If yes, do I have to change some settings or link additional libraries or whatever might be outside of the code. Link worked all right without any errors or warnings though.

- Paul's code worked okay - but I fail to see the difference in the general approach from this sample to my code (after following John's advice, that is)
1) include clearwin.ins and opengl.ins
2) open GL-Window, leave it open
3) start calling OpenGL routines
4) finally call glFlush to have them executed

Confused Confused

Norbert
Back to top
View user's profile Send private message
JohnHorspool



Joined: 26 Sep 2005
Posts: 270
Location: Gloucestershire UK

PostPosted: Mon Feb 19, 2007 12:25 pm    Post subject: Reply with quote

Norbert,

Yes the code I supplied back works fine with me, I see the triangle and square clearly.

I do not use Plato ! I do all my editing and source code writing using the freeware PFE editior. I do all my compiling and linking in a DOS window using the command line. For this simple example all I did was this:-

ftn95 glwindow.for /link

No additional setting or libraries are necessary.

cheers
John
Back to top
View user's profile Send private message Visit poster's website
ursuselasticus



Joined: 26 Mar 2005
Posts: 71

PostPosted: Mon Feb 19, 2007 12:51 pm    Post subject: Reply with quote

After some further time I got it - but I do not understand it.

Johns modifications work okay - when I remove the statement

call glEnable(GL_DEPTH_TEST).

from the code. If I re-introduce it, I only receive the blue screen.
Confused Surprised Confused

Is there something wrong with my system, my installation, my settings or what ??

Norbert
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Mon Feb 19, 2007 1:21 pm    Post subject: Reply with quote

I get the same as you - blue if the routine is not removed. I see the green and red if it is removed. Paul's example fails as it doesn't have another continuation marker. His b&w squares fill with garbage after a while. In both cases, if the window is obscured (covered) and then re-exposed, the image is gone.

Eddie
Back to top
View user's profile Send private message
ursuselasticus



Joined: 26 Mar 2005
Posts: 71

PostPosted: Mon Feb 19, 2007 1:45 pm    Post subject: Reply with quote

Quote:
if the window is obscured (covered) and then re-exposed, the image is gone.


This is fixed when the 'static' option is selected in the call to %og like

iwin=winio@('%og[static]&',600,400)

Norbert
Back to top
View user's profile Send private message
JohnHorspool



Joined: 26 Sep 2005
Posts: 270
Location: Gloucestershire UK

PostPosted: Mon Feb 19, 2007 2:55 pm    Post subject: Reply with quote

Norbert, Eddie

Your example is very trivial, which is of course the correct place to start.

But you can only start to appreciate the true power of OpenGL when you use display lists. I have modified your code again, to include a display list and a callback function to initialise and refresh the graphics.

WINAPP
program GLWindow

INCLUDE <clearwin.ins>,nolist
INCLUDE <opengl.ins>,nolist

external opengl_proc

character*20 title
iwindow=0

title = 'MyGLExercise'
iwin=winio@('%ca@&',title) ! Define Caption
iwin=winio@('%^og&',600,400,opengl_proc) ! Open GL
iwin = winio@('%sp&',0,0) ! set window position
iwin=winio@('%lw',iwindow) ! leave window open

end

integer function opengl_proc()

INCLUDE <clearwin.ins>,nolist
INCLUDE <opengl.ins>,nolist

character*128 reason

reason=clearwin_string@('CALL_BACK_REASON')

if (reason.eq.'SETUP') then
call ogl_init
else if (reason.eq.'DIRTY') then
call refresh
end if

opengl_proc=2

end

subroutine ogl_init

INCLUDE <clearwin.ins>,nolist
INCLUDE <opengl.ins>,nolist

common /gl_list/klist

klist=100

call glNewList(KLIST,GL_COMPILE)

! Init OpenGL

call glShadeModel (GL_SMOOTH)
call glClearColor (0.0, 0.0, 1.0, 0.0) ! clear screen to blue
call glClearDepth (1.0)
call glEnable (GL_DEPTH_TEST)
call glDepthFunc (GL_LEQUAL)
call glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)

! Clear GL Window

call glClear(ior(GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT))
call glLoadIdentity()

! draw triangle

call glcolor3f(1.0,0.0,0.0) ! Set color to red
call glBegin(GL_TRIANGLES)
call glVertex3f(1.0,1.0,0.0)
call glVertex3f(0.0,-1.0,0.0)
call glVertex3f(1.0,-1.0,0.0)
call glEnd()

! draw square

call glcolor3f(0.0,1.0,0.0) ! Set color to green
call glBegin(GL_QUADS)
call glVertex3f(-0.5, 0.5, 0.0)
call glVertex3f( 0.5, 0.5, 0.0)
call glVertex3f( 0.5,-0.5, 0.0)
call glVertex3f(-0.5,-0.5, 0.0)
call glEnd()

CALL glFlush()

call glEndList()

return
end

subroutine refresh

INCLUDE <clearwin.ins>,nolist
INCLUDE <opengl.ins>,nolist

common /gl_list/klist

call glClearColor (0.0, 0.0, 1.0, 0.0) ! clear screen to blue

! Clear GL Window

call glClear(ior(GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT))
call glLoadIdentity()

call glCallList(klist)

call glFlush()

call swap_opengl_buffers()

return
end


OpenGL is a vast subject and quite daunting at first ! I started by first studying the supplied examples with FTN95 and the relevant chapter of the Clearwin+ users guide, and thereafter downloading various tutorials from web searches. It was well worth the effort as the end result can be spectacular.

cheers
John Razz
Back to top
View user's profile Send private message Visit poster's website
ursuselasticus



Joined: 26 Mar 2005
Posts: 71

PostPosted: Mon Feb 19, 2007 3:33 pm    Post subject: Reply with quote

John,

thats about what I am trying to do.

The sample I came about with first is a contraction of the essential lines of code I got from Nehe's OpenGL Tutorial combined with what I got from clearwin to save me the effort to work with windows API.

I am well heading down the line to (finally) handle big objects on my screen with everything included to make the scene look and feel good. But I was stuck right at the beginning with some parts of code not working as I thought I understood how they should.

Thanks for your support.
It feels good that there is someone out there who mastered this for two reasons: (1) this proves it can be done (2) for the hope to get some answer on postings in this forum here (hope to keep this low in number though).

Norbert
Back to top
View user's profile Send private message
JohnHorspool



Joined: 26 Sep 2005
Posts: 270
Location: Gloucestershire UK

PostPosted: Mon Feb 19, 2007 4:33 pm    Post subject: Reply with quote

Norbert,

I had over 20 years experience in "conventional" graphics programming, where I had learnt all the tricks to speed things up (tektronix screens were incredibly slow!) I also developed my own shading and hidden line removal algorithms from scratch, the results of which I was very happy with. However what can be achieved with OpenGL is an order of magnitude better. I had to almost unteach myself everything I had learnt and develope a new mindset.

Beware though, OpenGL can be very unforgiving, get it wrong and you can lock up your machine ! The debugger doesn't help you either, as it is not part of ftn95. But the ability to dynamically rotate, pan and zoom complex contour shaded images in real time adds a new level of capability to your programs.

cheers and good luck !

John Razz
Back to top
View user's profile Send private message Visit poster's website
ursuselasticus



Joined: 26 Mar 2005
Posts: 71

PostPosted: Mon Feb 19, 2007 5:41 pm    Post subject: Reply with quote

John,

thanks for your good wishes - for I feel I am running out of luck - sort of.
Unteaching is not that difficult with me, my knowledge of computer graphics is limited to 2D. Display of results in graphs on such slow things as Calcomp plotters (my experience being more than 30 years old).

Now, with this OpenGL, I feel I miss something, something vital has dodged my attention, some setting up or something. Linker does not give any message, so I assume all the routines are linked to the project. Or is this a misconception ?

This thing, that glEnable (GL_Depth_test) switches my objects on and off, looks very strange, kind of overflow somewhere. But how to detect ?

Next its gluPerspective that beats me (yes, I have all the parameters set to double precision). Following my maths, my objects should lie in the frustum of perspective, but they do not show.

The Salford samples work okay, even the statements that mess up my sample prog.

Did you set up any compiler or linker options to get to work ?

Any advice would be welcome.

Norbert
Back to top
View user's profile Send private message
JohnHorspool



Joined: 26 Sep 2005
Posts: 270
Location: Gloucestershire UK

PostPosted: Mon Feb 19, 2007 10:17 pm    Post subject: Reply with quote

Norbert,

I can only recommend patience and not trying to run before you can walk. I didn't setup any options on the compiler or linker, just whatever it defaults to. I don't use the perspective view I use a straightforward orthogonal projection as I also maintain a GDI graphics driver and use the same graphics interrogation routines for both drivers. As I said earlier there are no debugging facilities (at least that I'm aware of), so I'd simply sprinkle write statements throughout the source code when attempting to locate an error. I display objects imported from CAD as either wireframe or solid shaded plus FE meshes. Shading requires computation of surface normals, occasionally really slivery geometry can make the surface normal calculation screw up and OpenGL doesn't like bad data! So I sanity check all data before making the relevant OpenGL call.

I got where I am by trial and error and studying a few tutorials (including NeHe). I found the texts I had downloaded too heavy going to read.

cheers
John Cool
Back to top
View user's profile Send private message Visit poster's website
JohnHorspool



Joined: 26 Sep 2005
Posts: 270
Location: Gloucestershire UK

PostPosted: Mon Feb 19, 2007 10:45 pm    Post subject: Reply with quote

Norbert,

Just looking through the OpenGL initialisation routine I have and I've noticed that I use:-

call glClearDepth(1.0d0)

A double precision argument not single.

cheers
John Idea
Back to top
View user's profile Send private message Visit poster's website
ursuselasticus



Joined: 26 Mar 2005
Posts: 71

PostPosted: Tue Feb 20, 2007 8:57 pm    Post subject: Reply with quote

Thanks John for your hints.

You know, I am just following the NeHe tut - not running it Smile Smile - and will do the same as you, that is start that old trial and error business.

But I am happy, that it is not some basic background thing everybody else knows but me - I just hate this being stupid feeling.

Cheers

Norbert Smile Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group