LB Booster
« Opengl text problem »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 03:27am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Opengl text problem  (Read 184 times)
RobM
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 91
xx Opengl text problem
« Thread started on: Aug 29th, 2017, 05:30am »

I have been able to get text to display in an Opengl window (not as easy as it may sound!) but for some reason the spaces between the words are missing. Any ideas?

Code:
    'http://nehe.gamedev.net/tutorial/bitmap_fonts/17002/
    nomainwin
    struct PFD,   Size as word, Version as word, Flags as long,_
        PixelType as char[1], ColorBits as char[1], RedBits as char[1],_
        RedShift as char[1], GreenBits as char[1], GreenShift as char[1],_
        BlueBits as char[1], BlueShift as char[1], AlphaBits as char[1],_
        AlphaShift as char[1],AccumBits as char[1], AccumRedBits as char[1],_
        AccumGreenBits as char[1], AccumBlueBits as char[1], AccumAlphaBits as char[1],_
        DepthBits as char[1], StencilBits as char[1], AuxBuffers as char[1],_
        LayerType as char[1], Reserved as char[1], LayerMask as long,_
        VisibleMask as long, DamageMask as long
    PFD.Version.struct=1:PFD.ColorBits.struct=24
    PFD.DepthBits.struct=16:PFD.Size.struct=len(PFD.struct)
    PFD.Flags.struct=37:GlColorBufferBit=16384
    open "opengl32.dll" for dll as #gl
    open "glu32.dll" for dll as #glu
    open "oleaut32.dll" for dll as #oleaut32
    WindowWidth=500:WindowHeight=500
    UpperLeftX=1:UpperLeftY=1
    open "Triangle" for window_nf as #main
    print #main,"trapclose [quit]"
    MainH=hwnd(#main)
    calldll #user32,"GetDC", MainH as ulong, MainDC as ulong
    calldll #gdi32,"ChoosePixelFormat", MainDC as ulong, PFD as struct, ret as long
    calldll #gdi32, "SetPixelFormat", MainDC as ulong, ret as long, PFD as struct, t as long
    calldll #gl,"wglCreateContext", MainDC as ulong, GLContext as ulong
    calldll #gl,"wglMakeCurrent", MainDC as ulong, GLContext as ulong, ret as long
    calldll #gl,"glClear", GlColorBufferBit as long,  ret as long
    'calldll #gl,"glRotated", 0 as double, 0 as double, 0 as double, 0 as double, ret as long
    calldll #gl,"glBegin", 4 as long, ret as long
    calldll #gl,"glColor3d", 0 as double, 0 as double, 255 as double, ret as long
    calldll #gl,"glVertex3i", -1 as long, -1 as long, 0 as long, ret as long
    calldll #gl,"glColor3d", 255 as double, 0 as double, 0 as double, ret as long
    calldll #gl,"glVertex3i", 0 as long, 1 as long, 0 as long, ret as long
    calldll #gl,"glColor3d", 0 as double, 255 as double, 0 as double, ret as long
    calldll #gl,"glVertex3i", 1 as long, -1 as long, 0 as long, ret as long
    calldll #gl,"glEnd", ret as void
    base=glGenLists(96)
    fontH=CreateFont(-22,"Times New Roman")
    calldll #gdi32,"SelectObject",_
        MainDC as ulong,_ 'handle of dc
        fontH as ulong,_ 'handle of brush
        oldfont as ulong
    calldll #gl,"wglUseFontBitmapsA",_
        MainDC as ulong,_
        32 as ulong,_
        96 as ulong,_
        base as ulong,_
        ret as long
    calldll #gdi32,"DeleteObject",fontH as ulong,r as ulong
    calldll #gl,"glColor3d", 0 as double, 0 as double, 0 as double, ret as long
    x=R4(-.35)
    y=R4(-.25)
    calldll #gl,"glRasterPos2f",_
       x as ulong,_
       y as ulong,_
       ret as long
    GL.LIST.BIT = 131072
    calldll #gl,"glPushAttrib",_
      GL.LIST.BIT as long,_
      ret as long
     gllistbase=base - 32
     calldll #gl,"glListBase",_
       gllistbase as long,_
       ret as long
    text$="My spaces are missing :("
    length=len(text$)
    GL.UNSIGNED.BYTE = 5121
    calldll #gl,"glCallLists",_
       length as long,_
       GL.UNSIGNED.BYTE as long,_
       text$ as ptr,_
       ret as long
    calldll #gl,"glPopAttrib", ret as long
    calldll #gdi32,"SwapBuffers", MainDC as ulong, ret as long
    wait
[quit]
    calldll #gl,"wglMakeCurrent", 0 as ulong, 0 as ulong, ret as long
    calldll #gl,"wglDeleteContext", GLContext as ulong, ret as long
    calldll #user32, "ReleaseDC", MainH as ulong, MainDC as ulong,ret as long
    close #main
    close #glu
    close #gl
    close #oleaut32
    end
function glGenLists(num)
    CALLDLL #gl , "glGenLists" ,_
      num AS long ,_
      glGenLists AS void
END function
function CreateFont(fontheight,facename$)
    calldll #gdi32, "CreateFontA",_
      fontheight as long, fontwidth as long,_
      escapement as long, orientation as long,_
      _FW_NORMAL as long, italic as long,_
      underline as long, strikeout as long,_
      CharSet as long, OutputPrecision as long,_
      ClipPrecision as long, Quality as long,_
      PitchAndFamily as long,facename$ as PTR,_
      CreateFont as ulong 'returns handle to font
end function
FUNCTION R4( R8 )
    STRUCT local1 ,_
      R4 AS ULong
    CALLDLL #oleaut32 , "VarR4FromR8" ,_
      R8 AS Double ,_
      local1 AS STRUCT ,_
      ret AS Long
    R4 = local1.R4.struct
END FUNCTION
 


User Image
« Last Edit: Aug 29th, 2017, 05:37am by RobM » User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Opengl text problem
« Reply #1 on: Aug 29th, 2017, 08:38am »

on Aug 29th, 2017, 05:30am, RobM wrote:
Any ideas?

Try this (based on the example at MSDN):

Code:
   nomainwin
    struct PFD,   Size as word, Version as word, Flags as long,_
        PixelType as char[1], ColorBits as char[1], RedBits as char[1],_
        RedShift as char[1], GreenBits as char[1], GreenShift as char[1],_
        BlueBits as char[1], BlueShift as char[1], AlphaBits as char[1],_
        AlphaShift as char[1],AccumBits as char[1], AccumRedBits as char[1],_
        AccumGreenBits as char[1], AccumBlueBits as char[1], AccumAlphaBits as char[1],_
        DepthBits as char[1], StencilBits as char[1], AuxBuffers as char[1],_
        LayerType as char[1], Reserved as char[1], LayerMask as long,_
        VisibleMask as long, DamageMask as long
    PFD.Version.struct=1:PFD.ColorBits.struct=24
    PFD.DepthBits.struct=16:PFD.Size.struct=len(PFD.struct)
    PFD.Flags.struct=37:GlColorBufferBit=16384
    open "opengl32.dll" for dll as #gl
    open "glu32.dll" for dll as #glu
    open "oleaut32.dll" for dll as #oleaut32
    WindowWidth=500:WindowHeight=500
    UpperLeftX=1:UpperLeftY=1
    open "Triangle" for window_nf as #main
    print #main,"trapclose [quit]"
    MainH=hwnd(#main)
    calldll #user32,"GetDC", MainH as ulong, MainDC as ulong
    calldll #gdi32,"ChoosePixelFormat", MainDC as ulong, PFD as struct, ret as long
    calldll #gdi32, "SetPixelFormat", MainDC as ulong, ret as long, PFD as struct, t as long
    calldll #gl,"wglCreateContext", MainDC as ulong, GLContext as ulong
    calldll #gl,"wglMakeCurrent", MainDC as ulong, GLContext as ulong, ret as long
    calldll #gl,"glClear", GlColorBufferBit as long,  ret as long
    'calldll #gl,"glRotated", 0 as double, 0 as double, 0 as double, 0 as double, ret as long
    calldll #gl,"glBegin", 4 as long, ret as long
    calldll #gl,"glColor3d", 0 as double, 0 as double, 255 as double, ret as long
    calldll #gl,"glVertex3i", -1 as long, -1 as long, 0 as long, ret as long
    calldll #gl,"glColor3d", 255 as double, 0 as double, 0 as double, ret as long
    calldll #gl,"glVertex3i", 0 as long, 1 as long, 0 as long, ret as long
    calldll #gl,"glColor3d", 0 as double, 255 as double, 0 as double, ret as long
    calldll #gl,"glVertex3i", 1 as long, -1 as long, 0 as long, ret as long
    calldll #gl,"glEnd", ret as void
    base=glGenLists(255)
    fontH=CreateFont(-22,"Times New Roman")
    calldll #gdi32,"SelectObject",_
        MainDC as ulong,_ 'handle of dc
        fontH as ulong,_ 'handle of brush
        oldfont as ulong
    calldll #gl,"wglUseFontBitmapsA",_
        MainDC as ulong,_
        0 as ulong,_
        255 as ulong,_
        base as ulong,_
        ret as long
    calldll #gdi32,"DeleteObject",fontH as ulong,r as ulong
    calldll #gl,"glColor3d", 0 as double, 0 as double, 0 as double, ret as long
    x=R4(-.50)
    y=R4(-.25)
    calldll #gl,"glRasterPos2f",_
       x as ulong,_
       y as ulong,_
       ret as long
    GL.LIST.BIT = 131072
    calldll #gl,"glPushAttrib",_
      GL.LIST.BIT as long,_
      ret as long
     calldll #gl,"glListBase",_
       base as long,_
       ret as long
    text$="My spaces are not missing :)"
    length=len(text$)
    GL.UNSIGNED.BYTE = 5121
    calldll #gl,"glCallLists",_
       length as long,_
       GL.UNSIGNED.BYTE as long,_
       text$ as ptr,_
       ret as long
    calldll #gl,"glPopAttrib", ret as long
    calldll #gdi32,"SwapBuffers", MainDC as ulong, ret as long
    wait
[quit]
    calldll #gl,"wglMakeCurrent", 0 as ulong, 0 as ulong, ret as long
    calldll #gl,"wglDeleteContext", GLContext as ulong, ret as long
    calldll #user32, "ReleaseDC", MainH as ulong, MainDC as ulong,ret as long
    close #main
    close #glu
    close #gl
    close #oleaut32
    end
function glGenLists(num)
    CALLDLL #gl , "glGenLists" ,_
      num AS long ,_
      glGenLists AS void
END function
function CreateFont(fontheight,facename$)
    calldll #gdi32, "CreateFontA",_
      fontheight as long, fontwidth as long,_
      escapement as long, orientation as long,_
      _FW_NORMAL as long, italic as long,_
      underline as long, strikeout as long,_
      CharSet as long, OutputPrecision as long,_
      ClipPrecision as long, Quality as long,_
      PitchAndFamily as long,facename$ as PTR,_
      CreateFont as ulong 'returns handle to font
end function
FUNCTION R4( R8 )
    STRUCT local1 ,_
      R4 AS ULong
    CALLDLL #oleaut32 , "VarR4FromR8" ,_
      R8 AS Double ,_
      local1 AS STRUCT ,_
      ret AS Long
    R4 = local1.R4.struct
END FUNCTION 


Richard.
User IP Logged

RobM
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 91
xx Re: Opengl text problem
« Reply #2 on: Aug 29th, 2017, 3:42pm »

Thanks Richard!

I am guessing the Nehe sample wouldn't run properly if it were compiled. Looks like it doesn't load enough characters.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls