Silverfrost Forums

Welcome to our forums

Fonts in OpenGL

25 Apr 2015 3:25 (Edited: 25 Apr 2015 9:02) #16235

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.

!     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)) 
      
 
25 Apr 2015 3:30 #16236
      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
26 Apr 2015 3:49 #16238

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

Please login to reply.