Skip to main content
Formatted title as question. Grammar clarifications to question body.
Source Link
Anko
  • 13.5k
  • 10
  • 56
  • 82

OpenGL ES with GLKit - applying How do I apply a texture over a material in OpenGL ES?

howHow can I apply a texture over a material?

I've set up an object with the following material:

GLKBaseEffect *effect; effect.colorMaterialEnabled = false; effect.material.ambientColor = GLKVector4Make(251.0/255.0, 95.0/255.0, 96.0/255.0, 1.0); effect.material.diffuseColor = GLKVector4Make(251.0/255.0, 95.0/255.0, 96.0/255.0, 1.0); 

and it is correctly rendered with a pink color.

WhenHowever, when I apply a texture with:

GLKTextureInfo * info = [GLKTextureLoader textureWithCGImage:...]; effect.texture2d0.name = info.name; effect.texture2d0.enabled = true; 

the material seems to disappear and I just see the texture; the object is transparent where the texture is not visible, instead of being pink.

Any hint is really appreciated!

 

Thanks, DANHere's an example:

UPDATE: here's an example, theThe texture is created with the following code:

- (UIImage*)generateTexturefromText:(NSString*)text { NSError *error; UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; myLabel.text = text; myLabel.font = [UIFont fontWithName:@"Helvetica""Helvetica" size:50]; myLabel.textAlignment = NSTextAlignmentLeft; myLabel.textColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1]; myLabel.backgroundColor = [UIColor clearColor]; myLabel.numberOfLines = -1; myLabel.lineBreakMode = NSLineBreakByCharWrapping; UIGraphicsBeginImageContextWithOptions(myLabel.bounds.size, NO, 1.0); CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0, 0); CGContextScaleCTM(UIGraphicsGetCurrentContext(), 1.0, 1.0); [myLabel.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *layerImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); if (error) { NSLog(@"" Error loading texture from image: %@"%",error); return nil; } return layerImage; } 

Why there'sis no color visible where the texture is transparent?

texture over material

OpenGL ES with GLKit - applying a texture over a material

how can I apply a texture over a material?

I've set up an object with the following material:

GLKBaseEffect *effect; effect.colorMaterialEnabled = false; effect.material.ambientColor = GLKVector4Make(251.0/255.0, 95.0/255.0, 96.0/255.0, 1.0); effect.material.diffuseColor = GLKVector4Make(251.0/255.0, 95.0/255.0, 96.0/255.0, 1.0); 

and it is correctly rendered with a pink color.

When I apply a texture with:

GLKTextureInfo * info = [GLKTextureLoader textureWithCGImage:...]; effect.texture2d0.name = info.name; effect.texture2d0.enabled = true; 

the material seems to disappear and I just see the texture; the object is transparent where the texture is not visible instead of being pink.

Any hint is really appreciated!

Thanks, DAN

UPDATE: here's an example, the texture is created with the following code:

- (UIImage*)generateTexturefromText:(NSString*)text { NSError *error; UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; myLabel.text = text; myLabel.font = [UIFont fontWithName:@"Helvetica" size:50]; myLabel.textAlignment = NSTextAlignmentLeft; myLabel.textColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1]; myLabel.backgroundColor = [UIColor clearColor]; myLabel.numberOfLines = -1; myLabel.lineBreakMode = NSLineBreakByCharWrapping; UIGraphicsBeginImageContextWithOptions(myLabel.bounds.size, NO, 1.0); CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0, 0); CGContextScaleCTM(UIGraphicsGetCurrentContext(), 1.0, 1.0); [myLabel.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *layerImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); if (error) { NSLog(@" Error loading texture from image: %@",error); return nil; } return layerImage; } 

Why there's no color where the texture is transparent?

texture over material

How do I apply a texture over a material in OpenGL ES?

How can I apply a texture over a material?

I've set up an object with the following material:

GLKBaseEffect *effect; effect.colorMaterialEnabled = false; effect.material.ambientColor = GLKVector4Make(251.0/255.0, 95.0/255.0, 96.0/255.0, 1.0); effect.material.diffuseColor = GLKVector4Make(251.0/255.0, 95.0/255.0, 96.0/255.0, 1.0); 

and it is correctly rendered with a pink color.

However, when I apply a texture with:

GLKTextureInfo * info = [GLKTextureLoader textureWithCGImage:...]; effect.texture2d0.name = info.name; effect.texture2d0.enabled = true; 

the material seems to disappear and I just see the texture; the object is transparent where the texture is not visible, instead of being pink.

 

Here's an example:

The texture is created with the following code:

- (UIImage*)generateTexturefromText:(NSString*)text { NSError *error; UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; myLabel.text = text; myLabel.font = [UIFont fontWithName:"Helvetica" size:50]; myLabel.textAlignment = NSTextAlignmentLeft; myLabel.textColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1]; myLabel.backgroundColor = [UIColor clearColor]; myLabel.numberOfLines = -1; myLabel.lineBreakMode = NSLineBreakByCharWrapping; UIGraphicsBeginImageContextWithOptions(myLabel.bounds.size, NO, 1.0); CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0, 0); CGContextScaleCTM(UIGraphicsGetCurrentContext(), 1.0, 1.0); [myLabel.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *layerImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); if (error) { NSLog(" Error loading texture from image: %",error); return nil; } return layerImage; } 

Why is no color visible where the texture is transparent?

texture over material

added 1395 characters in body
Source Link
DAN
  • 337
  • 3
  • 9

how can I apply a texture over a material?

I've set up an object with the following material:

GLKBaseEffect *effect; effect.colorMaterialEnabled = false; effect.material.ambientColor = GLKVector4Make(251.0/255.0, 95.0/255.0, 96.0/255.0, 1.0); effect.material.diffuseColor = GLKVector4Make(251.0/255.0, 95.0/255.0, 96.0/255.0, 1.0); 

and it is correctly rendered with a pink color.

When I apply a texture with:

GLKTextureInfo * info = [GLKTextureLoader textureWithCGImage:...]; effect.texture2d0.name = info.name; effect.texture2d0.enabled = true; 

the material seems to disappear and I just see the texture; the object is transparent where the texture is not visible instead of being pink.

Any hint is really appreciated!

Thanks, DAN

UPDATE: here's an example, the texture is created with the following code:

- (UIImage*)generateTexturefromText:(NSString*)text { NSError *error; UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; myLabel.text = text; myLabel.font = [UIFont fontWithName:@"Helvetica" size:50]; myLabel.textAlignment = NSTextAlignmentLeft; myLabel.textColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1]; myLabel.backgroundColor = [UIColor clearColor]; myLabel.numberOfLines = -1; myLabel.lineBreakMode = NSLineBreakByCharWrapping; UIGraphicsBeginImageContextWithOptions(myLabel.bounds.size, NO, 1.0); CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0, 0); CGContextScaleCTM(UIGraphicsGetCurrentContext(), 1.0, 1.0); [myLabel.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *layerImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); if (error) { NSLog(@" Error loading texture from image: %@",error); return nil; } return layerImage; } 

Why there's no color where the texture is transparent?

texture over material

how can I apply a texture over a material?

I've set up an object with the following material:

GLKBaseEffect *effect; effect.colorMaterialEnabled = false; effect.material.ambientColor = GLKVector4Make(251.0/255.0, 95.0/255.0, 96.0/255.0, 1.0); effect.material.diffuseColor = GLKVector4Make(251.0/255.0, 95.0/255.0, 96.0/255.0, 1.0); 

and it is correctly rendered with a pink color.

When I apply a texture with:

GLKTextureInfo * info = [GLKTextureLoader textureWithCGImage:...]; effect.texture2d0.name = info.name; effect.texture2d0.enabled = true; 

the material seems to disappear and I just see the texture; the object is transparent where the texture is not visible instead of being pink.

Any hint is really appreciated!

Thanks, DAN

how can I apply a texture over a material?

I've set up an object with the following material:

GLKBaseEffect *effect; effect.colorMaterialEnabled = false; effect.material.ambientColor = GLKVector4Make(251.0/255.0, 95.0/255.0, 96.0/255.0, 1.0); effect.material.diffuseColor = GLKVector4Make(251.0/255.0, 95.0/255.0, 96.0/255.0, 1.0); 

and it is correctly rendered with a pink color.

When I apply a texture with:

GLKTextureInfo * info = [GLKTextureLoader textureWithCGImage:...]; effect.texture2d0.name = info.name; effect.texture2d0.enabled = true; 

the material seems to disappear and I just see the texture; the object is transparent where the texture is not visible instead of being pink.

Any hint is really appreciated!

Thanks, DAN

UPDATE: here's an example, the texture is created with the following code:

- (UIImage*)generateTexturefromText:(NSString*)text { NSError *error; UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; myLabel.text = text; myLabel.font = [UIFont fontWithName:@"Helvetica" size:50]; myLabel.textAlignment = NSTextAlignmentLeft; myLabel.textColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1]; myLabel.backgroundColor = [UIColor clearColor]; myLabel.numberOfLines = -1; myLabel.lineBreakMode = NSLineBreakByCharWrapping; UIGraphicsBeginImageContextWithOptions(myLabel.bounds.size, NO, 1.0); CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0, 0); CGContextScaleCTM(UIGraphicsGetCurrentContext(), 1.0, 1.0); [myLabel.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *layerImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); if (error) { NSLog(@" Error loading texture from image: %@",error); return nil; } return layerImage; } 

Why there's no color where the texture is transparent?

texture over material

added 1 characters in body
Source Link
DAN
  • 337
  • 3
  • 9

how can I apply a texture over a material?

I've set up an object with the following material:

GLKBaseEffect *effect; effect.colorMaterialEnabled = false; effect.material.ambientColor = GLKVector4Make(251.0/255.0, 95.0/255.0, 96.0/255.0, 1.0); effect.material.diffuseColor = GLKVector4Make(251.0/255.0, 95.0/255.0, 96.0/255.0, 1.0); 

and it is correctly rendered with a pink color.

When I apply a texture with:

GLKTextureInfo * info = [GLKTextureLoader textureWithCGImage:...]; effect.texture2d0.name = info.name; effect.texture2d0.enabled = true; 

the material seems to disappear and I just see the texture; the object is transparent where the texture is nonot visible instead of being pink.

Any hint is really appreciated!

Thanks, DAN

how can I apply a texture over a material?

I've set up an object with the following material:

GLKBaseEffect *effect; effect.colorMaterialEnabled = false; effect.material.ambientColor = GLKVector4Make(251.0/255.0, 95.0/255.0, 96.0/255.0, 1.0); effect.material.diffuseColor = GLKVector4Make(251.0/255.0, 95.0/255.0, 96.0/255.0, 1.0); 

and it is correctly rendered with a pink color.

When I apply a texture with:

GLKTextureInfo * info = [GLKTextureLoader textureWithCGImage:...]; effect.texture2d0.name = info.name; effect.texture2d0.enabled = true; 

the material seems to disappear and I just see the texture; the object is transparent where the texture is no visible instead of being pink.

Any hint is really appreciated!

Thanks, DAN

how can I apply a texture over a material?

I've set up an object with the following material:

GLKBaseEffect *effect; effect.colorMaterialEnabled = false; effect.material.ambientColor = GLKVector4Make(251.0/255.0, 95.0/255.0, 96.0/255.0, 1.0); effect.material.diffuseColor = GLKVector4Make(251.0/255.0, 95.0/255.0, 96.0/255.0, 1.0); 

and it is correctly rendered with a pink color.

When I apply a texture with:

GLKTextureInfo * info = [GLKTextureLoader textureWithCGImage:...]; effect.texture2d0.name = info.name; effect.texture2d0.enabled = true; 

the material seems to disappear and I just see the texture; the object is transparent where the texture is not visible instead of being pink.

Any hint is really appreciated!

Thanks, DAN

Source Link
DAN
  • 337
  • 3
  • 9
Loading