Author Topic: Demo of Text in Opengl point by point  (Read 1804 times)

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
Demo of Text in Opengl point by point
« on: September 26, 2021, 04:12:58 pm »
Hi
here a adjourned version of Text point by point in Opengl
now with no handy conversions of colors and dimensions from standard SCREEN and Opengl Screen.

Code: QB64: [Select]
  1. 'OpenGL text without mapping or font
  2.  
  3. Const True = -1, False = 0
  4. Const Black = _RGB32(0, 0, 0, 255), White = _RGB32(255)
  5. Const Red = _RGB32(230, 0, 0, 255), Green = _RGB32(0, 230, 0, 255)
  6. Const Blu = _RGB32(0, 0, 230, 255)
  7.  
  8. Dim Shared sXp As Integer, glXp As Single, sYp As Integer, glYp As Single
  9. Dim Shared glInit As Integer, sRc As Integer, sGc As Integer, sBc As Integer, sAc As Integer
  10.  
  11.  
  12. T = _NewImage(600, 400, 32)
  13. S = _NewImage(600, 400, 32)
  14. _Title "Demo2 of Text in OpenGL:point by point"
  15.  
  16. glRun = False
  17. sBkc = White
  18. sFgc = Green
  19. PrepareTxt "Hello"
  20.  
  21. ShowSourceTxt
  22. Print "Now a text in OpenGL"
  23. glInit = True
  24. glRun = True
  25.     _Limit 10
  26.  
  27. Sub PrepareTxt (txt As String)
  28.     _Dest T
  29.     Cls , Red
  30.     Color sFgc, sBkc
  31.     Locate 1, 1: Print txt
  32.     _Dest 0
  33.  
  34. Sub ShowSourceTxt
  35.     Screen T
  36.     _Delay 3
  37.     Screen S
  38.  
  39.  
  40.  
  41. Sub copyTxt (Xs As Integer, Ys As Integer, glFgc As _Unsigned Long, Size As Integer)
  42.     Dim WidhTxt As Integer, HeighTxt As Integer
  43.     WidhTxt = 40
  44.     HeighTxt = 12
  45.     _Source T
  46.     _Dest S
  47.  
  48.     For sXp = 0 To WidhTxt Step 1
  49.         For sYp = 1 To HeighTxt Step 1
  50.             If Point(sXp, sYp) = sFgc Then
  51.                 PaintPoint Xs + (sXp * Size), Ys + (sYp * Size), glFgc, Size
  52.             End If
  53.         Next sYp
  54.     Next sXp
  55.  
  56.  
  57. ' OpenGl-----------------------------
  58. Sub _GL ()
  59.     If glRun = False Then Exit Sub
  60.     If glInit Then InitGL
  61.     _glClear _GL_COLOR_BUFFER_BIT
  62.  
  63.     ' every time _GL runs it must set values for screen
  64.     _glMatrixMode _GL_MODELVIEW
  65.     _glTranslatef -1, 1, 0
  66.     _glScalef (1 / (_Width / 2)), (-1 / (_Height / 2)), 1
  67.  
  68.  
  69.  
  70.     copyTxt 1, 1, Green, 1
  71.     copyTxt 100, 200, Red, 2
  72.     copyTxt 200, 100, Black, 4
  73.  
  74. Sub InitGL
  75.     glInit = False
  76.     _glClearColor 0, 0, 0.8, 1
  77.     _glDisable _GL_MULTISAMPLE ' disable antialiasing method that hides one pixel
  78.     ' in Opengl Anti aliasing method is ON for default
  79.     _glFlush
  80.  
  81.  
  82. Sub PaintPoint (X As Single, Y As Single, glFgc As _Unsigned Long, Sizing As Integer)
  83.     Dim gXp As Single, gYp As Single, gRc As Single, gGc As Single, gBc As Single, gAc As Single
  84.     _glColor4ub _Red32(glFgc), _Green32(glFgc), _Blue32(glFgc), _Alpha32(glFgc) 'f gRc, gGc, gBc, gAc
  85.     _glPointSize Sizing
  86.     _glBegin _GL_POINTS
  87.     _glVertex2f X, Y
  88.     _glEnd
  89.  
  90.  

while here a clear example to make text in 3D using a matrix by SMcNeill
https://www.qb64.org/forum/index.php?topic=3254.msg125353#msg125353
Good watching
Programming isn't difficult, only it's  consuming time and coffee