Interactive PowerBasic Forum

IT-Consultant: Charles Pegge => OxygenBasic Examples => Topic started by: Frank Brübach on July 11, 2024, 10:16:19 PM

Title: OpenGL question gprint
Post by: Frank Brübach on July 11, 2024, 10:16:19 PM
Hello Charles..

I have some Problems to Display for this Kind of OpenGL a simple gprint for Text Message in this Scene. I dont want anything with getwordarea putboxarea.. I need it pure  Like in the beginning and simple..

Thanks


  ' how to set a simple text with gprint to this opgl scene ?
  '
  'includepath "$\inc\"
  $ FileName "t.exe"
  'include   "RTL32.inc"
  'include   "RTL64.inc"
  $ title    "Rotating Triangle"
  int width=640
  int height=480

  uses OpenglSceneFrame


  sub Initialize(sys hWnd)
  '=======================
  end sub
  '
  sub Scene(sys hWnd)
  '==================
  '
  static single ang1,angi1=1
  '
  glClearColor 0.3, 0.3, 0.5, 0
  glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
  '
  glLoadIdentity
  '
  '
  gltranslatef    0.0, 0.0, -4.0
  glrotatef ang1, 0.0, 0.0,  1.0
  '
  glBegin GL_TRIANGLES
  glColor3f   1.0, 0.0, 0.0 : glVertex3f   0.0,  1.0, 0.0
  glColor3f   0.0, 1.0, 0.0 : glVertex3f  -1.0, -1.0, 0.0
  glColor3f   0.0, 0.0, 1.0 : glVertex3f   1.0, -1.0, 0.0
  glEnd
  '
  'UPDATE ROTATION ANGLES
  '----------------------
  '
  glPushMatrix
  '
  glLoadIdentity
  static int framecount
  sys x,y
  framecount++
  gltranslatef -.5,.25,-4.0
  ''getwordarea "batman",x,y ---> dont want to use it here ;)
  glColor3f    .99,.50,.50
  glscalef     .06,.06,.01
  gprint       str(framecount)
  glpopmatrix

  glpushMatrix
  glClearColor 0.8, 0.3, 0.5, 0
  glRotatef 90.0,0,0,1
  gprint "Hello triangle"
  glPopMatrix

  ang1+=angi1
  if ang1>360 then ang1-=360
  '
  end sub


  sub Release(sys hwnd)
  '====================
  end sub

Title: Re: OpenGL question gprint
Post by: Charles Pegge on July 12, 2024, 03:00:17 AM
Hi Frank,

I have marked my changes '***

  ' how to set a simple text with gprint to this opgl scene ?
  '
  'includepath "$\inc\"
  $ FileName "t.exe"
  'include   "RTL32.inc"
  'include   "RTL64.inc"
  $ title    "Rotating Triangle"
  $ fontA =  "Arial",FW_SEMIBOLD '***  set font
  int width=640
  int height=480

  uses OpenglSceneFrame


  sub Initialize(sys hWnd)
  '=======================
  end sub
  '
  sub Scene(sys hWnd)
  '==================
  '
  static single ang1,angi1=1
  '
  glClearColor 0.3, 0.3, 0.5, 0
  glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
  '
  glLoadIdentity
  '
  '
  gltranslatef    0.0, 0.0, -4.0
  glrotatef ang1, 0.0, 0.0,  1.0
  '
  glBegin GL_TRIANGLES
  glColor3f   1.0, 0.0, 0.0 : glVertex3f   0.0,  1.0, 0.0
  glColor3f   0.0, 1.0, 0.0 : glVertex3f  -1.0, -1.0, 0.0
  glColor3f   0.0, 0.0, 1.0 : glVertex3f   1.0, -1.0, 0.0
  glEnd
  '
  'UPDATE ROTATION ANGLES
  '----------------------
  '
  glPushMatrix
  '
  glLoadIdentity
  static int framecount
  sys x,y
  framecount++
  gltranslatef -.5,.25,-4.0
  ''getwordarea "batman",x,y ---> dont want to use it here ;)
  glColor3f    .99,.50,.50
  glscalef     .2,.2,.01 '*** larger scale fron ,06
  gprint       str(framecount)
  '
  glpopmatrix

  glpushMatrix
  'glClearColor 0.8, 0.3, 0.5, 0 '*** remove
  glscalef     .2,.2,.01 '*** respecify scale
  glRotatef 90.0,0,0,1
  gprint "Hello triangle"
  glPopMatrix

  ang1+=angi1
  if ang1>360 then ang1-=360
  '
  end sub


  sub Release(sys hwnd)
  '====================
  end sub
Title: Re: OpenGL question gprint
Post by: Frank Brübach on July 12, 2024, 09:22:57 AM
Many thanks Charles :) my example Works Well here.. Looks simple but IT isnt.. and I have explored also include files whats the meaning of build Font Function..

I dont understand a Powerbasic NeHe 13 example and tried to rotate a Font but without success..

Here's my Code snippets.. perhaps you have an Idea how I can rotate this Font Text would be great thanks, Frank

....
METHOD SetupScene

      ' Select smooth shading
      glShadeModel %GL_SMOOTH
      ' Specify clear values for the color buffers
      glClearColor 0.0!, 0.0!, 0.0!, 0.0!
      ' Specify the clear value for the depth buffer
      glClearDepth 1.0!
      ' Enable depth comparisons and update the depth buffer
      glEnable %GL_DEPTH_TEST
      ' Specify the value used for depth-buffer comparisons
      glDepthFunc %GL_LEQUAL
      ' Really nice perspective calculations
      glHint %GL_PERSPECTIVE_CORRECTION_HINT, %GL_NICEST

      ' Storage for 96 characters
      m_FontBase = glGenLists(96)
      ' Build the font
      m_hFont = CreateFont(-24, _                             ' Height of the font
                           0, _                              ' Width of the font
                           0, _                              ' Angle of escapement
                           0, _                              ' Orientation angle
                           %FW_BOLD, _                       ' Font weight
                           0, _                              ' Italic
                           0, _                              ' Underline
                           0, _                              ' Strikeout
                           %ANSI_CHARSET, _                  ' Character set identifier
                           %OUT_TT_PRECIS, _                 ' Output precision
                           %CLIP_DEFAULT_PRECIS, _           ' Clipping precision
                           %ANTIALIASED_QUALITY, _           ' Output quality
                           %FF_DONTCARE OR %DEFAULT_PITCH, _ ' Family and pitch
                           "Courier New")                    ' Font name

      ' Select our font
      m_hOldFont = SelectObject(m_hdc, m_hFont)
      ' Builds 96 characters starting at character 32
      wglUseFontBitmaps m_hdc, 32, 96, m_FontBase
      ' Select previous font
      SelectObject m_hdc, m_hOldFont
      ' Delete the font
      DeleteObject m_hFont

   END METHOD
   ' =====================================================================================

' ...

   ' =======================================================================================
   ' Render the scene
   ' =======================================================================================
METHOD RenderScene

      ' Clear the screen buffer
      glClear %GL_COLOR_BUFFER_BIT OR %GL_DEPTH_BUFFER_BIT
      ' Reset the view
      glLoadIdentity

      ' Move one unit into the screen
      glTranslatef 0.0!, 0.0!, -1.0!
      ' Pulsing colors based on text position
      glColor3f 1.0! * COS(m_cnt1), 1.0! * SIN(m_cnt2), 1.0! - 0.5! * COS(m_cnt1 + m_cnt2)

      '----------------------------------- problem zone for rotate font text to 90.0 degrees
      '
      ' glrotatef 90.0,0.0,0.0,1.0 '' thats my problem that doesnt run with only this code line
      '
      ' Position the text on the screen
      glRasterPos2f -0.45! + 0.05! * COS(m_cnt1), 0.32! * SIN(m_cnt2)
      ' Print GL text to the screen
      m_szText = "Active OpenGL Text With NeHe - " & FORMAT$(m_cnt1, "#.00")
      '----------------------------------- problem zone for rotate font text to 90.0 degrees

      ' Pushes the display list bits
      glPushAttrib %GL_LIST_BIT
      ' Sets the base character to 0
      glListBase m_FontBase - 32
      ' Draws the display list text
      glCallLists LEN(m_szText), %GL_UNSIGNED_BYTE, m_szText
      ' Pops the display list bits
      glPopAttrib
      ' Increase counters
      m_cnt1 = m_cnt1 + 0.051!
      m_cnt2 = m_cnt2 + 0.005!

      ' // Exchange the front and back buffers
      SwapBuffers m_hdc

   END METHOD
      ' =======================================================================================
   
Title: Re: OpenGL question gprint
Post by: Frank Brübach on July 12, 2024, 10:11:05 AM
PS: thats what I have explored about buildFont etcpp..

' oxygen
#ifndef opengles
    #ifdef fontA
      BuildFont hWnd, hDC, hRC, 1024,"Arial",FW_NORMAL,0
    #endif
    #ifdef fontB
      BuildFont hWnd, hDC, hRC ,1280, "Courier New",600,1
      'BuildFont hWnd, hDC, hRC ,1280, fontB
    #endif
  #endif
   #ifndef opengles
    uses Glo2\OpenglSceneUtil
  #endif

sub BuildFont (sys hWnd,hDC,hRC, int base=1024, string name="Arial", int weight=FW_NORMAL, charset=DEFAULT_CHARSET)
  ===================================================================================================================
  indexbase 0
  LOGFONT   glFont
  sys       glFontHandle
  '
  glFont.lfHeight         = 1                             'Height Of Font
  glFont.lfWeight         = weight                        'Font Weight FW_BOLD etc
  glFont.lfCharSet        = charset                       'Character Set Identifier
  glFont.lfOutPrecision   = OUT_TT_PRECIS                 'Output Precision
  glFont.lfClipPrecision  = CLIP_DEFAULT_PRECIS           'Clipping Precision
  glFont.lfQuality        = ANTIALIASED_QUALITY           'Output Quality
  glFont.lfPitchAndFamily = FF_DONTCARE or DEFAULT_PITCH  'Family And Pitch
  glFont.lfFaceName       = name    ' "Arial" "Lucida Console" "Consolas" ' "Courier New"    'Font Name
  '
  glFontHandle = CreateFontIndirect(@glFont)
  glFontHandle = SelectObject(hDC, glFontHandle)
  wglUseFontOutlinesA (hDC, 0, 256, base, 0.0, .25, WGL_FONT_POLYGONS, @gmf[base-1024])
  DeleteObject(glFontHandle)
  end sub

' powerbasic
DECLARE FUNCTION CreateFontIndirectA IMPORT "GDI32.DLL" ALIAS "CreateFontIndirectA" ( _
   BYREF lplf AS LOGFONTA _                             ' __in CONST LOGFONTA *lplf
 ) AS DWORD                                             ' HFONT

DECLARE FUNCTION CreateFontIndirectW IMPORT "GDI32.DLL" ALIAS "CreateFontIndirectW" ( _
   BYREF lplf AS LOGFONTW _                             ' __in CONST LOGFONTW *lplf
 ) AS DWORD                                             ' HFONT


#IF %DEF(%USEPBDECL)
DECLARE FUNCTION wglUseFontOutlinesA LIB "OPENGL32.DLL" _
    ALIAS "wglUseFontOutlinesA" (BYVAL hdc AS DWORD, BYVAL dFirst AS DWORD, _
    BYVAL dCount AS DWORD, BYVAL dListBase AS DWORD, _
    BYVAL deviation AS SINGLE, BYVAL extrusion AS SINGLE, _
    BYVAL iFormat AS LONG, BYVAL lpgmf AS DWORD) AS LONG
#ELSE
DECLARE FUNCTION wglUseFontOutlinesA IMPORT "OPENGL32.DLL" ALIAS "wglUseFontOutlinesA" ( _
   BYVAL hdc AS DWORD _                                 ' __in HDC hdc
 , BYVAL dFirst AS DWORD _                              ' __in DWORD dFirst
 , BYVAL dCount AS DWORD _                              ' __in DWORD dCount
 , BYVAL dListBase AS DWORD _                           ' __in DWORD dListBase
 , BYVAL deviation AS SINGLE _                          ' __in FLOAT deviation
 , BYVAL extrusion AS SINGLE  _                         ' __in FLOAT extrusion
 , BYVAL iFormat AS LONG _                              ' __in int iFormat
 , BYREF lpgmf AS GLYPHMETRICSFLOAT _                   ' __out LPGLYPHMETRICSFLOAT lpgmf
 ) AS LONG                                              ' BOOL
#ENDIF

' -- > glFontHandle = CreateFontIndirect(@glFont)
' -- > createFontIndirect (wingdi.h)

Title: Re: OpenGL question gprint
Post by: Frank Brübach on July 13, 2024, 12:08:59 AM
Hello Charles.. only a Message that I Have built an Powerbasic example with rotating Font with 90 degrees and that was some piece of Work to find the solution ;) I did and found solution in a gprint function of an NeHe 17 example..

Thx nevertheless.. its Always interesting to Adept Code example or looking for similar Setups in OpenGL or other winapi examples.. I wanted to solve the solution and I did it..

Regards, Frank
Title: Re: OpenGL question gprint
Post by: Charles Pegge on July 13, 2024, 11:46:02 AM
Well done Frank. As you can see, setting up Opengl is not easy. It took me years to develop the OpenglScene framework for Oxygen. But I have just spotted a problem with the FontA and FontB macros. Currently they have a fixed definition which overrides the user definition. So I will try to resolve this for the next release.
Title: Re: OpenGL question gprint
Post by: Bernard Kunzy on July 17, 2024, 09:08:57 PM
I think that GDImage does that very well, including 0-360 full range rotation.
https://forum.powerbasic.com/forum/user-to-user-discussions/third-party-addons/832675-circular-text


With OpenGL the solution is obvious, create a bitmap and use it for texture on a quadratic surface.

Indeed you can use the same concept that is used there (http://www.objreader.com/index.php?topic=408.0) for text rotation.
Title: Re: OpenGL question gprint
Post by: Charles Pegge on July 19, 2024, 12:54:49 PM
A brief demo of circular text using consoleG with the predefined Arial Font. Each character is a vertex list for a solid shape, which can be scaled, rotated etc.


'CIRCULAR TEXT DEMO
uses consoleg
procedure main()
move 20,-15
string s="WELCOME CODERS"
int i,j
cls .2,.1,.5
scale 1.5
color .9,.8,.0
for i=1 to len(s)
  pushstate
    rotateZ -24*j
    move 4
    scale 2
    rotateZ -90-12 'clockwise
    gprint mid(s,i,1)
  popstate
  j++
next
end procedure
endscript