Draw Text in OpenGL ES

Hi all,
I tried to use the Texture2D class included in the CrashLanding Example but i saw that I can't set the color of the text (it draws only white text).
How can i set the color of the text or exists another method to draw text with OpenGL ES?
Thanks

There several ways to draw text but not an easy one so far I know. One idea is to have every letter as texture (with alphachannel) and draw an rectangle with a such a texture for each letter. Usually you set the gl drawcolor to white but you can change it to other, so you can color your text.

Similar Messages

  • How to draw text vertically, or in an angle

    please help me how to draw text vertically, or in an angle

    I robbed the framework from Dr Las or 74phillip (don't remember which) ...
    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class AngleText extends JPanel {
      private int      degrees = 16;
      private JSpinner degreesSpinner;
      public AngleText () {
        setBackground ( Color.WHITE );
      }  // AngleText constructor
      protected void paintComponent ( Graphics _g ) {
        super.paintComponent ( _g );
        Graphics2D g = (Graphics2D)_g;
        g.setRenderingHint ( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
        AffineTransform at = AffineTransform.getRotateInstance ( Math.toRadians ( degrees ) );
        Font f =  g.getFont();
        g.setFont ( f.deriveFont ( at ) );
        g.drawString ( "Rotating Text!", getWidth()/2, getHeight()/2 );
        g.setRenderingHint ( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
      }  // paintComponent
      public JPanel getUIPanel () {
        SpinnerModel degreesModel = new SpinnerNumberModel (
                                      degrees  // initial
                                     ,0        // min
                                     ,360      // max
                                     ,2        // step
        degreesSpinner = new JSpinner ( degreesModel );
        degreesSpinner.addChangeListener ( new DegreesTracker() );
        JPanel panel = new JPanel();
        panel.add ( degreesSpinner );
        return panel;
      }  // getUIPanel
      //  DegreesTracker
      private class DegreesTracker implements ChangeListener {
        public void stateChanged ( ChangeEvent e ) {
          Integer i = (Integer)((JSpinner)e.getSource()).getValue();
          degrees   = i.intValue ();
          repaint();
      }  // DegreesTracker
      //  main
      public static void main ( String[] args ) {
        JFrame f = new JFrame ( "AngleText" );
        f.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
        AngleText app = new AngleText();
        f.getContentPane().add ( app );
        f.getContentPane().add ( app.getUIPanel(), BorderLayout.SOUTH );
        f.setSize ( 200, 200 );
        f.setVisible ( true );
      }  // main
    }  // AngleText

  • Are you drawing text at an angle with TextRenderer?

    This is a question for folks that are aware of the difference in quality of output between TextRenderer.DrawText and (Graphics.DrawString + Graphics.TextRenderingHint = Text.TextRenderingHint.AntiAlias). It is an issue that has been discussed by others,
    elsewhere, without resolution, and I'm simply asking if anyone has come up with a workaround.
    I want to render text in the quality of TextRenderer.DrawText, at right angles or upside down. TextFormatFlags.PreserveGraphicsTranslateTransform ignores calls to RotateTransform on the Graphics object that exposes IDeviceContext to DrawText, and DrawText doesn't
    play nicely with bitmaps.
    Has anyone figured out a way to draw text at the same quality provided by TextRenderer.DrawText, at an angle other than 0 degrees?
    (For those who need a back story to prove to you that I cannot use a Label or Graphics.DrawString for this, here you go.
    There is a cat stuck in a tree in my back yard. I would like to rescue him, but there is a troll standing between me and the tree. He's a nasty troll, but on TV he plays a happy-go-lucky helpful troll, so when I call the police to complain, they just laugh
    at me. "Ha! You can't fool us! We watch TV!"
    The troll will allow me to reach the cat if I provide him with a UserControl that renders text at the same quality as the Windows.Forms.Label control, but at angles 90, 180 and -90 degrees. He is a clever troll in that he notices details between shoddy and
    neat; rough and smooth; ugly and pretty; cat and honey badger. Therefore, I have not been able to fool him into thinking that ugly text is pretty by asserting that ugly text is pretty. Argh. I dislike this troll.)

    And this has to do with
    Usability Steven's
     issue in what fasion and why are you responding to somebody elses issue
    Mick Doherty? Or is this just for my information?
    La vida loca
    Hi Monkey
    This was mainly for info, but the OP did question the difference between GDI and GDIPlus methods of drawing rotated text. Your example only provides a GDIPlus method.
    GDI does not respect the Graphics objects rotations, but so long as the PreserveGraphicsTranslateTransform flag is set it will respect Translations.
    Here's a simple example to highlight the issue:
    Public Class Form1
    Public Sub New()
    ' This call is required by the designer.
    InitializeComponent()
    ' Add any initialization after the InitializeComponent() call.
    Me.SetStyle(ControlStyles.ResizeRedraw, True)
    End Sub
    Private Sub Form1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
    Dim testString As String = "My Test String"
    Dim angle As Single = 0
    If Me.CheckBox1.Checked Then angle = 180
    Using testFont As New Font("Arial", 24, FontStyle.Regular, GraphicsUnit.Point)
    Dim rc As Rectangle = Me.ClientRectangle
    rc.Offset(0, -24)
    Me.DrawRotatedGDIText(e.Graphics, testString, testFont, rc, Color.Red, angle)
    rc.Offset(0, 48)
    Me.DrawRotatedGDIPlusText(e.Graphics, testString, testFont, rc, Color.Black, angle)
    End Using
    End Sub
    Private Sub CheckBox1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
    Me.Invalidate()
    End Sub
    Private Sub DrawRotatedGDIText(graphics As Graphics, text As String, font As Font, bounds As Rectangle, color As Color, rotation As Single)
    Dim sz As Size = TextRenderer.MeasureText(text, font)
    Dim centre As Point = bounds.Location
    centre.Offset(bounds.Width \ 2, bounds.Height \ 2)
    Dim offset As Point = New Point(-sz.Width \ 2, -sz.Height \ 2)
    graphics.TranslateTransform(centre.X, centre.Y)
    graphics.RotateTransform(rotation)
    TextRenderer.DrawText(graphics, text, font, offset, color, TextFormatFlags.PreserveGraphicsTranslateTransform)
    graphics.ResetTransform()
    End Sub
    Private Sub DrawRotatedGDIPlusText(graphics As Graphics, text As String, font As Font, bounds As Rectangle, color As Color, rotation As Single)
    Dim sz As Size = graphics.MeasureString(text, font).ToSize
    Dim centre As Point = bounds.Location
    centre.Offset(bounds.Width \ 2, bounds.Height \ 2)
    Dim offset As Point = New Point(-sz.Width \ 2, -sz.Height \ 2)
    graphics.TranslateTransform(centre.X, centre.Y)
    graphics.RotateTransform(rotation)
    Using myBrush As New SolidBrush(color)
    graphics.DrawString(text, font, myBrush, offset)
    End Using
    graphics.ResetTransform()
    End Sub
    End Class
    Here you can see the GDI string (red text) is rendered differently to the GDI Plus string (black text) i.e. the GDI Plus text is longer. Both strings have been rendered to the correct location as set by the graphics transformation:
    Here a Rotation to the graphics object has been performed, but the GDi method has totally ignored it:
    As a rule, Win32 based controls render with GDI rather than GDI+ and so if we wish to draw a custom control which appears similar to a Win32 based control we need to render with GDI. If you've ever tried to ownerdraw a tabcontrol then you will have noticed
    that the text does not always fit on the tabs if we've used GDI+. using GDI the text fits perfectly, but when we side align the tabs the text does not rotate. We can, as the OP has done, draw unrotated text to a bitmap and then rotate the bitmap and this
    works well if we have a solid background. If we have a textured background however, this method is not acceptable.
    Mick Doherty
    http://dotnetrix.co.uk
    http://glassui.codeplex.com

  • Can someone help me with drawing text and a custom image in cocoa?

    I am trying to learn how to draw, and when I look at the tutorial, instead of getting straight to the point on how to draw text at a coordinate, it talks about the concepts of how to draw. I get that, but exactly what methods and what objects should I use?
    For instance, the java code:
    +public void drawComponent(Graphics g){+
    +Graphics2D g2 = (Graphics2D) g;+
    +g2.drawString("Hello, World!", 10, 20);+
    draws the good old "Hello, World!" on a line starting 20 pixels down and 10 pixels across. How would I do the same in objective-c in a customized view? Based on the tutorial, I need specify the code in the
    +- (void)drawRect: (NSRect) rect+
    method.
    Also, how would I draw a picture(.gif and .png format)?

    Here's a very basic example:
    - (void)drawRect:(NSRect)rect {
    // draw text
    NSString *myString = @"Hello World";
    NSFont *font = [NSFont boldSystemFontOfSize:24];
    NSColor *color = [NSColor blueColor];
    NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:
    font, NSFontAttributeName,
    color, NSForegroundColorAttributeName,
    nil];
    [myString drawAtPoint:NSMakePoint(20, 0) withAttributes:attrs];
    // draw image
    NSImage *myImage = [NSImage imageNamed:@"picture1.png"];
    [myImage drawAtPoint:NSMakePoint(20, 40)
    fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0];
    Since the above uses the imageNamed convenience method of NSImage, the arg must be the name of an image file you've previously added to the main bundle (Project->Add to Project). The code for a gif would be exactly the same.
    For more details see [Drawing Images into a View|https://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Coc oaDrawingGuide/Images/Images.html#//apple_ref/doc/uid/TP40003290-CH208-BCIIBDAD] and [Simple Text Drawing|https://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ CocoaDrawingGuide/Text/Text.html#//apple_ref/doc/uid/TP40003290-CH209-SW1] in the +Cocoa Drawing Guide+. Btw, the above is for OS X, since you asked about Cocoa. iPhone code is now called Cocoa Touch, so I hope I guessed the platform right. In case you really wanted iPhone, the code would be quite similar, but you'll need to substitute CGPointMake for NSMakePoint, UIColor for NSColor, UIImage for NSImage, and use a method like [drawAtPoint:forWidth:withFont:minFontSize:actualFontSize:lineBreakMode:baselin eAdjustment:|http://developer.apple.com/iphone/library/documentation/UIKit/Refer ence/NSStringUIKit_Additions/Reference/Reference.html#//appleref/doc/uid/TP40006893-CH3-SW14] for your text. You'll also only need one arg for the [drawAtPoint|http://developer.apple.com/iphone/library/documentation/UIKit/Refe rence/UIImageClass/Reference/Reference.html#//appleref/doc/uid/TP40006890-CH3-SW24] method of UIImage.
    Hope that helps get you started!
    - Ray

  • How to draw text to scale in actual inches?

    When I set my document to draw text in inches and then outline the text, its usually smaller than what it was supposed to be. How do I set it to draw to an accurate size while still in edit mode (not outlined)?

    It is exactly the size it is supposed to be. When you enter a type size, it is not the height of the capital letters, it's the distance from the tallest ascender to the lowest descender.
    all the text below is 12 point
    the only way to get what you want is to figure out the point size at which the capitals will equal .5 inches  - as you can see, this point size will vary depending on the font.

  • How draw TEXT to Image

    I have a Image component loaded from file :
    private Image bgImage;
    bgImage           = new ImageIcon("images/BackGround.jpg").getImage();
    And I want draw text to this image.
    How to do it?
    Best Regards.

    Related to this posting:
    http://forum.java.sun.com/thread.jspa?threadID=756975
    It would be nice if the OP will keep all the information together in one place so everybody knows what has already been suggested.

  • Appleworks6 (drawing - text & graphics) to be converted - how?

    I have a lot of mathematics worksheets, produced on Appleworks6 (on the drawing package with text and graphics) over the years. The new OS will not support Rosetta, I understand, and so I need to transfer (translate?) all the worksheets into a more modern format, available to both Mac and PC users. How do I do this and what applications are now available which will be suitable? If I try Word:mac (11.6.3) it tells me the Appleworks6 drawing document is not the right file type.

    If it were an AW6 text document with inserted graphics, then Pages would probably open it.
    However, as a drawing document with text added that may not work. It is possible that Keynote might be able to open it.
    Edit - - nope - just tried it with Keyboate, won't do it.
    Just played with AW6 a bit. If these documents are static docs, meaning ones which do not need to be changed or otherwise addressed except viewed, there's other choices. One I tried just now in AW6, ws to do a Save As and change the format to JPEG.
    This resulted in a document that should be openable by most anyone. In OS X, it opens in Preview automatically, but should be able to be opened in any app that can open JPEG files.
    In Pages it got a bit trickier - Pages would not open it directly, not even via Open in File menu. But, when I treated it as a regular JPEG it worked: I opened a blank text doc in Pages, then drag-and-dropped the JPEG file into it. That worked - gave me a Pages doc with an inserted image of the original AW6 graphics file.

  • Default gutter width for drawing text boxes for overset text

    I have master pages that were created with columns and the correct gutter width we want. When I drag a story from a window (a window that is part of our CMS) and place it on the page, the gutters between the text columns are correct -- p9 (or 0.125 inches). But if I draw a new text box or if I click the red plus to draw a text box for overset text, the gutter is a full pica (or 0.1667 inches).
    I want any text box that is drawn on the page or any overset text box that is drawn to default to p9 for gutters.
    I don't want to manually change the gutter for every new text box I draw.
    I'm using ID with CS4.
    Thank you.

    The default gutter in a multi-column frame is set in the object style under Text Frame General Options. If you haven't defined any new styles you only need to edit the [Basic Text Frame] style. New frames will use the new gutter value when you add columns. If you have object styles for other text frames, you'll need to edit those, too. For existing frames, if the number of columns has been changed manually, you will need to reset the gutter.

  • Drawing text on a canvas

    Hi everybody,
    I would like to know if it's possible to draw (not hard coded) text on a canvas. I know that you can put the text in a text field and afterwards you can copy the content of the text field to a certain place, chosen by the mouse. But the thing that I want to do is put the cursor on a certain place on the canvas and start entering some text.
    Does anybody know if that's possible and if yes, how do I have to start?
    Thanks for your help!!!
    E_J

    Hi everybody,
    I would like to know if it's possible to draw (not hard coded) text on a canvas. I know that you can put the text in a text field and afterwards you can copy the content of the text field to a certain place, chosen by the mouse. But the thing that I want to do is put the cursor on a certain place on the canvas and start entering some text.
    Does anybody know if that's possible and if yes, how do I have to start?
    Thanks for your help!!!
    E_J

  • Complete text on opengl es for ios

    Hello,
    what's a complete and correct textbook/guide/reference/manual/documentation on utilising OpenGL ES 2.0 under iOS 5 to achieve 3D graphics on iOS 5 and up devices?
    I found Apples guides wrong and omitting necessary steps, also they are badly organised and conceptually untargeted imo, see my 2 other inquiries.

    to clarify: I'm looking for a text on how to write the framework code for iOS to be able to then use OpenGL code, I'm not looking for a text on how to write OpenGL code.
    Currently I wrote around 30 lines of "code" following Apples Guides without any OpenGL ES graphics code (if you don't count Apples EGL implementation) and this framework isn't working.

  • Draw text with kerning

    Hi,
    I have to create an image using Java. I tryed using:
    g.setFont(new Font("Times New Roman",Font.PLAIN,50));
    This solution is not good because the font doesn't have the right kerning.
    My question is:
    How do I draw a text using the right kerning (like in Photoshop)?
    Please help me with that.
    Thanks,
    Andrei Todea ([email protected])

    hi rkippen,
    thanks for your help.
    the code that you gave me works but it's not what I want. I don't want do the kerning manually (what your code allows). I want it done by the system using the kerning table for each font. If this is not possible (but I can not imagine I'm the first guy who thought about writing a text that looks good even with large font weight using Java) than I would need to get the kerning table somehow and use it with your code.
    please help me with this problem.
    I really need to write this text with the correct kerning (like in Photoshop, Flash, Word...)
    thank you,
    andrei todea ([email protected])

  • LV 8.5.1 crashes drawing text....

    Since support now wants all these questions posted in the forums I will try it here...
    How come LV 8.5.1 has trouble drawing a simple text box?  LabVIEW has crashed a number of times.  This is on a cleanly installed system.  This program is designed to run continuously and reliably and did so under LV 8.2.1.  Now with an update to 8.5.1 I am losing this reliability.
    Here is the traceback from a memory protection fault.
    Thread 0 Crashed:
    0   libSystem.B.dylib               0x90004910 szone_malloc + 4056
    ...  bunch of apple libraries.
    13  com.apple.QD                   0x91788ed0 StdText + 308
    14  com.ni.labview                 0x005931dc LVHostDrawable_DrawTextBox(Rect*, long, unsigned char*, long, FontType_t*, DColorSet) + 1540
    As you can see LV is trying to draw a text box.  Simple no?  This is a large program that has a lot of asynchronous loops, DAQ, GPIB, Serial, DIO, and data logging.
    The only other hint I got was from the lvlog files.  I have the DialogWarn token set so they give more warnings than usual.
     plotsupp.cpp(4051) : DWarn: too many points in plot
    $Id: //labview/branches/Jupiter/dev/source/panel/plotsupp.cpp#53 $
    0x006FF498 - <unknown> + 6FF3C8
    Huh!  How many points is too many?  Almost all my plots are history charts with maybe 1000 pts max.  Probably more like 200.
    -Scott
    LV 8.5.1
    Mac OS X 10.4.11
    PPC

    Hi Johannes,
    I have already converted and saved the VI to LV8.5.1.
    Anyway, here are the steps to reproduce the problem:
      1. Open the LV7.1.1-VI using LV8.5.1
      2. Save it with LV 8.5.1
      3. Create a new project containing the VI and having it as startup VI in an Application
      4. Trying to build the application --> leads to the "source does not exist" error
    Attached is the source VI (vers. 7.1.1) causing the problem.
    thanks in advance,
    Leo
    Attachments:
    Check_Pfad.vi ‏44 KB

  • Drawing Text in Quartz - Text on head?

    Hi
    I have a very strange problem. I draw some text in a UIView.
    This looks like that:
    CGContextSelectFont(_context,"Courier", 18, kCGEncodingMacRoman);
    CGContextSetRGBStrokeColor (_context, 0, 0, 1, 1);
    CGContextTranslateCTM(_context, 30,10);
    CGContextShowTextAtPoint (_context, point.x, point.y,[aString UTF8String],[aString length]);
    CGContextRestoreGState(_context);
    The funny thing is, *the text is always painted on the head* ! I must have missed a very stupid thing, but I see no argument where I could change the direction or anything else.
    Another thing is transformation. If I do rotation, it works perfectly. If I do translation, nothing happens.
    Any hints?
    Thanks in advance!
    Daniel

    Couple of threads discussing this question:
    http://discussions.apple.com/thread.jspa?messageID=7891632&#7891632
    http://discussions.apple.com/message.jspa?messageID=7865805#7865805
    HTH
    Mike

  • [iPhone related] having trouble drawing text with Quartz

    I am unable to get any text to show up using Quartz.
    My context is showing other Quartz shapes like rects.
    Here is the code I'm using:
    string test = "this is a test";
    CGContextSetRGBFillColor(context, 0, 0, 0, 1);
    CGContextSetRGBStrokeColor(context, 1, 1, 1, 1);
    CGContextSelectFont (context, "Times-Bold", 20, kCGEncodingMacRoman);
    CGContextSetTextDrawingMode (context, kCGTextFillStroke);
    CGContextShowTextAtPoint(context, 30, 30, test.c_str(), test.length());
    Any help appreciated.

    I think your problem is that the iPhone only supports a very limited set of fonts.
    As far as i know, "Times-bold" is not one of them.
    The safest way is to do it like so:
    UIFont* font = [[UIFont systemFontOfSize:12.0]];
    CGContextSelectFont(context, [[font.fontName UTF8String]], 12.0, kCGEncodingMacRoman);
    Further more, I don't recommend using the method CGContextShowTextAtPoint() since it doesn't support unicode strings for non-english texts.
    The correct way to display text on the iPhone is like so:
    NSString* myStr = ....
    UIFont* font = [[UIFont systemFontOfSize:12.0]];
    UIGraphicsPushContext(context);
    [[myStr drawInRect: CGRectMake(x, y, w, h) withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter]];
    UIGraphicsPopContext();

  • Drawing  text in a jpeg image

    Hi,
    I want to draw a string in a jpeg image file.The file will contain only that string.Anybody can help me suggesting the best way or any available program is there for it.
    Thanks in advance.
    Papu

    You can use the image functions in PHP to get the size of JPEG, GIF, PNG, SWF, TIFF and JPEG2000 images, and if you have the GD library (available at http://www.boutell.com/gd/) you will also be able to create and manipulate images.
    good lock
    ciprian
    http://www.astroclaire.com

Maybe you are looking for