Announcement

Collapse
No announcement yet.

OpenGL how to rotate text label

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • OpenGL how to rotate text label

    Finally, I have found this OpenGL section.

    I'm struggling to rotate a text label namely the "Height" of a triangle to 90 degrees with the horizontal.

    All my labels are now horizontally aligned.
    How do I rotate the text label to certain degrees with respect to the horizontal?

    ?


    Failing code
    Code:
    #COMPILE EXE
    #DIM ALL
    %UNICODE = 1
    #INCLUDE "win32api.inc"
    #INCLUDE "gl.inc"
    #INCLUDE "glu.inc"
    
     GLOBAL hDlg, hDlg2, hDC, hRC AS DWORD
     GLOBAL FontBaseUni  AS DWORD
    
    FUNCTION PBMAIN() AS LONG
       DIALOG NEW PIXELS, 0, "Main Screen",620,60,_
             180, 40,%WS_OVERLAPPEDWINDOW TO hDlg
       DIALOG SHOW MODAL hdlg CALL dlgproc
    END FUNCTION
    
    CALLBACK FUNCTION dlgproc()
       SELECT CASE CB.MSG
          CASE %WM_INITDIALOG
               OpenDialog2
                DrawScene
       END SELECT
    END FUNCTION
    
    SUB OpenDialog2
       DIALOG NEW PIXELS, 0, "OpenGL Canvas", _
           20,50, 620, 540,%WS_VISIBLE OR %WS_POPUP TO hDlg2
       DIALOG SHOW MODELESS hdlg2 CALL dlgproc2
    END SUB
    
    
    CALLBACK FUNCTION dlgproc2()
       SELECT CASE CB.MSG
    
          CASE %WM_INITDIALOG
               GetRenderContext
               InitializeScene
    
          CASE %WM_SIZE
               ResizeScene LO(WORD, CB.LPARAM), HI(WORD, CB.LPARAM)
               DrawScene
    
          CASE %WM_PAINT
               DrawScene
    
          CASE %WM_CLOSE
              ' Delete All 96 Characters
                glDeleteLists(FontBaseUni, 96)
                 wglmakecurrent %null, %null 'unselect rendering context
                 wgldeletecontext hRC        'delete the rendering context
                 releasedc hDlg2, hDC         'release device context
       END SELECT
    END FUNCTION
    
    SUB GetRenderContext
       LOCAL pfd AS PIXELFORMATDESCRIPTOR   'pixel format properties for device context
       pfd.nSize       =  SIZEOF(PIXELFORMATDESCRIPTOR)
       pfd.nVersion    =  1
       pfd.dwFlags     = %pfd_draw_to_window OR %pfd_support_opengl OR %pfd_doublebuffer
       pfd.dwlayermask = %pfd_main_plane
       pfd.iPixelType  = %pfd_type_rgba
       pfd.ccolorbits  = 24
       pfd.cdepthbits  = 24
    
       hDC = GetDC(hDlg2)                                      'DC for dialog
       SetPixelFormat(hDC, ChoosePixelFormat(hDC, pfd), pfd)  'set properties of device context
       hRC = wglCreateContext (hDC)                           'get rendering context
       wglMakeCurrent hDC, hRC                                'make the RC current
    END SUB
    
    SUB InitializeScene
       glClearColor 245,255,250,1     'sets color to be used with glClear
       glClearDepth 1           'sets zvalue to be used with glClear
    
    
       glDepthFunc %gl_less                                'specify how depth-buffer comparisons are made
       glEnable %gl_depth_test                             'enable depth testing
       glShadeModel %gl_smooth                             'smooth shading
       glHint %gl_perspective_correction_hint, %gl_nicest  'best quality rendering
    
    
     ' Build the Unicode fonts -- use a larger height
     ' for clarity
       Build_FontUni( 28 , 900 )
    END SUB
    
    SUB ResizeScene (w AS LONG, h AS LONG)
       glViewport 0, 0, w, h             'resize viewport to match window size
       glMatrixMode %gl_projection       'select the projection matrix
       glLoadIdentity                    'reset the projection matrix
       gluPerspective 45, w/h, 0.1, 100  'calculate the aspect ratio of the Window
       glMatrixMode %gl_modelview        'select the modelview matrix
    END SUB
    
    SUB DrawScene
       glClear %gl_color_buffer_bit OR %gl_depth_buffer_bit  'clear buffers
       glLoadIdentity               'clear the modelview matrix
       glBegin %gl_triangles        'select triangles as primitive
       glcolor3ub 25,200,0        'set default vertex color
       glvertex3f   0, 0.5, -4     'vertex1
       glvertex3f  -0.5, -0.5, -4     'vertex2
       glvertex3f  0.5, -0.5, -4     'vertex3
       glEnd
    
      ' label center
       glPrintStUni("   "+ CHR$$(&h2104) ,-0.2 ,0.8,-4 , 1,0,1,0)
    
       ' label height -- need to rotate this text by 90 degrees
        glPrintStUni("Height " ,0.73 ,0,-4 , 1,0,1,0)
    
       ' label width
        glPrintStUni("Width " ,-0.25 ,-0.9,-4 , 1,0,1,0)
    
       SwapBuffers hDC              'display the buffer (image)
    END SUB
    
    
    
    
    
    '=========================================
    ' Build the Unicode fonts base
    ' font_weight = 300 for normal font
    '             = 900 for bold heavy font
    ' https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows/781771-display-centerline-symbol?p=781834#post781834
    SUB Build_FontUni( font_height AS SINGLE, font_weight AS SINGLE )
        LOCAL hfont,hWantfont AS DWORD
     '  Storage For 96 Characters
        FontBaseUni = glGenLists(96)
    
    '         hFONT =CreateFont(
    '           int nHeight,               // height of font
    '           int nWidth,                // average character width
    '           int nEscapement,           // angle of escapement
    '           int nOrientation,          // base-line orientation angle
    '           int fnWeight,              // font weight
    '           DWORD fdwItalic,           // italic attribute option
    '           DWORD fdwUnderline,        // underline attribute option
    '           DWORD fdwStrikeOut,        // strikeout attribute option
    '           DWORD fdwCharSet,          // character set identifier
    '           DWORD fdwOutputPrecision,  // output precision
    '           DWORD fdwClipPrecision,    // clipping precision
    '           DWORD fdwQuality,          // output quality
    '           DWORD fdwPitchAndFamily,   // pitch and family
    '           LPCTSTR lpszFace           // typeface name
    ');
          hfont = CreateFont(-font_height,_  'Size of font
                         0,_
                         0,_
                         0,_
                         font_weight,_
                         %FALSE,_       'italic
                         %FALSE,_       'underline
                         %FALSE,_       'strikeout
                         %ANSI_CHARSET,_
                         %OUT_TT_PRECIS,_
                         %CLIP_DEFAULT_PRECIS,_
                         %ANTIALIASED_QUALITY,_          ' output quality
                         %FF_DONTCARE OR %DEFAULT_PITCH,_
                         "Arial Unicode MS")
          ' Selects The Font that We have Created
          hWantfont = SelectObject(hDC, hfont)
          ' Note that we are extending fonts to &h2104
          ' as we need to have centerline symbol
          ' Need to change this for other wanted symbols
          ' when that need arises
          wglUseFontBitmaps(hDC, 32, &h2104-30, FontBaseUni)
          SelectObject(hDC, hWantfont)
          DeleteObject(hfont)
       END SUB
    
    
    
     '===========================
    ' Display the given string on the screen in Unicode
    ' https://forum.powerbasic.com/forum/user-to-user-discussions/source-code/24993-opengl-outline-font-tutorial
    ' https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows/781771-display-centerline-symbol?p=781834#post781834
      SUB glPrintStUni( GivString AS WSTRING,_
             Xcoord AS DOUBLE, Ycoord AS DOUBLE, Zcoord AS DOUBLE, _
             ColorR AS SINGLE, ColorG AS SINGLE, ColorB AS SINGLE , _
             FlagFontBig AS LONG )
    
         ' Color the letters
           glColor3f(ColorR,ColorG,ColorB)
         ' Location of the string on screen
           glRasterPos3f(Xcoord, Ycoord, Zcoord)
         ' Pushes The Display List Bits
           glPushAttrib(%GL_LIST_BIT)
    
            'use Unicode font
             glListBase( FontBaseUni-32 )
    
    
        ' Draws The Display List Text
          glCallLists( LEN(GivString), %GL_SHORT , BYVAL STRPTR(GivString) )
         ' Pops The Display List Bits
          glPopAttrib()
       END SUB
    Last edited by Tim Lakinir; 9 Jun 2019, 01:22 PM.

  • #2
    Probably the sub glPrintStUni needs to be amended to get text rotation?

    Comment


    • #3
      I have modified the Drawscene routine but could not get it to work!

      Code:
      SUB DrawScene
      
         glClear %gl_color_buffer_bit OR %gl_depth_buffer_bit  'clear buffers
         glLoadIdentity               'clear the modelview matrix
         glBegin %gl_triangles        'select triangles as primitive
         glcolor3ub 25,200,0        'set default vertex color
         glvertex3f   0, 0.5, -4     'vertex1
         glvertex3f  -0.5, -0.5, -4     'vertex2
         glvertex3f  0.5, -0.5, -4     'vertex3
         glEnd
      
        ' label center
         glPrintStUni("   "+ CHR$$(&h2104) ,-0.2 ,0.8,-4 , 1,0,1,0)
      
      
           ' label width
          glPrintStUni("Width " ,-0.25 ,-0.9,-4 , 1,0,1,0)
      
      
          STATIC Rotation AS SINGLE
              rotation = 45
            ' Position the text
         '   glTranslatef 1.1! * COS(Rotation / 16.0!), 0.8! * SIN(Rotation / 20.0!), -3.0!
            ' Rotate on the X axis
          '  glRotatef Rotation, 1.0!, 0.0!, 0.0!
            ' Rotate on the Y axis
          '  glRotatef Rotation * 1.2!, 0.0!, 1.0!, 0.0!
            ' Rotate on the Z axis
            glRotatef Rotation * 1.4!, 0.0!, 0.0!, 1.0!
            ' Center on X, Y, Z axis
            glTranslatef -0.35!, -0.35!, 0.1!
      
         ' label height -- need to rotate this text by 90 degrees
          glPrintStUni("Height " ,0.73 ,0,-4 , 1,0,1,0)
      
      
         SwapBuffers hDC              'display the buffer (image)
      END SUB

      Comment


      • #4
        I hope that someone can direct me to what is wrong. Your participation is duly noted ,
        you might want to post a comment to help me untangle text rotation in OpenGL

        Comment


        • #5
          Quick and dirty.....

          Code:
          #COMPILE EXE
          #DIM ALL
          %UNICODE = 1
          #INCLUDE "win32api.inc"
          #INCLUDE "gl.inc"
          #INCLUDE "glu.inc"
          %fontlist=1
           GLOBAL hDlg, hDC, hRC AS DWORD
          
          MACRO SetglColor4ub(clr, alpha)=glColor4ub(GetRValue(clr), GetGValue(clr), GetBValue(clr), alpha)
          
          FUNCTION PBMAIN() AS LONG
             DIALOG NEW PIXELS, 0, "Main Screen",20, 20,_
                   620, 540, %WS_OVERLAPPEDWINDOW TO hDlg
             DIALOG SHOW MODAL hdlg CALL dlgproc
          END FUNCTION
          
          CALLBACK FUNCTION dlgproc()
             SELECT CASE CB.MSG
          
                CASE %WM_INITDIALOG
                     GetRenderContext
                     InitializeScene
          
                CASE %WM_SIZE
                     ResizeScene LO(WORD, CB.LPARAM), HI(WORD, CB.LPARAM)
                     DrawScene
          
                CASE %WM_PAINT
                     DrawScene
          
                CASE %WM_CLOSE
          
                      glDeleteLists(%fontlist, 1)
                       wglmakecurrent %null, %null 'unselect rendering context
                       wgldeletecontext hRC        'delete the rendering context
                       releasedc hDlg, hDC         'release device context
             END SELECT
          END FUNCTION
          
          SUB GetRenderContext
             LOCAL pfd AS PIXELFORMATDESCRIPTOR   'pixel format properties for device context
             pfd.nSize       =  SIZEOF(PIXELFORMATDESCRIPTOR)
             pfd.nVersion    =  1
             pfd.dwFlags     = %pfd_draw_to_window OR %pfd_support_opengl OR %pfd_doublebuffer
             pfd.dwlayermask = %pfd_main_plane
             pfd.iPixelType  = %pfd_type_rgba
             pfd.ccolorbits  = 24
             pfd.cdepthbits  = 24
          
             hDC = GetDC(hDlg)                                      'DC for dialog
             SetPixelFormat(hDC, ChoosePixelFormat(hDC, pfd), pfd)  'set properties of device context
             hRC = wglCreateContext (hDC)                           'get rendering context
             wglMakeCurrent hDC, hRC                                'make the RC current
          END SUB
          
          SUB InitializeScene
             glClearColor 245,255,250,1     'sets color to be used with glClear
             glClearDepth 1           'sets zvalue to be used with glClear
          
          
             glDepthFunc %gl_less                                'specify how depth-buffer comparisons are made
             glEnable %gl_depth_test                             'enable depth testing
             glShadeModel %gl_smooth                             'smooth shading
             glHint %gl_perspective_correction_hint, %gl_nicest  'best quality rendering
          
             oglCreateFontList(hDlg, %fontlist, "Arial", 1, 0)
          END SUB
          
          SUB ResizeScene (w AS LONG, h AS LONG)
             glViewport 0, 0, w, h             'resize viewport to match window size
             glMatrixMode %gl_projection       'select the projection matrix
             glLoadIdentity                    'reset the projection matrix
             gluPerspective 45, w/h, 1, 10  'calculate the aspect ratio of the Window
             glMatrixMode %gl_modelview        'select the modelview matrix
          END SUB
          
          SUB DrawScene
             glMatrixMode(%gl_modelview)
             glClear %gl_color_buffer_bit OR %gl_depth_buffer_bit  'clear buffers
             glLoadIdentity               'clear the modelview matrix
             glBegin %gl_triangles        'select triangles as primitive
             glcolor3ub 25,200,0        'set default vertex color
             glvertex3f   0, 0.5, -4     'vertex1
             glvertex3f  -0.5, -0.5, -4    'vertex2
             glvertex3f  0.5, -0.5, -4     'vertex3
             glEnd
          
          
          'glPrintStUni(GivString AS WSTRING,_
          '         Xcoord AS DOUBLE, Ycoord AS DOUBLE, Zcoord AS DOUBLE, _
          '         FColor AS SINGLE, _
          '         fontht AS SINGLE, _
          '         Rotang AS SINGLE)
          
             glPrintStUni("Height", 0, 0.5, -4, %RED, .25, 45)
             glPrintStUni("Width " , -0.25 ,-0.9, -4, %GREEN, .25, -45)
             SwapBuffers hDC              'display the buffer (image)
          
          END SUB
          
          SUB glPrintStUni(GivString AS STRING,_
                   Xcoord AS DOUBLE, Ycoord AS DOUBLE, Zcoord AS DOUBLE, _
                   FColor AS SINGLE, _
                   fontht AS SINGLE, _
                   Rotang AS SINGLE)
            glPolygonMode(%GL_FRONT_AND_BACK, %GL_FILL)
            glListBase(%fontlist)  '%contourfontlist) '
            SetglColor4ub(FColor, 100)
            glLineWidth(1) 'Keep at 1 called list is printer aware
            glPushMatrix
            glLoadIdentity()
            glTranslated(Xcoord, Ycoord, -4) 'Zcoord)
            glScalef(fontht, fontht, 1)
            glRotated(rotang, 0, 0, 1)
            glCallLists(LEN(GivString), %GL_UNSIGNED_BYTE, BYVAL STRPTR(GivString))
            glPopMatrix()
          END SUB
          
          FUNCTION oglCreateFontList(BYVAL hWnd AS DWORD, BYVAL listno AS LONG, BYREF fontname AS STRING, BYVAL fwt AS LONG, BYVAL fitalic AS LONG) AS SINGLE
              REGISTER c  AS LONG
              LOCAL fs      AS LOGFONTA
              LOCAL newfont, oldfont AS DWORD
              LOCAL bDC  AS DWORD
              bDC=GetDC(%HWND_DESKTOP)
              fs.lfHeight = 6 'Doesn't Matter..
              fs.lfWidth = 0
              fs.lfEscapement = 0
              fs.lfOrientation = 0
              fs.LfWeight = IIF(fwt=0, %FW_NORMAL, %FW_BOLD)
              fs.lfitalic = IIF(fitalic, 1, 0)
              fs.lfCharSet = %ANSI_CHARSET
              fs.lfoutprecision = %OUT_TT_ONLY_PRECIS '%OUT_DEVICE_PRECIS   '%OUT_DEFAULT_PRECIS
              fs.lfClipPrecision = %CLIP_DEFAULT_PRECIS
              fs.lfQuality = %PROOF_QUALITY '%DEFAULT_QUALITY
              fs.lfPitchAndFamily = %DEFAULT_PITCH OR %FF_DONTCARE
              fs.lforientation = 0
              fs.lfFaceName = fontname
              newfont = CreateFontIndirectA(fs)
              IF newfont THEN
          
                oldfont=SelectObject(bDC, newfont)
                DIM cgm(255) AS LOCAL GLYPHMETRICSFLOAT
                wglUseFontOutlines(bDC, 0, 128, listno, 0, 0, %WGL_FONT_POLYGONS, VARPTR(cgm(0)))
                LOCAL maxy AS SINGLE
                SelectObject(bDC, oldfont)
                DeleteObject(newfont)
                maxy=1/cgm(ASC("A")).gmfBlackBoxY
                FUNCTION=maxy
          
              END IF
              ReleaseDC(hWnd, bDC)
          END FUNCTION
          "Show me a young Conservative and I'll show you someone with no heart. Show me an old Liberal and I'll show you someone with no brains." ― Winston Churchill
          "Socialism is the philosophy of failure, the creed of ignorance and the gospel of envy." ― Winston Churchill

          Comment


          • #6
            Awesome man, great thanks to you Doug , that's what I needed

            Comment


            • #7
              Hi Doug, using your program I wasn't able to display special characters such as the centerline symbol

              In your program of post #5, I have modified your code by adding this centerline symbol CHR$$(&h2104)

              Code:
                 glPrintStUni("Width "+ CHR$$(&h2104) , -0.25 ,-0.9, -4, %GREEN, .25, -45)
              It only display a ? rather than the centerline symbol, how do I add unicode symbols into the program

              Comment


              • #8
                For the last time; you must choose a font face that contains the particular character for that character to show.

                It looks to me that the code in post #5 uses "Arial". Arial does not have a character at &h2104, so no centerline symbol.

                USE CHARACTER MAP TO VERIFY THAT FONT CONTAINS CHARACTER(S) YOU NEED!

                Cheers,
                Dale

                Comment


                • #9
                  Dale,

                  when I posted post #7 , I have actually place the following code as well and with those fonts added it also didn't work
                  You can test it out by yourself

                  Code:
                    ' Create the rotated fonts
                     oglCreateFontList(hDlg, %fontlist, "Arial Unicode MS", 1, 0)
                  Hence it didn't work even when using Arial Unicode MS font (which was used successfully in post #1 to display the centerline symbol)

                  Comment


                  • #10
                    But you didn't say that. And it still didn't work for some reason,
                    Dale

                    Comment


                    • #11
                      Originally posted by Tim Lakinir View Post
                      Dale,

                      when I posted post #7 , I have actually place the following code as well and with those fonts added it also didn't work
                      You can test it out by yourself

                      Code:
                      ' Create the rotated fonts
                      oglCreateFontList(hDlg, %fontlist, "Arial Unicode MS", 1, 0)
                      Hence it didn't work even when using Arial Unicode MS font (which was used successfully in post #1 to display the centerline symbol)
                      Notes:

                      1) "Arial Unicode MS" did not include the centerline symbol, at least on my machine.

                      2) It's important to understand that the function wglUseFontOutlines creates lists containing polygons representing each character in the font. It is my opinion this should be limited to to only the standard characters typically used, at most the first 256 characters of the ascii table. Also since for the purposes here, the first 32 characters are irrelevant, for sure. I point this out because lists created using all the characters in a unicode set would be huge, and very inefficient (and may not be possible due to opengl limitations) Therefore, I took a different approach, by...

                      3) You will see a function oglCreateSymbolList, I created, to create a list for only 1 item in a font set. I think this is most efficient. You can create as many single symbols as you would like, but I'd recommend an equate to ID each different symbol you would want to create and use, as in the code below.

                      4) Keep the lists straight through equates. If not overwritten, create once, reuse many.

                      5) The method I used here for the centerline symbol, may not be a guaranteed one, as it depends on the font definition on the users computer. I think if it were me, I'd create a list, and draw my own....just to be safe. On my machine, "Microsoft Sans Serif", had this symbol defined, and should be pretty universal (?).

                      6) Just for demo, I created a label using another font. Just to demonstrated how multiple fonts can be used, without overwriting a previously created font list.

                      Here is the revised code, with a bit more commenting...(Still quick and dirty)

                      Code:
                      #COMPILE EXE
                      #DIM ALL
                      
                      #INCLUDE "win32api.inc"
                      #INCLUDE "gl.inc"
                      #INCLUDE "glu.inc"
                      'Since creating lists of polygons from a font for each character,
                      'let's try to minimize to only necessary characters.
                      %BegChar=32  'When defining character lists from fonts, the beginning character to begin with.
                      %EndChar=126 'the end character to define.  Standard use characters from 32 to 126.
                      
                      %fontlist=1
                      %diasymlist=%fontlist+%EndChar-1
                      %altfontlist=%diasymlist+1
                      
                      GLOBAL hDlg, hDC, hRC AS DWORD
                      
                      MACRO SetglColor4ub(clr, alpha)=glColor4ub(GetRValue(clr), GetGValue(clr), GetBValue(clr), alpha)
                      
                      FUNCTION PBMAIN() AS LONG
                         DIALOG NEW PIXELS, 0, "Main Screen",20, 20,_
                               620, 540, %WS_OVERLAPPEDWINDOW TO hDlg
                         DIALOG SHOW MODAL hdlg CALL dlgproc
                      END FUNCTION
                      
                      CALLBACK FUNCTION dlgproc()
                         SELECT CASE CB.MSG
                      
                            CASE %WM_INITDIALOG
                                 GetRenderContext
                                 InitializeScene
                      
                            CASE %WM_SIZE
                                 ResizeScene LO(WORD, CB.LPARAM), HI(WORD, CB.LPARAM)
                                 DrawScene
                      
                            CASE %WM_PAINT
                                 DrawScene
                      
                            CASE %WM_CLOSE
                      
                                  glDeleteLists(%fontlist, 1)
                                  wglmakecurrent %null, %null 'unselect rendering context
                                  wgldeletecontext hRC        'delete the rendering context
                                  releasedc hDlg, hDC         'release device context
                         END SELECT
                      END FUNCTION
                      
                      SUB GetRenderContext
                         LOCAL pfd AS PIXELFORMATDESCRIPTOR   'pixel format properties for device context
                         pfd.nSize       =  SIZEOF(PIXELFORMATDESCRIPTOR)
                         pfd.nVersion    =  1
                         pfd.dwFlags     = %pfd_draw_to_window OR %pfd_support_opengl OR %pfd_doublebuffer
                         pfd.dwlayermask = %pfd_main_plane
                         pfd.iPixelType  = %pfd_type_rgba
                         pfd.ccolorbits  = 24
                         pfd.cdepthbits  = 24
                      
                         hDC = GetDC(hDlg)                                      'DC for dialog
                         SetPixelFormat(hDC, ChoosePixelFormat(hDC, pfd), pfd)  'set properties of device context
                         hRC = wglCreateContext (hDC)                           'get rendering context
                         wglMakeCurrent hDC, hRC                                'make the RC current
                      END SUB
                      
                      SUB InitializeScene
                         glClearColor 245,255,250,1     'sets color to be used with glClear
                         glClearDepth 1           'sets zvalue to be used with glClear
                      
                      
                         glDepthFunc %gl_less                                'specify how depth-buffer comparisons are made
                         glEnable %gl_depth_test                             'enable depth testing
                         glShadeModel %gl_smooth                             'smooth shading
                         glHint %gl_perspective_correction_hint, %gl_nicest  'best quality rendering
                      
                         oglCreateFontList(hDlg, %fontlist, "Microsoft Sans Serif", 1, 0)
                         oglCreateFontList(hDlg, %altfontlist, "Courier New", 1, 1)
                      
                         oglCreateSymbolList(hDlg, %diasymlist, &H2104 , "Microsoft Sans Serif", 1, 0) '&H2104
                      END SUB
                      
                      SUB ResizeScene (w AS LONG, h AS LONG)
                         glViewport 0, 0, w, h             'resize viewport to match window size
                         glMatrixMode %gl_projection       'select the projection matrix
                         glLoadIdentity                    'reset the projection matrix
                         gluPerspective 45, w/h, 1, 10  'calculate the aspect ratio of the Window
                         glMatrixMode %gl_modelview        'select the modelview matrix
                      END SUB
                      
                      SUB DrawScene
                         glMatrixMode(%gl_modelview)
                         glClear %gl_color_buffer_bit OR %gl_depth_buffer_bit  'clear buffers
                         glLoadIdentity               'clear the modelview matrix
                         glBegin %gl_triangles        'select triangles as primitive
                         glcolor3ub 25,200,0        'set default vertex color
                         glvertex3f   0, 0.5, -4     'vertex1
                         glvertex3f  -0.5, -0.5, -4    'vertex2
                         glvertex3f  0.5, -0.5, -4     'vertex3
                         glEnd
                      
                      
                      'glPrintSt(GivString AS WSTRING,_
                      '         Xcoord AS DOUBLE, Ycoord AS DOUBLE, Zcoord AS DOUBLE, _
                      '         FColor AS SINGLE, _
                      '         fontht AS SINGLE, _
                      '         Rotang AS SINGLE, _
                      '         Opt uselast as long)
                         glPushMatrix
                         glPrintSt("Height ", %fontlist, 0, 0.5, -4, %RED, .25, 45) : glCallList(%diasymlist)
                         glPrintSt(" suffix", %fontlist, 0, 0, 0, %RED, 0, 0, 1)
                         glPopMatrix()
                         glPushMatrix
                         glPrintSt("Width" , %fontlist, -0.25 ,-0.9, -4, %GREEN, .25, -45)
                         glPrintSt("Font2"+CHR$(%endchar), %altfontlist, 0.5 ,-0.9, -4, %BLUE, .25, 0) 'just add %endchar to test if last char is there..
                         SwapBuffers hDC              'display the buffer (image)
                      
                      END SUB
                      
                      SUB glPrintSt(GivString AS STRING, _
                               baselist AS DWORD, _         'beginning of List of prev created Font list to use
                               Xcoord AS DOUBLE, Ycoord AS DOUBLE, Zcoord AS DOUBLE, _
                               FColor AS SINGLE, _
                               fontht AS SINGLE, _
                               Rotang AS SINGLE, _
                               OPT uselast AS LONG) 'if true do not change position. (continuation)
                      
                        glPolygonMode(%GL_FRONT_AND_BACK, %GL_FILL)
                        glListBase(baselist)
                        SetglColor4ub(FColor, 100)
                        glLineWidth(1) 'Keep at 1 called list is printer aware
                      
                        IF %begChar>0 THEN 'a kludge since glCallLists can't be offset.  The string of character codes
                                            'passed to glListsts, is zero based.
                                            'So revise the string to reflect the char code we started with. (%begChar)
                                            '(Slower but saves number of lists)
                          LOCAL tmpstr AS STRING
                          LOCAL c AS DWORD
                      
                          FOR c=1 TO LEN(GivString)
                            tmpstr+=CHR$(ASC(GivString, c)-%begChar)
                          NEXT c
                        ELSE
                          tmpstr=GivString
                        END IF
                        IF ISMISSING(uselast) OR ISFALSE(uselast) THEN
                          glLoadIdentity()
                          glTranslated(Xcoord, Ycoord, -4) 'Zcoord)
                          glScalef(fontht, fontht, 1)
                          glRotated(rotang, 0, 0, 1)
                        END IF
                        glCallLists(LEN(tmpStr), %GL_UNSIGNED_BYTE, BYVAL STRPTR(tmpStr))
                      END SUB
                      
                      FUNCTION oglCreateSymbolList(BYVAL hWnd AS DWORD, BYVAL listno AS LONG, BYVAL CharNo AS LONG, BYREF fontname AS STRING, BYVAL fwt AS LONG, BYVAL fitalic AS LONG) AS SINGLE
                          REGISTER c  AS LONG
                          LOCAL fs    AS LOGFONTW
                          LOCAL newfont, oldfont AS DWORD
                          LOCAL bDC  AS DWORD
                          LOCAL maxy AS SINGLE
                      
                          'This function Creates a symbol list (one list), based on the fontname, and character code passed.
                          'It returns the approx max char height if successful.
                          'NOTE: There is no guarantee that the symbol exists as desired in the font called by fontname!
                      
                          bDC=GetDC(%HWND_DESKTOP)
                          fs.lfHeight = 6 'Doesn't Matter..
                          fs.lfWidth = 0
                          fs.lfEscapement = 0
                          fs.lfOrientation = 0
                          fs.LfWeight = IIF(fwt=0, %FW_NORMAL, %FW_BOLD)
                          fs.lfitalic = IIF(fitalic, 1, 0)
                          fs.lfCharSet = %ANSI_CHARSET
                          fs.lfoutprecision = %OUT_TT_ONLY_PRECIS
                          fs.lfClipPrecision = %CLIP_DEFAULT_PRECIS
                          fs.lfQuality = %PROOF_QUALITY
                          fs.lfPitchAndFamily = %DEFAULT_PITCH OR %FF_DONTCARE
                          fs.lforientation = 0
                          fs.lfFaceName = fontname
                          newfont = CreateFontIndirectW(fs)
                          IF newfont THEN
                            oldfont=SelectObject(bDC, newfont)
                            DIM cgm(0) AS LOCAL GLYPHMETRICSFLOAT
                            wglUseFontOutlinesW(bDC, Charno, 1, listno, 0, 0, %WGL_FONT_POLYGONS, VARPTR(cgm(0)))
                      
                            SelectObject(bDC, oldfont)
                            DeleteObject(newfont)
                            maxy=1/cgm(0).gmfBlackBoxY
                            FUNCTION=maxy
                          END IF
                          ReleaseDC(hWnd, bDC)
                      END FUNCTION
                      
                      
                      FUNCTION oglCreateFontList(BYVAL hWnd AS DWORD,_
                          BYVAL listno AS LONG, _     'Beginning list number
                          BYREF fontname AS STRING, _ 'Fontname, windows will sub closest font if not found
                          BYVAL fwt AS LONG, _        'Bold if true
                          BYVAL fitalic AS LONG) _    'Italic if true
                          AS SINGLE
                      
                          REGISTER c  AS LONG
                          LOCAL fs      AS LOGFONTA
                          LOCAL newfont, oldfont AS DWORD
                          LOCAL bDC  AS DWORD
                          LOCAL maxy AS SINGLE
                      
                          'This function Creates lists of polygons, each list defines 1 Ascii character, based on the fontname, fwt, and fitalic,
                          'beginning with %begchar and ending with %endchar (the first 32 characters, are useless for this excersize).
                          ' This only needs to be called once, unless the lists are overwritten, or wish to be redefined.
                          'It returns the approx max char height if successful.
                          bDC=GetDC(%HWND_DESKTOP)
                          fs.lfHeight = 6 'Doesn't Matter..
                          fs.lfWidth = 0
                          fs.lfEscapement = 0
                          fs.lfOrientation = 0
                          fs.LfWeight = IIF(fwt=0, %FW_NORMAL, %FW_BOLD)
                          fs.lfitalic = IIF(fitalic, 1, 0)
                          fs.lfCharSet = %ANSI_CHARSET
                          fs.lfoutprecision = %OUT_TT_ONLY_PRECIS
                          fs.lfClipPrecision = %CLIP_DEFAULT_PRECIS
                          fs.lfQuality = %PROOF_QUALITY
                          fs.lfPitchAndFamily = %DEFAULT_PITCH OR %FF_DONTCARE
                          fs.lforientation = 0
                          fs.lfFaceName = fontname
                          newfont = CreateFontIndirectA(fs)
                          IF newfont THEN
                            oldfont=SelectObject(bDC, newfont)
                            DIM cgm(%EndChar-%BegChar) AS LOCAL GLYPHMETRICSFLOAT
                            wglUseFontOutlinesW(bDC, %BegChar, %EndChar-%BegChar+1, listno, 0, 0, %WGL_FONT_POLYGONS, VARPTR(cgm(0)))
                      
                            SelectObject(bDC, oldfont)
                            DeleteObject(newfont)
                            maxy=1/cgm(ASC("A")-%BegChar).gmfBlackBoxY
                            FUNCTION=maxy
                          END IF
                          ReleaseDC(hWnd, bDC)
                      END FUNCTION
                      "Show me a young Conservative and I'll show you someone with no heart. Show me an old Liberal and I'll show you someone with no brains." ― Winston Churchill
                      "Socialism is the philosophy of failure, the creed of ignorance and the gospel of envy." ― Winston Churchill

                      Comment


                      • #12
                        In function oglCreateFontList, "wglUseFontOutlinesW" should be changed to wglUseFontOutlinesA. I couldn't edit it.
                        "Show me a young Conservative and I'll show you someone with no heart. Show me an old Liberal and I'll show you someone with no brains." ― Winston Churchill
                        "Socialism is the philosophy of failure, the creed of ignorance and the gospel of envy." ― Winston Churchill

                        Comment


                        • #13
                          Thank you Doug, AWESOME

                          After compiling with wglUseFontOutlinesW the centerline symbol can be displayed but
                          with wglUseFontOutlinesA the centerline symbol did not show up ?

                          I think I'll just use wglUseFontOutlinesW for all my programs as it does the work as I needed.

                          Comment


                          • #14
                            Originally posted by Tim Lakinir View Post
                            Thank you Doug, AWESOME

                            After compiling with wglUseFontOutlinesW the centerline symbol can be displayed but
                            with wglUseFontOutlinesA the centerline symbol did not show up ?

                            I think I'll just use wglUseFontOutlinesW for all my programs as it does the work as I needed.
                            It should only be changed within the "oglCreateFontList" function.
                            "Show me a young Conservative and I'll show you someone with no heart. Show me an old Liberal and I'll show you someone with no brains." ― Winston Churchill
                            "Socialism is the philosophy of failure, the creed of ignorance and the gospel of envy." ― Winston Churchill

                            Comment

                            Working...
                            X