Text mit OpenGL rendern

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Text mit OpenGL rendern

    Hallo liebe Community,

    wir befinden uns in der drawRect() Methode, und ich würde gern mein String den ich in ein Bild umgewandelt habe in meinen OpenGLView packen. Leider weiß ich ganz und garnicht was ich falsch mache. Linien und Punkte habe ich bereits gezeichnet mein View hat eine Größe von 1000x1000.

    Quellcode

    1. NSFontManager *fontManager = [NSFontManager sharedFontManager];
    2. NSString* fontName =[NSString stringWithCString: "Helvetica" encoding: NSMacOSRomanStringEncoding];
    3. NSFont* font = [fontManager fontWithFamily:fontName traits:0 weight:5 size:25];
    4. NSMutableDictionary *m_attribs = [[NSMutableDictionary alloc] init];
    5. [m_attribs setObject:font forKey:NSFontAttributeName];
    6. NSString* aString = [NSString stringWithCString: "Halloposad jfosaiö jölas jdas " encoding: NSMacOSRomanStringEncoding];
    7. NSSize frameSize = [aString sizeWithAttributes: m_attribs];
    8. NSImage* image = [[NSImage alloc] initWithSize:frameSize];
    9. [image lockFocus];
    10. [aString drawAtPoint:NSMakePoint (0, 0) withAttributes:m_attribs];
    11. NSBitmapImageRep* bitmap = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect (0.0f, 0.0f, frameSize.width, frameSize.height)];
    12. [image unlockFocus];
    13. //Here is some code to create a texture with that image data.
    14. GLuint texture = 0;
    15. glGenTextures(1, &texture);
    16. glEnable(GL_TEXTURE_2D);
    17. glBindTexture(GL_TEXTURE_2D, texture);
    18. glEnable(GL_BLEND);
    19. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.size.width, image.size.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, [bitmap bitmapData]);
    20. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    21. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    Alles anzeigen