Vorel512

Members
  • Content count

    45
  • Joined

  • Last visited

Community Reputation

130 Neutral

About Vorel512

  • Rank
    Member
  1. Resolved! The problem was, that the frame size should be power of two. Please mark this topic "Resolved"!
  2. Rendering text iPhone

    The problem was, that the frame size has to be power of two. Please mark this topic "Resolved".
  3. Hi, 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. Thanx, RP 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]
  4. GLSL normals problem?

    Hi you have to rotate the normal like: [source lang="cpp"]mat4 rotate_x(float theta) { return mat4( 1.0, 0.0, 0.0, 0.0, 0.0, cos(theta), sin(theta), 0.0, 0.0, -sin(theta), cos(theta), 0.0, 0.0, 0.0, 0.0, 1.0 ); } void main() { .... .... mat4 tRotation = rotate_x(originalRotation.x); vec4 newTranslation = vec4(tRotation * PositionFromAttributes); vec3 eyeNormal = NormalMatrix3x3 * vec3(newTranslation) * NormalFromAttributes; .... .... }[/source]
  5. I've made a new function just for text rendering, but the picture is black anyway. I've tried to change the color values in the label, but still black output. [source lang="cpp"]- (GLuint)setupTextTexture:(NSString *)text { //0 CGPoint position = CGPointMake(0,0); // Make a UILabel with the string UIFont *font = [UIFont fontWithName:@"Georgia" 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; // Make a UIImage with the UILabel UIGraphicsBeginImageContext(label.frame.size); [[label layer] renderInContext:UIGraphicsGetCurrentContext()]; UIImage *layerImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); // 1 CGImageRef spriteImage = layerImage.CGImage; if (!spriteImage) { NSLog(@"Failed to setup text image %@", text); exit(1); } // 2 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*4, CGImageGetColorSpace(spriteImage), kCGImageAlphaPremultipliedLast); // 3 CGContextDrawImage(spriteContext, CGRectMake(0, 0, width, height), spriteImage); CGContextRelease(spriteContext); // 4 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]
  6. GLSL multitexturing

    Okay, I missed '1' at the second glUniform1i(_textureUniform1, 0); I've set the mix to the second pictures alpha channel, and now it looks much more proper. But some pixels has alpha 1... I do not know why, because the background image has alpha 255 everywhere.
  7. 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!
  8. 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]
  9. OpenGL render vbo not working

    Hello, So... [color=#000000]glBufferData[/color][color=#666600]([/color][color=#000000]GL_ARRAY_BUFFER[/color][color=#666600],[/color][color=#000000] [/color][color=#000088]sizeof[/color][color=#666600]([/color][color=#660066]Vertex[/color][color=#666600])*[/color][color=#006666]3[/color][color=#666600],&[/color][color=#000000]triangle[/color][color=#666600][[/color][color=#006666]0[/color][color=#666600]].[/color][color=#000000]x[/color][color=#666600],[/color][color=#000000]GL_STATIC_DRAW[/color][color=#666600]);[/color] You should pass a pointer to "&triangle" and with sizeof(triangle) now you allocate memory for only the first position. And then try to set opengl where to search for specified data like normals. It would be a great start to read and try out some example." [CODE] #define BUFFER_OFFSET(i) ((char *)NULL + (i)) glEnableVertexAttribArray(GLKVertexAttribPosition); glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(0)); glEnableVertexAttribArray(GLKVertexAttribNormal); glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12)); glEnableVertexAttribArray(GLKVertexAttribTexCoord0); glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(24)); [/CODE] [font="monospace"][color="#000000"]sizeof() gives you the size of the variable in bytes, not the amount of data stored in them. In your case all vertexes has 8 elements (3+3+2 = 8) and 3 vertexes (3*8=24).[/color][/font]
  10. In Instruments I do not see any memory drop. Even if I remove a lot of textures. Maybe it is because I use automatic reference counting.
  11. 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!
  12. I suppose, that you are not created any threads. It looks like, that the execution stuck between the mThread class.
  13. Hello there experts! So... 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. [CODE] if ([[[cManager getAttributeAtIndex:index] getAttribName] isEqualToString:@"adam"]) { NSLog(@"match!"); } [/CODE] 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!!!!!
  14. dynamic music

    Hi JoJoSim1! I would suggest this AVFoundation framework for a start. You can set pan, volume, and also play from time, etc. On my first app I used it with touches ended event. Every object had its own sound, and I played it when the user touched the object. Also there is the OpenAL framework, but I am still a newbie in that...
  15. Hi there! Usually the built in functions are faster than a thing you write, because they are working directly with the DX "core". But testing is always a good idea, nobody is a god, so there can be functions that fit more for you. In your case maybe I would go for the hand written one, maybe some day that knowledge will be useful.