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 

Fonts in OpenGL

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



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

PostPosted: Sat Apr 25, 2015 4:25 am    Post subject: Fonts in OpenGL Reply with quote

Someone asked me time back how to control the fonts in OpenGL. I'm posting this example, otherwise it will be lost (even though posting such not that long example on phpBB with its length restrictions is not a pleasant thing. You do that many times and start over again. To post this I edited it 25 times at least swearing like hell). Some small help is inside but i suggest you just play with it and see how fonts are changed.
Code:

!     Dan RRight
!     2014 December 13
!     No rights reserved :)

      subroutine spinDisplay(spin)
      include <opengl.ins>
      include <clearwin.ins>
      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+1d0
      endif
1000      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>
      include <opengl.ins>

      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)

      ibase = glGenLists(96)               ! Storage For 96 Characters
!..................  Not all this works with wglUseFontOutlines .....................
!   ifont =CreateFont (-122,            ! Height Of Font
!     *            0,               ! Width Of Font
!     *            0,               ! Angle Of Escapement
!     *            0,               ! Orientation Angle
!     *            FW_BOLD,            ! Font Weight
!     *            .TRUE.,            ! Italic
!     *            .FALSE.,            ! Underline
!     *            .FALSE.,            ! Strikeout
!     *            ANSI_CHARSET,         ! Character Set Identifier
!     *            OUT_TT_PRECIS,         ! Output Precision
!     *            CLIP_DEFAULT_PRECIS,         ! Clipping Precision
!     *            ANTIALIASED_QUALITY,          ! Output Quality
!     *            or(FF_DONTCARE,DEFAULT_PITCH),   ! Family And Pitch
!     *            'Comic Sans MS' )   
!
!     *            ior(FF_DONTCARE,DEFAULT_PITCH),   ! Family And Pitch
!
!   ignor = SelectObject(hDC, ifont)                  ! Selects The Font We Want
!..............................................
      ok=wglUseFontOutlines(hDC, 0, 255, 1000, 0.0, 0.31, WGL_FONT_POLYGONS,core4(0))
     
 


Last edited by DanRRight on Sat Apr 25, 2015 10:02 am; edited 7 times in total
Back to top
View user's profile Send private message
DanRRight



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

PostPosted: Sat Apr 25, 2015 4:30 am    Post subject: Reply with quote

Code:

      call glMatrixMode (GL_MODELVIEW)
      call glLoadIdentity()
      call glTranslated(0d0,0d0,-10d0)

      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)

      call glColor3fv(red_colour)
      call glListBase (1000)
      call glTranslated(-3.d0,scale*0.0,0.2d0)
      call glScaled(1.5d0,1.5d0,1.5d0)
      call glCallLists (9, GL_UNSIGNED_BYTE, 'Clearwin+')
      call glEndList()

      end
   
      subroutine myinit()
      call assemble_list()
      end

      subroutine myreshape(w,h)
      include <opengl.ins>
      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>
      include <opengl.ins>
      integer w,h
      character*256 reason
      double precision spin

      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

        spin=270. ! 0d0
        i=-1
      while(i .LT. 0)do
        call spinDisplay(spin)
   if(spin.ge.360.d0) goto 1000
      endwhile
1000   continue

      else if(reason.EQ.'MOUSE_RIGHT_CLICK')then
        call stopSlab()
      endif
      opengl_proc=2
      end
!------------------------------------------------------
      Program Clearwin
      include <clearwin.ins>
      real*8 spin
      integer i,window
      integer opengl_proc
      external opengl_proc
      i=winio@('%es%ca[Rotating Logo]&')
      i=winio@('%fn[Arial]%ts&',1.0d0)

      i=winio@('%bf&')
      i=winio@('%sp%ww[no_border]%pv%^og[double,depth16]%lw',0,0,1050,750,opengl_proc,window)

      spin=90.
      while(window .LT. 0)do
        call spinDisplay(spin)
      if(spin.ge.360.d0) goto 1000
      endwhile
1000   continue
      end
Back to top
View user's profile Send private message
John-Silver



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

PostPosted: Sun Apr 26, 2015 4:19 am    Post subject: Reply with quote

Quote:
Some small help is inside but i suggest you just play with it and see how fonts are changed.


All I see is 'Clearwin+' and when I click on screen it rotates up from a 'flat' position.
Is that all its supposed to do ?
I don't see any 'Help' as you mention.

One small comment, if you re-size the window, the text disappears (until the blank screen is clicked on.
Back to top
View user's profile Send private message
DanRRight



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

PostPosted: Sun Apr 26, 2015 4:49 pm    Post subject: Reply with quote

Program just shows how to set the fonts. I suffered from ugly fonts for a decade because there is no OpenGL help for this Fortran. Then i found on my harddrive this program, i do not know the source of it, probably i played with it taking from somewhere long long ago and then completely forgot about it.

Fonts are defined by the chosen %fn in main program and settings in

wglUseFontOutlines(hDC, 0, 255, 1000, 0.0, 0.31, WGL_FONT_POLYGONS,core4(0))

For the latter one the help is in the code:

!.................. Not all this works with wglUseFontOutlines .....................
! ifont =CreateFont (-122, ! Height Of Font
! * 0, ! Width Of Font
! * 0, ! Angle Of Escapement
! * 0, ! Orientation Angle
! * FW_BOLD, ! Font Weight
! * .TRUE., ! Italic
! * .FALSE., ! Underline
! * .FALSE., ! Strikeout
! * ANSI_CHARSET, ! Character Set Identifier
! * OUT_TT_PRECIS, ! Output Precision
! * CLIP_DEFAULT_PRECIS, ! Clipping Precision
! * ANTIALIASED_QUALITY, ! Output Quality
! * or(FF_DONTCARE,DEFAULT_PITCH), ! Family And Pitch
! * 'Comic Sans MS' )
!
! * ior(FF_DONTCARE,DEFAULT_PITCH), ! Family And Pitch
!
! ignor = SelectObject(hDC, ifont) ! Selects The Font We Want
!...

Further playing with the source you can easily make other things fixed (like bad resize). BTW, I had OpenGL examples on this forum, they show how to resize
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 -> ClearWin+ 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