Autore Topic: Rendering del testo in una GLArea  (Letto 439 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.723
  • Ne mors quidem nos iunget
    • Mostra profilo
Rendering del testo in una GLArea
« il: 10 Gennaio 2014, 23:40:50 »
Riporto questa discussione apparsa nella M.L. ufficiale:


" Hi, does anyone has an example on rendering some text in a glArea with (or without) openGL?

tnx!
Saludos
Martin
"


" Look at the PdfPresentation example, it uses a GLArea. And I don't know
 what you mean by *not* using OpenGL to draw in a GLArea.
 --
 Benoit Minisini
"


" funny, it's the only OpenGL example I can't run: program freezes while showing the Openfile dialog. Tried this workaround:
Codice: gambas [Seleziona]
Dialog.Title = ("Select a PDF file")
Dialog.Filter = ["*.pdf", ("PDF files")]
  'If Dialog.OpenFile() Then Return   ' FREEZES HERE
  'workaround (its a valid path)
sPath = User.home &/ "CIRSOC tablas de perfiles.pdf" 'Dialog.Path
txtPath.Text = sPath


but only shows a rotating cube with the gambas logo.

I meant using another control inside (or on top) the GLArea, like a label or something. But it doesn't work, it only shows the contents of the GLArea.

Martin



" > funny, it's the only OpenGL example I can't run: program freezes while showing the Openfile dialog.

Indeed, with gb.gtk. But it works with gb.qt4...

> but only shows a rotating cube with the gambas logo.

You must press the SPACE key then.

--
Benoît Minisini
"
« Ultima modifica: 20 Gennaio 2014, 16:07:05 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.723
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Rendering del testo in una GLArea
« Risposta #1 il: 11 Gennaio 2014, 15:57:30 »
...continua...

" Got it working after moving code from glaPresentation_KeyPress to Form_KeyPress, but it's not the
kind of text rendering I need because the GLArea will be a mixed between a structure (a building) some text data.

Just thougt about a little hidden Picturebox to print the text with usual methods and then past the image from memory into the GLArea when rendering. Do you think that would work?

Martin
"


" Yes (using OpenGL), but it's rather involved. I had an epic failure of
hardware and human logic this week and am just wrapping up restoring
sanity to my server and workstation, but give me a day or so and I'll
give you the source code.

It's my understanding that OpenGL has no native support of rendering
text, that it must be done manually. I can also provide you with a
couple of "fonts" that I created from ttf.

Basically you take a ttf, type out all the characters you want in GIMP
(I recommend keeping them in line with an ASCII table), then save each
character into a separate png file with alpha. You then load these into
OpenGL textures and render them as quads. The horrible bit (as if it
weren't horrible enough) is getting the spacing right for different
combinations of characters. You'll want to add drop shadows, beveling,
etc. in GIMP as I don't know of a way to do this in OpenGL other than
perhaps by using shaders (zero knowledge there).

Using Gambas's native software text rendering libraries is slower but easier.

Kevin
"


" Why slower? You can use Gambas to create the font characters texture,
and maintain a texture cache to not do that each time a character is drawn.

--
Benoît Minisini
"


" That's a good point. It's actually exactly what I do with the the
landscape tiles for my game using the DrawAlpha function. Composite each
tile using Gambas software operations, then offload it to an array of
OpenGL textures for on-screen rendering. I never thought the same could
be done with text.

In any case, let me know Martin if you're interested in my text
rendering code and bitmaps. I finally got everything up and running here.
kevin
"
« Ultima modifica: 20 Gennaio 2014, 16:07:19 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.723
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Rendering del testo in un GLarea
« Risposta #2 il: 13 Gennaio 2014, 15:33:34 »
...continua...


" Of course I am!
And I need no speed as my goal is a static view of a structure. I managed to get this code worrking but results are odd, because I cant make the text match the size of everithing else:

Codice: gambas [Seleziona]

Public Sub txtRendering2D(texto As String, p As Punto3d, Optional Altura As Single = 12, Optional _color As Long = Color.Blue, _BackColor As Long = -1)
 
  Dim rectangulo As RectF
  Dim imagen As New Image, pR As New Punto3d

  imagen.Resize(200, 200) 'so Paint.Begin gives no error
  Paint.Begin(imagen)
    Paint.Font.Size = Altura
    Paint.Brush = Paint.Color(_color)
    rectangulo = Paint.TextSize(texto)
  Paint.End
 
  'this can't go into the Paint loop
  imagen.resize(rectangulo.w, rectangulo.h)
  imagen.Transparent(Color.Black)
  If _backcolor > 0 Then imagen.Fill(_BackColor)
 
 
  Paint.Begin(imagen)
    Paint.Font.Size = Altura
    Paint.Brush = Paint.Color(_color)
   
   
    Paint.Text(texto, 0, rectangulo.h)
    Paint.Fill
  Paint.End
  'imagen.Save("imagen.png")  ' this is to check the Paint worked (and works!)

 
  rotar3d(p, pr)  ' custom rotation
  gl.Enable(gl.TEXTURE_2D)                     
  Gl.TexImage2D(imagen)
  Glu.Build2DMipmaps(imagen)
  Gl.TexParameteri(Gl.TEXTURE_2D, Gl.TEXTURE_MIN_FILTER, Gl.LINEAR_MIPMAP_NEAREST)
  Gl.TexParameteri(Gl.TEXTURE_2D, Gl.TEXTURE_MAG_FILTER, Gl.LINEAR)
  gl.Enable(gl.TEXTURE_2D)                 

   

  gl.BindTexture(gl.TEXTURE_2D, hText[0])       
  Gl.Begin(Gl.QUADS)
  gl.color3f(1, 1, 1)
  ' Bottom Left OF The Texture AND Quad
  Gl.TexCoordf(0.0, 1.0)
  Gl.Vertex3f(pr.x, pr.y, pr.z)
  ' Bottom Right OF The Texture AND Quad
  Gl.TexCoordf(1.0, 1.0)
  Gl.Vertex3f(pr.x + rectangulo.w, pr.y, pr.z)
  ' Top Right OF The Texture AND Quad
  Gl.TexCoordf(1.0, 0.0)
  Gl.Vertex3f(pr.x + rectangulo.w, pr.y + rectangulo.h, pr.z)
  ' Top Left OF The Texture AND Quad
  Gl.TexCoordf(0.0, 0.0)
  Gl.Vertex3f(pr.x, pr.y + rectangulo.h, pr.z)


  Gl.End()


martin "
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »