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 axis numbering

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



Joined: 10 Mar 2008
Posts: 2227
Location: South Pole, Antarctica

PostPosted: Mon Mar 30, 2020 12:14 am    Post subject: OpenGL axis numbering Reply with quote

In Silverfrost/Salford library of EXAMPLES there exist an OpenGL example ANIMATE.FOR which I successfully used and then expanded knowing absolutely nothing more about OpenGL, just using this example. Wrote even 3D game using it. But where I did not succeed for 25 years is tic numbering of X an Y axis. Can anyone make numbering of each tics in this famous example ? The problem is that unlike draw_characters@('text',x,y,color) which you can call multiple times and each time the text will be plotted at the same point (x,y) or any other at your will, the glCallLists (nchars, GL_UNSIGNED_BYTE, 'text') which is analog of draw_characters@, shifts the position by the width and dimension of plottext text 'text' and you can not return it back and plot in the same place. As a result you never know exact position of plotted characters (or it is just me who does not know this). Ones per decade I return to numbering and every time fail miserably.

Code:

**********************************
*                                *
*      Trial OPENGL program      *
*                                *
**********************************

      subroutine spinDisplay(spin)
      include <opengl.ins>,nolist
      include <clearwin.ins>,nolist
      double precision spin
      logical do_draw
      common /animate_com/ do_draw

      if (do_draw)then
        call glClear (OR(GL_COLOR_BUFFER_BIT,GL_DEPTH_BUFFER_BIT))
        call glMatrixMode (GL_MODELVIEW)
        call glLoadIdentity()
        call glTranslated(0d0,0d0,-10d0)
        call glRotated(spin,1d0,0d0,0d0)
        call glCallList(101)
        call swap_opengl_buffers()
        spin=spin+2d0
      endif
      call temporary_yield@()
      end

      subroutine spinSlab()
      logical do_draw
      common /animate_com/ do_draw
      data do_draw/.TRUE./
      do_draw=.TRUE.
      end

      subroutine stopSlab()
      logical do_draw
      common /animate_com/ do_draw
      do_draw=.FALSE.
      end

      subroutine assemble_list
      include <clearwin.ins>,nolist
      include <opengl.ins>,nolist

      real*4 white_colour(4), grey_colour(4), dark_grey_colour(4)
      real*4 red_colour(4), yellow_colour(4), green_colour(4)
      real*4 blue_colour(4), purple_colour(4), cyan_colour(4)
      real*8 dimension,scale,d,fd,front,back
      integer flags,k
      integer hdc
      logical ok
      external opengl_proc
      data white_colour/1.0,1.0,1.0,1.0/
      data grey_colour/0.5,0.5,0.5,1.0/
      data dark_grey_colour/0.3,0.3,0.3,1.0/
      data red_colour/1.0,0.0,0.0,1.0/
      data yellow_colour/1.0,1.0,0.0,1.0/
      data green_colour/0.0,1.0,0.0,1.0/
      data blue_colour/0.0,0.0,1.0,1.0/
      data purple_colour/1.0,0.0,1.0,1.0/
      data cyan_colour/0.0,1.0,1.0,1.0/
      data front,back/-0.01d0,-0.5d0/

      call glEnable(GL_DEPTH_TEST)
      hDC=clearwin_info@('OPENGL_DEVICE_CONTEXT')
      call glColor3f(1.0,1.0,1.0)

      ok=wglUseFontOutlines(hDC, 0, 255, 1000, 0.0, 0.1,
     &                     WGL_FONT_POLYGONS,core4(0))
     
      call glMatrixMode (GL_MODELVIEW)
      call glLoadIdentity()
      call glTranslated(0d0,0d0,-10d0)
C
C  Clear the color and depth buffers.
C
      call glClear (OR(GL_COLOR_BUFFER_BIT,GL_DEPTH_BUFFER_BIT))
      dimension=2.2d0
      scale=dimension*0.9d0
      call glDisable(GL_LIGHTING)

      call glNewList(101,GL_COMPILE)


Last edited by DanRRight on Mon Mar 30, 2020 12:46 am; edited 11 times in total
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2227
Location: South Pole, Antarctica

PostPosted: Mon Mar 30, 2020 12:16 am    Post subject: Reply with quote

Code:

C Front face
      call glBegin(GL_POLYGON)
      call glColor3fv(blue_colour)
      call glVertex3d(-dimension,-dimension,front)
      call glVertex3d(-dimension, dimension,front)
      call glVertex3d( dimension, dimension,front)
      call glVertex3d( dimension,-dimension,front)
      call glEnd()
C Back face                         
      call glBegin(GL_POLYGON)
      call glColor3fv(yellow_colour)
      call glVertex3d(-dimension,-dimension,back)
      call glVertex3d( dimension,-dimension,back)
      call glVertex3d( dimension, dimension,back)
      call glVertex3d(-dimension, dimension,back)
      call glEnd()
C Top face
      call glBegin(GL_POLYGON)
      call glColor3fv(red_colour)
      call glVertex3d(-dimension, dimension,front)
      call glVertex3d(-dimension, dimension,back)
      call glVertex3d( dimension, dimension,back)
      call glVertex3d( dimension, dimension,front)
      call glEnd()
C Bottom face
      call glBegin(GL_POLYGON)
      call glColor3fv(green_colour)
      call glVertex3d( dimension,-dimension,front)
      call glVertex3d( dimension,-dimension,back)
      call glVertex3d(-dimension,-dimension,back)
      call glVertex3d(-dimension,-dimension,front)
      call glEnd()
C
C      Draw graph
C
      call glBegin(GL_LINES)
      call glColor3fv(white_colour)
      call glVertex2d(-scale,0d0)
      call glVertex2d(scale,0d0)
      call glVertex2d(0d0,-scale)
      call glVertex2d(0d0,scale)
      k=-10
      while(k .LE. 10) do
        call glVertex2d((scale/10)*k,0.0d0)
        call glVertex2d((scale/10)*k,0.1d0)
        call glVertex2d(0.0d0,(scale/10)*k)
        call glVertex2d(0.1d0,(scale/10)*k)
        k=k+1
      endwhile
      call glEnd()
      call glColor3fv(red_colour)
      call glBegin(GL_LINE_STRIP)
      d=-10d0
      while(d .LT. 10d0)do
        fd=5*(d/10)**3+3*(d/10)**2-d/10
        call glVertex2d(d*scale/10,fd*scale/10)
        d=d+0.05d0
      endwhile
      call glEnd()
      call glColor3fv(green_colour)

      call glBegin(GL_LINE_STRIP)
      d=-10d0
      while(d .LT. 10)do
        fd=5*(d/10)**3+6*(d/10)**2-d/10
        call glVertex2d(d*scale/10,fd*scale/10)
        d=d+0.05d0
      endwhile
      call glEnd()




Last edited by DanRRight on Mon Mar 30, 2020 12:38 am; edited 2 times in total
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2227
Location: South Pole, Antarctica

PostPosted: Mon Mar 30, 2020 12:16 am    Post subject: Reply with quote

Code:

      call glColor3fv(White_colour)
      call glListBase (1000)
      call glTranslated(0.15d0,scale*0.98,0d0)
      call glScaled(0.15d0,0.15d0,0.15d0)
      call glCallLists (4, GL_UNSIGNED_BYTE, '10.0')
      call glEndList()
      end
   
      subroutine myinit()
      call assemble_list()
      end


      subroutine myreshape(w,h)
      include <opengl.ins>,nolist
      integer w
      integer h
      double precision aspect_ratio
                     
      if(h.NE.0)then
        aspect_ratio=dble(w)/h

        call glMatrixMode (GL_PROJECTION)
        call glLoadIdentity ()
        call gluPerspective (30.0d0,aspect_ratio,1d0,15d0)
        call glViewport(0,0,w,h)
      endif

      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 myinit()
      else if(reason.EQ.'RESIZE')then
        w=clearwin_info@('OPENGL_WIDTH')
        h=clearwin_info@('OPENGL_DEPTH')
        call myreshape(w,h)
      else if(reason.EQ.'MOUSE_LEFT_CLICK')then
        call spinSlab()
      else if(reason.EQ.'MOUSE_RIGHT_CLICK')then
        call stopSlab()
      endif
      opengl_proc=2
      end

      program Animate
      include <clearwin.ins>,nolist
      double precision spin
      integer i,window
      integer opengl_proc
      external opengl_proc
      i=winio@('%es%ca[Rotating Slab]&')
!     i=winio@('%fn[Times New Roman]%ts&',3.0d0)
!      i=winio@('%fn[Arial]%ts&',0.1d0)
      i=winio@('%fn[Tahoma]%ts&',0.1d0)
      i=winio@('%bf&')
      i=winio@('%sp%ww[no_border]%pv%^og[double,depth16]%lw'
     &         ,0,0,650,650,opengl_proc,window)

      spin=0d0
      while(window .LT. 0)do
        call spinDisplay(spin)
      endwhile
      end

Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2227
Location: South Pole, Antarctica

PostPosted: Mon Mar 30, 2020 1:06 am    Post subject: Reply with quote

To get the essence of the problem just add one more absolutely similar line like this
Code:

      call glCallLists (4, GL_UNSIGNED_BYTE, '10.0')
      call glCallLists (4, GL_UNSIGNED_BYTE, '10.0')
and you will get plotted 10.010.0 instead of 10.0

Even if you add
Code:
      call glTranslated(0.d0, 0d0, 0d0)

to look like this
Code:

      call glCallLists (4, GL_UNSIGNED_BYTE, '10.0')
      call glTranslated(0.d0, 0d0, 0d0)
      call glCallLists (4, GL_UNSIGNED_BYTE, '10.0')
before second line to return the system of coordinates back to zero, this will not help you, all text plotting is corrupted forever. Things get worse in 3D case (this plot is essentially in 2D, the Z axis is not used, though could be added easily), there you are totally screwed, the text shifts both in X, Y and Z space unpredictably.

Drawing lines, polygons and everything else is absolutely predictable and extremely fast. In 64bits I ones plotted even 500 million polygons

Just the advise how to make
Code:

      call glCallLists (4, GL_UNSIGNED_BYTE, '10.0')
      call glCallLists (4, GL_UNSIGNED_BYTE, '10.0')
plotting just 10.0 with arbitrary scaling text size glScaled(0.15d0,0.15d0,0.15d0)
would help me immensely. Basically it is necessary for program to forget that it plotted something in previous call to glCallLists
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