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.
Alles anzeigen
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
- NSFontManager *fontManager = [NSFontManager sharedFontManager];
- NSString* fontName =[NSString stringWithCString: "Helvetica" encoding: NSMacOSRomanStringEncoding];
- NSFont* font = [fontManager fontWithFamily:fontName traits:0 weight:5 size:25];
- NSMutableDictionary *m_attribs = [[NSMutableDictionary alloc] init];
- [m_attribs setObject:font forKey:NSFontAttributeName];
- NSString* aString = [NSString stringWithCString: "Halloposad jfosaiö jölas jdas " encoding: NSMacOSRomanStringEncoding];
- NSSize frameSize = [aString sizeWithAttributes: m_attribs];
- NSImage* image = [[NSImage alloc] initWithSize:frameSize];
- [image lockFocus];
- [aString drawAtPoint:NSMakePoint (0, 0) withAttributes:m_attribs];
- NSBitmapImageRep* bitmap = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect (0.0f, 0.0f, frameSize.width, frameSize.height)];
- [image unlockFocus];
- //Here is some code to create a texture with that image data.
- GLuint texture = 0;
- glGenTextures(1, &texture);
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, texture);
- glEnable(GL_BLEND);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.size.width, image.size.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, [bitmap bitmapData]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);