Opengl/Cocoa text rendering - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Opengl/Cocoa text rendering (/thread-9289.html)
Pages: 1 2
Opengl/Cocoa text rendering - tesil - Aug 20, 2011 11:25 AM
So for a couple years I'd been using the code from OSC's text tutorial to render fast text into opengl views. I just got lion and tried running a project that previously worked fine in 10.6 and now i get static and strange/seemingly random artifacts within the text's bounding rect. Anyone ideas or similar experiences?
RE: Opengl/Cocoa text rendering - OneSadCookie - Aug 20, 2011 01:39 PM
http://onesadcookie.com/svn/NSViewTexture/ broke at 10.6 (which I fixed in r2691), but I just checked and it still seems to work on Lion?
RE: Opengl/Cocoa text rendering - tesil - Aug 20, 2011 05:32 PM
Hmmm, that's odd. I just tried it again in a new empty project and got the same effect, static fill the quad behind the text (the text does display).
RE: Opengl/Cocoa text rendering - OneSadCookie - Aug 20, 2011 06:14 PM
have you got blending turned on? perhaps the transparent pixels are not black?
RE: Opengl/Cocoa text rendering - tesil - Aug 20, 2011 06:27 PM
Nope, I copied you're code exactly into an empty project. Could it be some Xcode thing? ...Because as far as I can see that's the only difference aside from lion.
RE: Opengl/Cocoa text rendering - OneSadCookie - Aug 20, 2011 09:29 PM
Well, does it work if you actually use my Xcode project?
The project I have is probably set up to build against the 10.6 SDK... does it work if you change that setting?
RE: Opengl/Cocoa text rendering - tesil - Aug 21, 2011 10:36 AM
I didn't see a way to download the actual project so I just copied the NSViewTexture class files into the project, then I copied all of the code from NSViewTextureTest.cpp into my projects main file.
So I tried changing both the base sdk and the deployment target but neither made a difference. Then I switched the architecture from the default 64 bit to 32 and it worked (regardless of the sdk), though I have not the slightest idea of why.
RE: Opengl/Cocoa text rendering - OneSadCookie - Aug 21, 2011 05:48 PM
It seems to work in 64-bit when I make that change here...
RE: Opengl/Cocoa text rendering - tesil - Aug 23, 2011 11:22 AM
Okay, so I think I've got the first part taken care of. But there's still one issue. Using the code from the tutorial I created a routine to create textures on the fly which are deleted upon use, but the problem is that the text sitting in the supposedly deleted textures shows up in all subsequent textures.
RE: Opengl/Cocoa text rendering - tesil - Aug 24, 2011 10:24 AM
Basically each time I call fast_text, the next text is textured over whatever text was drawn into the view from the previous call; it's as if the view itself had never been deallocated however (and thus accumulates whatever is drawn into it), from my understanding of the code, ConvenienceReleaseNSTextView() should delete the view and make is okay for me to call ConvenienceCreateNSTextView() for 'view' once again, right?
RE: Opengl/Cocoa text rendering - OneSadCookie - Aug 28, 2011 09:21 AM
The code was using malloc to allocate memory for the bitmap, assuming Cocoa would clear it, but running afoul of it being coincidentally clear the first allocation.
I've fixed the code to use calloc instead, and updated the sample app to a case that hit the problem.
RE: Opengl/Cocoa text rendering - tesil - Feb 25, 2012 08:51 AM
One - I've been using this code for quite some time to render text in an app I'm working on. Recently I enabled distributed objects logging via the product->edit_scheme menu as part of an unrelated debugging effort and I noticed a lot of logging activity - which for the life of me I'm unable to understand - going on as the result of the above mentioned text drawing code. Here's a sample:
Is this normal or something I should be worried about?
And two - I was fooling around with apples code for doing opengl text (GLString) and was unable to find a way in which to constrain the text so as to keep it within the bounds of a predefined rectangle. Anyone know how to do this?
RE: Opengl/Cocoa text rendering - SethWillits - Feb 25, 2012 12:21 PM
That's logging the chatter that DO uses. I don't see how this at all relates to your text rendering or how it's a problem.
As for bounding the text, I assume you mean you want to be able to create a really long string, but have it wrap, or truncate?
It looks like if you use useStaticFrame: then it'll draw the string into a frame no larger than that given size, but the text will be single-line only and cut off rather than nicely truncated.
If you want wrapping or truncation, you'll need to modify GLString. In genTexture it's using [string drawAtPoint:...]; You'll want to use drawWithRect:options: with the option NSStringDrawingUsesLineFragmentOrigin I believe (for wrapping), and setup an NSMutableParagraph style with a line break mode for truncation.
RE: Opengl/Cocoa text rendering - tesil - Feb 27, 2012 08:08 AM
(Feb 25, 2012 12:21 PM)SethWillits Wrote: I don't see how this at all relates to your text rendering or how it's a problem.
The text rendering is what seems to be generating the logs. When I turn it off, the logs disappear - in fact, I get no logs whatsoever when not rendering text.
RE: Opengl/Cocoa text rendering - tesil - Mar 20, 2012 07:39 AM
By the way, will this code work on iOS?