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 

Simple OpenGL Program

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
stfark1



Joined: 02 Sep 2008
Posts: 131

PostPosted: Tue Jun 19, 2018 6:34 pm    Post subject: Simple OpenGL Program Reply with quote

Totally Frustrated, using Win 10 and Fortran to Opengl calls, output "crazy":
PROGRAM BASIC
INCLUDE <clearwin.ins>,nolist
INCLUDE <opengl.ins>,nolist
DIMENSION X(N),Y(N),Z(N)
INTEGER ctrl
X=0.
Y=0.
Z=0.
i=winio@('%es%ca[Simple Opengl Sample]&')
i=winio@('%sp%ww[no border]%og[static]%1w',
* 0, 0, 1000, 1000, ctrl)
CALL glBegin(GL_LINES)
CALL glRotatef(22.0,1.0,0.0,0.0)
CALL glRotatef(22.0,0.0,1.0,0.0)
CALL glRotatef(22.0,0.0,0.0,1.0)
INDX=0
DO 10 I=1,7
INDX=INDX+1
IF (INDX .EQ. N) GOTO 20
CALL glVertex3f(X(INDX),Y(INDX),Z(INDX))
CALL glVertex3f(X(INDX+1),Y(INDX+1),Z(INDX+1))
10 CONTINUE
20 CALL glEnd
END

Note: N in above was 8, tried to submit and it entered a emoticon?
No matter what I change the glRotate commands to, get the same thing, a vertical and a horizontal line on the output, no Z axis and had addition curve date yet did not plot the curve. Have this identical program in C++ works great???
How Simple can one get??? Anyone have ideas? Sid Kraft
Back to top
View user's profile Send private message
John-Silver



Joined: 30 Jul 2013
Posts: 959
Location: Aerospace Valley

PostPosted: Tue Jun 19, 2018 7:49 pm    Post subject: Reply with quote

Sid, you should probably delete this DUPLICATE version of your post or you'll get replies on both !
_________________
''Computers are incredibly rigid. They question nothing. Especialy input data.Human beings are incredibly trusting of computers and don't check input data. Together they are capable of cocking up even the simplest calculation ... Smile "
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Tue Jun 19, 2018 8:32 pm    Post subject: Reply with quote

I have not tested your program but a quick glance shows %1w instead of %lw.
Back to top
View user's profile Send private message
John-Silver



Joined: 30 Jul 2013
Posts: 959
Location: Aerospace Valley

PostPosted: Tue Jun 19, 2018 9:34 pm    Post subject: Reply with quote

I spotted that too Paul .
This is the program I ran (after correcting the '1w' to 'lw', after reinstating th '8' where required instead of the 'N') :-

Code:

      PROGRAM BASIC
      INCLUDE <clearwin.ins>,nolist
      INCLUDE <opengl.ins>,nolist
      DIMENSION X(8),Y(8),Z(8)
      INTEGER ctrl
      X=0.
      Y=0.
      Z=0.
      i=winio@('%es%ca[Simple Opengl Sample]&')
      i=winio@('%sp%ww[no_border]%og[static]%lw',0, 0, 1000, 1000, ctrl)
      CALL glBegin(GL_LINES)
      CALL glRotatef(22.0,1.0,0.0,0.0)
      CALL glRotatef(22.0,0.0,1.0,0.0)
      CALL glRotatef(22.0,0.0,0.0,1.0)
      INDX=0
      DO 10 I=1,7
      INDX=INDX+1
      IF (INDX .EQ. 8) GOTO 20
      CALL glVertex3f(X(INDX),Y(INDX),Z(INDX))
      CALL glVertex3f(X(INDX+1),Y(INDX+1),Z(INDX+1))
   10 CONTINUE
   20 CALL glEnd
      END


... and for me it resulted in just a blank black window appearing, no lines at all.

Sid, I'm not familiar with OpenGL commands and how you have to set up the graphic space.

I founf ììd an opengl command reference here:
http://www.glprogramming.com/blue/
but half the time I struggle with what the commands mean.

I do notice though that the points (vertices) you're using all appear to be (0.,0.,0.) (you set arrays X,Y and Z to be zero) ! which would explain why I got nothing on screen if it's just plotting zero length lines as the points co-incide !

Am I right in deducing that you're expecting 7 lines to be plotted ?
.... in a 'co-ordinate space' which is rotated 22 deg. about each axis ?

I presume the 2 lines you're seeing are 2 of the 'axes' but it's not clear. And I get nothing running the code listed above.

I'm running Win7 btw but why that should affect things relative to your Win10 I couldn't imagine.
_________________
''Computers are incredibly rigid. They question nothing. Especialy input data.Human beings are incredibly trusting of computers and don't check input data. Together they are capable of cocking up even the simplest calculation ... Smile "
Back to top
View user's profile Send private message
stfark1



Joined: 02 Sep 2008
Posts: 131

PostPosted: Wed Jun 20, 2018 12:27 am    Post subject: Simple OpenGL Program Reply with quote

John Silver: I left out 3 statements by mistake where I set the input values to 1.:
after the below which set the values all to zero for the complete arrays:
x=0.
y=0.
z=0.
should have been additional codes:

x(2)=1.
y(4)=1.
z(6)=1.
this should have drawn the x,y,z axes but after changing the 1 to l, still did not work! Sid
Back to top
View user's profile Send private message
stfark1



Joined: 02 Sep 2008
Posts: 131

PostPosted: Thu Jun 21, 2018 1:29 pm    Post subject: Simple OpenGL Program Reply with quote

So Frustrated with this system, cannot post a screen shot so have to type in every line of code and other statements whenever I want to ask question ! BOO bad system!

I finally got the above program to work but there appears to be a memory management problem with the Fortran to OpenGL callable system, the minute that I add more code to above, I get "crazy" output data from OpenGL, zig zag lines all over the place. I would suggest exploring this problem as is not good for the system to act this way, Sid kraft
Back to top
View user's profile Send private message
dgurok



Joined: 26 May 2011
Posts: 42

PostPosted: Thu Jun 21, 2018 2:09 pm    Post subject: Reply with quote

stfark1, did you look at the opengl examples in ftn95 documentation? (use ftn95 /help)



Code:
      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)     
C
      CALL glColor3f(1.0,0.0,0.0)
      CALL glVertex2f(-0.5, -0.5)
C     
      CALL glColor3f(0.0,1.0,0.0)
      CALL glVertex2f(-0.5, 0.5)
C
      CALL glColor3f(0.0,0.0,1.0)     
      CALL glVertex2f( 0.5, 0.5)
C
      CALL glColor3f(1.0,0.0,0.0)     
      CALL glVertex2f( 0.5, -0.5)
      CALL glEnd()
      CALL glFlush()
      END


There is also another opengl example which shows you some rotations.
In general, I prefer to use SCC, because in the internet more useful examples are written in C++.

First you should read some simple opengl manuals and understand how opengl works in the basic structure.
Your main code has some basic fortran errors... Dimension N unknown, X,Y,Z initialized incorrectly... and some basic opengl calls are missing...
Back to top
View user's profile Send private message
John-Silver



Joined: 30 Jul 2013
Posts: 959
Location: Aerospace Valley

PostPosted: Thu Jun 21, 2018 9:30 pm    Post subject: Reply with quote

Solution Found !!!

I presume this is what you were expecting Sid ?

I dug around a few old forum posts and made a couple of changes/additions.
Don’t quote me but I think the solution was the moving of the rotations commands (glrotatef) outside the ‘glBegin / glEnd’ area of the code.
This hint was given by Ian Lambley in an old post where he was trying out opengl and made the comment relating to a different command.
It seems opengl has a certain ‘hierarchy’ of commands placement, you just can’t place them where you want to.
Note I also combined the 3 glrotatef’s into one. That might potentially have created a slightly different ‘axes’ orientation to the one you are aiming for.

PS – everyone’s jumped through the ‘how to post pics on the forums’ loop a few times !
I’ll post a guide shortly for you (and future newcomers) to cover that.

Remember we’re all learning with you here about opengl as it’s not used much.
Ian Lambley and DanRRight being the at the forefront brave ones that I've seen have delved into it’s murky depths in the past.
There may be others amongst the 'silent majority' of the 1000+ registered users but they only pop out of the woodwork sporadically). That really needs to be encouraged to change.

Anyway, here it is, in all it’s now coloured (another change) glory (or should that be gory ! ):-


_________________
''Computers are incredibly rigid. They question nothing. Especialy input data.Human beings are incredibly trusting of computers and don't check input data. Together they are capable of cocking up even the simplest calculation ... Smile "
Back to top
View user's profile Send private message
John-Silver



Joined: 30 Jul 2013
Posts: 959
Location: Aerospace Valley

PostPosted: Thu Jun 21, 2018 9:38 pm    Post subject: Reply with quote

... and here's exactly the code I used (note I also changed the Y size of the window so it would fit on my screen !) ...

Code:
!
!      v3b - corrected coords initialisation & a few other changes
!             incl. intro. colour & re-location ofrotation commands

      PROGRAM BASIC
      INCLUDE <clearwin.ins>,nolist
      INCLUDE <opengl.ins>,nolist
      DIMENSION X(8),Y(8),Z(8)
      INTEGER ctrl
      X=0.
      Y=0.
      Z=0.

      x(2)=1.
      y(4)=1.
      z(6)=1.


      i=winio@('%es%ca[Simple Opengl Sample]&')
      i=winio@('%sp%ww[no_border]%og[static]%lw',0, 0, 1000, 600, ctrl)

! set colour to Green
      CALL glClear(GL_COLOR_BUFFER_BIT)
      CALL glColor3f (0.0, 1.0, 0.0)


!      CALL glRotatef(22.0,1.0,0.0,0.0)
!      CALL glRotatef(22.0,0.0,1.0,0.0)
!      CALL glRotatef(22.0,0.0,0.0,1.0)
      CALL glRotatef(22.0,1.0,1.0,1.0)

      INDX=0

      CALL glBegin(GL_LINES)

      DO 10 I=1,7
      INDX=INDX+1
      IF (INDX .EQ. 8) GOTO 20
      CALL glVertex3f(X(INDX),Y(INDX),Z(INDX))
      CALL glVertex3f(X(INDX+1),Y(INDX+1),Z(INDX+1))
   10 CONTINUE
   20 CALL glEnd
      END

_________________
''Computers are incredibly rigid. They question nothing. Especialy input data.Human beings are incredibly trusting of computers and don't check input data. Together they are capable of cocking up even the simplest calculation ... Smile "
Back to top
View user's profile Send private message
John-Silver



Joined: 30 Jul 2013
Posts: 959
Location: Aerospace Valley

PostPosted: Fri Jun 22, 2018 8:05 am    Post subject: Reply with quote

Sid,
Sorry, I see you too got the code working, well done.
How did you manage it ? Was it different to how I did it (above) ?

For your "zig zag lines all over the place" code, you need to post the code ! for us to be able to try to help.

I didn't understand you're comment about why you can't paste code to the forum.
To do that 'copy' from your source file, put the cursor in the 'reply' edit box, then click on the 'code' button first, then 'paste' the copied code, THEN click the 'code' button again which will 'terminate' the designation as code.
Your code will appear in a whte background box.
Thn continue with any other comments.

Instructions for posting screenshots I'll post seperately.
_________________
''Computers are incredibly rigid. They question nothing. Especialy input data.Human beings are incredibly trusting of computers and don't check input data. Together they are capable of cocking up even the simplest calculation ... 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 -> General All times are GMT + 1 Hour
Page 1 of 1

 
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