Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Write text on texture

  1. #1

    Write text on texture

    Hi to everybody, This is my first post on this forum!
    I'm fighting with Opengl, In a 2d application I need to write rotate text (90¬?).
    I read that the best way is to write normally on a texture then rotate the texture, but I don't know how to write a text on a transparent texture?
    Any Idea?

    regards
    Lorenzo


  2. #2

    Re: Write text on texture

    It doesn't matter if the text is on texture or rendered in other ways, key thing is that with OpenGL you have full control on where and which way your rendered things show up.

    1) Can you render text in normal way with what you have?

    2) You can use commands glTranslate() glRotatef() to place and rotate your text.
    If you want to rotate 90 so that rotation center point is in the middle of your text, then it goes about:
    [pascal]glPushMatrix; // May want to recall previous matrix afterwards
    glTranslate(textX, textY, 0);
    glRotatef(90, 0, 0, 1);
    glTranslate(-textWidth(text)/2, -fontHeight/2, 0);
    DrawText(text);
    glPopMatrix;[/pascal]

  3. #3

    Re: Write text on texture

    Thank's User137, I will try it soon as possible!
    I'm working on OPENGL for the first time and I'm a little bit confused!

  4. #4

    Re: Write text on texture

    I tested it but seems doesn't work, the 2d font text doesn't rotate!
    I'm working on D7 using old borland Opengl header, maybe this is the cause?!
    I tried to using DLGOPNEGL header but this cause a lot of errors on init functions that work fine in OPENGL header (I need to work in 2d way on a region(panel) of my application)!
    Can someone know a way to use dlgopengl for working in this way (2d on a region), I'm usually use this method and with opengl header work fine:


    Code:
      fillchar(pfd,SizeOf(pfd),0);
    	with pfd do begin
    		nSize := SizeOf(pfd);
    		nVersion := 1; {The current version of the desccriptor is 1}
    		dwFlags := PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER;
    		iPixelType := PFD_TYPE_RGBA;
    		cColorBits := 24; {support 24-bit color}
    		cDepthBits := 32; {depth of z-axis}
    		iLayerType := PFD_MAIN_PLANE;
    	end;
      FglDC := getDC(handle);//the main object is tcustompanel
      FormatIndex := ChoosePixelFormat(FglDC,@pfd);
    	SetPixelFormat(FglDC,FormatIndex,@pfd);
    	GLContext := wglCreateContext(FglDC);
    	wglMakeCurrent(FglDC,GLContext);
    	//glEnable(GL_LINE_SMOOTH); //Antialaising ON
    	glEnable(GL_BLEND);
    	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
      
    
      	glViewPort(0,0,ClientWidth,ClientHeight);
     	glMatrixMode(GL_PROJECTION);    // Change Matrix Mode to Projection
     	glLoadIdentity();
      gluOrtho2D(0.0,ClientWidth,ClientHeight,0.0);
     	glMatrixMode(GL_MODELVIEW);     // Return to the modelview matrix

  5. #5

    Re: Write text on texture

    Can you show the code which renders text to OpenGL?

  6. #6

    Re: Write text on texture

    I call the glPrint_Rot procedure that use the glPrint (that work fine for default text 0 deg).

    Code:
    procedure glPrint(x,y:integer;text: string;Abase_Font:GLuint);
    begin
     if text = '' then exit;
     glrasterpos2i(x, y);
     glPushAttrib(GL_LIST_BIT);
     glListBase(Abase_Font-(CHR_Code_Start));//se no i caratteri sono swiftati di uno???
     glCallLists(length(text), GL_UNSIGNED_BYTE, Pchar(text));
     glPopAttrib;
    
    end;
    
    procedure glPrint_Rot(x,y:integer;text: string;Abase_Font:GLuint;Rot:double);
    begin
      glPushMatrix;
      glTranslated(x, y, 0);
      glRotatef(Rot, 0, 0, 1);
      glPrint(x,y,text,Abase_Font);
      glPopMatrix;
    end;

  7. #7

    Re: Write text on texture

    I think you need to take out
    Code:
    glrasterpos2i(x, y);
    I don't specifically understand what it does (i suspect it nullifies the rotation), however you already move caret to right position with glTranslate so it is unnecessary to do it second time.

  8. #8

    Re: Write text on texture

    Sorry User137, I tried this solution but seems doesn't work!
    If you want I made an easier program to test the problem directly! If you want you can download it and verify by your self if there is something wrong, or if it is possible to find a solution.
    thanks for your support!

    http://www.abulafia.it/temp/OGL_simple.zip

  9. #9

    Re: Write text on texture

    I have looked in the code and come to conclusion that wglUseFontBitmaps() is the issue. It creates a bitmap, and these graphics don't seem to follow world matrix at all. Nehe example uses wglUseFontOutlines() instead to make vector displaylist. Tutorial was here:
    http://nehe.gamedev.net/data/lessons....asp?lesson=14

    It worked for what i tried:
    [pascal]procedure TForm2.BuildFont(name: Pansichar; size: integer);
    var
    Font: HFONT;
    gmf: array[0..255] of GLYPHMETRICSFLOAT;
    ...
    wglUseFontOutlines(FglDC, 32, 96, base, 0,
    0.2, WGL_FONT_POLYGONS, @gmf);

    procedure TForm2.glPrint_Rot(x,y:integer; text: string; Rot:double);
    begin
    if text = '' then exit;
    glPushMatrix;
    glTranslatef(x, y, 0);
    glRotatef(Rot, 0, 0, 1);
    glPushAttrib(GL_LIST_BIT);
    glListBase(base-32);
    glScale(20,20,20); // The font size
    glCallLists(length(text), GL_UNSIGNED_BYTE, Pchar(text));
    glPopAttrib;
    glPopMatrix;
    end;[/pascal]

  10. #10

    Re: Write text on texture

    Ok, I'll try this!
    Initially I assumed that bitmap fonts could not be rotated, which is why I wrote this post.
    Somewhere I read that the only way was to rotate the texture on which they were used!?
    The thing that I didn't know was that the outline-fonts could be used as 2d, mistakenly I thought that they worked only in 3d project!
    Thanks, I'll know you the results!



Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •