Jump to content

  • Log In with Google      Sign In   
  • Create Account

Gamedev.net will be down tonight at approximately 9pm EST for site maintenance


Member Since 02 Jan 2012
Offline Last Active Aug 30 2012 06:42 AM

Topics I've Started

Rendering text iPhone

13 August 2012 - 02:59 AM


I would like to ask for a little help. I am stuck with displaying texts with OpenGL ES 2.0. I have read a lot of tutorial, but none of them working.
If anybody knows where can I find some working example please link it here.


My existing, tho not working code:
[source lang="cpp"]- (GLuint)setupTextTexture:(NSString *)text { CGPoint position = CGPointMake(0,0); UIFont *font = [UIFont fontWithName:@"Arial" size:12]; CGSize size = [text sizeWithFont:font forWidth:12 lineBreakMode:UILineBreakModeClip]; CGRect frame; frame.origin = position; frame.size = size; UILabel *label = [[UILabel alloc]initWithFrame:frame]; label.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1]; label.text = text; label.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; label.font = font; label.alpha = 1; UIGraphicsBeginImageContext(label.frame.size); [[label layer] renderInContext:UIGraphicsGetCurrentContext()]; UIImage *layerImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); CGImageRef spriteImage = layerImage.CGImage; if (!spriteImage) { NSLog(@"Failed to setup text image %@", text); exit(1); } size_t width = CGImageGetWidth(spriteImage); size_t height = CGImageGetHeight(spriteImage); GLubyte * spriteData = (GLubyte *) calloc(width*height*4, sizeof(GLubyte)); CGContextRef spriteContext = CGBitmapContextCreate(spriteData, width, height, 8, width*height*4, CGColorSpaceCreateDeviceGray(), kCGImageAlphaNone); CGContextDrawImage(spriteContext, CGRectMake(0, 0, width, height), spriteImage); CGContextRelease(spriteContext); GLuint texName; glGenTextures(1, &texName); glBindTexture(GL_TEXTURE_2D, texName); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, spriteData); free(spriteData); return texName;}[/source]

GLSL multitexturing

24 July 2012 - 06:54 AM

Hi experts,

I am learning shader programming, and I do not know how to place a picture on another.

My obj-c code:
[source lang="cpp"] glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, _fishTexture); glUniform1i(_textureUniform0, 0); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, _floorTexture); glUniform1i(_textureUniform1, 0); glUniformMatrix4fv(_modelViewUniform, 1, 0, modelView.glMatrix); glUniformMatrix3fv(_modelNormalUniform, 1, 0, modelView.glMatrix); glViewport(0, 0, self.frame.size.width, self.frame.size.height); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); glVertexAttribPointer(_positionSlot, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex2), 0); glVertexAttribPointer(_colorSlot, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex2), (GLvoid*) (sizeof(float) * 3)); glVertexAttribPointer(_normalSlot, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex2), (GLvoid*) (sizeof(float) * 7)); glVertexAttribPointer(_texCoordSlot, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*) (sizeof(float) * 10));[/source]

And my fragment shader:
[source lang="cpp"]varying lowp vec4 DestinationColor;varying lowp vec2 TexCoordOut;uniform sampler2D Texture0,Texture1; void main(void){ gl_FragColor = mix(texture2D(Texture0,TexCoordOut),texture2D(Texture1, TexCoordOut),1);}[/source]

Also I have the right declarations and syntax. But it displays only one of my pictures. (I have a neon green and a grey plain texture, and the grey is shown always, no matter the query...)

As far as I know the mix() function return value is computed as follows: x*(1-a)+y*a. So if I set it to 1, the second texture (Texture1) will be above the first. I do not want to calculate some colors, I want to use the images as they are, but on top of each other.

Thanx in advance!

Create textures from text OpenGL ES 2.0 / GLKit

28 June 2012 - 02:21 AM

Hi all,

I have a code snippet, and it seems not working, if anyone run into the same problem and solved, please post the know how.
The error is, the image results in a black plain. Other images I use are work nice, just this text rendering not...
[source lang="cpp"]NSString *aString = [NSString stringWithFormat:@"Hello World."]; CGPoint position = CGPointMake(10,10); // Make a UILabel with the string UIFont *font = [UIFont fontWithName:@"Georgia" size:50]; CGSize size = [aString sizeWithFont:font forWidth:20 lineBreakMode:UILineBreakModeClip]; CGRect frame; frame.origin = position; frame.size = size; UILabel *label = [[UILabel alloc]initWithFrame:frame]; label.backgroundColor = [UIColor clearColor]; label.text = aString; label.textColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1]; label.font = font; // Make a UIImage with the UILabel UIGraphicsBeginImageContext(label.frame.size); [[label layer] renderInContext:UIGraphicsGetCurrentContext()]; UIImage *layerImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); // Get a textureInfo from the UILabel texture = [GLKTextureLoader textureWithCGImage:layerImage.CGImage options:options error:&error]; if (texture == nil) { NSLog(@"Texture Error:%@", error); }[/source]

glDeleteTextures does not remove picture from memory

09 May 2012 - 06:02 AM

Hi Experts,

I've run into an irritating problem.
After I load a picture with GLKTextureLoader, I can not free it from memory.
When I call glDeleteTextures(1,&texturename), nothing happens.

I use OpenglES2.0 on iOS5.1

Thanks in advance!

memory leak when using NSString isEqualToString

03 May 2012 - 08:20 AM

Hello there experts!

I have an array (NSMutableArray) of a class.
In the class I store Name and Address.
When I want to compare the contents to a string, which I've added by code, it eats more and more memory.
if ([[[cManager getAttributeAtIndex:index] getAttribName] isEqualToString:@"adam"])

getAttribName is the name of the person in an NSString object.
When I run Instruments, it tells me, that the program eats more and more memory. If I comment out this if function, the growing stops.
For me it looks like I've allocate a variable and not deallocate it.
I am out of ideas what's gone wrong, so every help is appreciate!!!!!