Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Need to speed this up

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2008
    Location
    California
    Posts
    15

    Need to speed this up

    I'm rendering Text using Textures but its super slow any advice as to how to speed it up. Is there any other way to use Textures without the Quads or is there a way to speed up the Quads?


    // Change rendering conditions
    gr.glDisable(GR.GL_DEPTH_TEST);
    gr.glDisable(GR.GL_CULL_FACE);


    // Preserve current matrices, and switch to an orthographic view, and
    // do scaling and translation as necessary.

    gr.glMatrixMode(GR.GL_PROJECTION);
    gr.glPushMatrix();
    gr.glLoadIdentity();
    gr.glOrtho
    (
    (double)0,
    (double)(clientWidth - 1),
    (double)0,
    (double)(clientHeight - 1),
    -1.0,
    1.0
    );

    gr.glMatrixMode(GR.GL_MODELVIEW);
    gr.glLoadIdentity();



    if (null != texture)
    {
    // Enable texture
    texture.SetAsActiveTexture(gr);

    gr.glEnable(GR.GL_TEXTURE_2D);
    }

    // Enable blending
    gr.glEnable(GR.GL_BLEND);
    gr.glBlendFunc(GR.GL_SRC_ALPHA, GR.GL_ONE_MINUS_SRC_ALPHA);


    // Draw a quad

    gr.glBegin(GR.GL_QUADS);

    // TOP-LEFT
    gr.glTexCoord2f(0.0f, 1.0f);
    gr.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    gr.glVertex3f((float)(drawX), (float)((clientHeight - 1) - drawYTextMode), 0.0f);

    // BOTTOM-LEFT
    gr.glTexCoord2f(0.0f, 0.0f);
    gr.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    gr.glVertex3f((float)(drawX), (float)((clientHeight - 1) - (drawYTextMode + drawHeight)), 0.0f);

    // BOTTOM-RIGHT
    gr.glTexCoord2f(1.0f, 0.0f);
    gr.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    gr.glVertex3f((float)(drawX + (drawWidth)), (float)((clientHeight - 1) - (drawYTextMode + drawHeight)), 0.0f);

    // TOP-RIGHT
    gr.glTexCoord2f(1.0f, 1.0f);
    gr.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    gr.glVertex3f((float)(drawX + (drawWidth)), (float)((clientHeight - 1) - drawYTextMode), 0.0f);

    gr.glEnd();


    // Disable blending
    gr.glDisable(GR.GL_BLEND);


    if (null != texture)
    {
    // Disable texture
    gr.glDisable(GR.GL_TEXTURE_2D);

    gr.glBindTexture(GR.GL_TEXTURE_2D, 0);
    }


    // Restore original matrices.
    gr.glMatrixMode(GR.GL_MODELVIEW);
    gr.glPopMatrix();
    gr.glMatrixMode(GR.GL_PROJECTION);
    gr.glPopMatrix();


    // Restore rendering conditions

    gr.glEnable(GR.GL_DEPTH_TEST);
    gr.glEnable(GR.GL_CULL_FACE);

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Jan 2007
    Posts
    965

    Re: Need to speed this up

    Do you call all of that code just to draw each single character?

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2008
    Location
    California
    Posts
    15

    Re: Need to speed this up

    No it draws the entire text onto a bitmap.

  4. #4
    Junior Member Newbie
    Join Date
    Feb 2008
    Location
    California
    Posts
    15

    Re: Need to speed this up

    Here's the code that creates the bitmap where the entire string is drawn:

    mTextBitmap = new Bitmap(Convert.ToInt32(myTextScale.FontWidth * Text.Length), Convert.ToInt32(myTextScale.FontHeight));
    using (Graphics g = Graphics.FromImage(mTextBitmap))
    {
    g.Clear(Color.FromArgb(0,myStack.BackColor[0],myStack.BackColor[1],myStack.BackColor[2]));
    SolidBrush TextClr = new SolidBrush(Color.FromArgb(255, myStack.TextColor[0], myStack.TextColor[1], myStack.TextColor[2]));

    SizeF extent = new SizeF(0, 0);

    Font aFont = AtlasSupport.AppropriateFont(g, 0.0f, 50.0f, mTextBitmap.Size, Text, new Font(myStack.FontName, 50.0f), out extent);
    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
    g.DrawString(Text, aFont, TextClr, new PointF(0.0f, 0.0f));
    }

    mTextTexture.UpdateTextureWithBitmapData(gr, mTextBitmap);

  5. #5
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,728

    Re: Need to speed this up

    The way you do your text drawing is by having the GDI (or whatever) draw to a bitmap, then you read it and upload it to OpenGL, where you then draw it to the screen.

    First thing is that you should only be regenerating your texture if the text has changed.

    But most importantly second, you can't really expect that to be particularly fast. The general way this is handled is that you create a texture containing letters (once), and you draw each letter of the string of interest.

Posting Permissions

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