Hello all,
Having a bit of trouble here, trying to take the GLSprite texture loading code and transform it into a class, but im getting some strange build errors (Symbol(s) not found) that I can't figure out why I'm getting. Would appreciate it if anyone could take a look at it and tell me what I'm doing wrong, as my searches so far have turned up nothing.
Code and errors are as follows:
Texture.h
Texture.m
Error Output:
Again, any help would be greatly appreciated.
Thanks,
-Limb
Having a bit of trouble here, trying to take the GLSprite texture loading code and transform it into a class, but im getting some strange build errors (Symbol(s) not found) that I can't figure out why I'm getting. Would appreciate it if anyone could take a look at it and tell me what I'm doing wrong, as my searches so far have turned up nothing.
Code and errors are as follows:
Texture.h
Code:
#import <UIKit/UIKit.h>
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
@interface Texture : NSObject {
GLuint spriteTexture;
}
- (GLuint) initWithImage:(NSString *)image;
@end
Texture.m
Code:
#import <QuartzCore/QuartzCore.h>
#import <OpenGLES/EAGLDrawable.h>
#import "Texture.h"
@implementation Texture
- (GLuint)initWithImage:(NSString *) Image
{
CGImageRef spriteImage;
CGContextRef spriteContext;
GLubyte *spriteData;
size_t width, height;
// Creates a Core Graphics image from an image file
spriteImage = [UIImage imageNamed:Image].CGImage;
// Get the width and height of the image
width = CGImageGetWidth(spriteImage);
height = CGImageGetHeight(spriteImage);
// Texture dimensions must be a power of 2. If you write an application that allows users to supply an image,
// you'll want to add code that checks the dimensions and takes appropriate action if they are not a power of 2.
if(spriteImage) {
// Allocated memory needed for the bitmap context
spriteData = (GLubyte *) malloc(width * height * 4);
// Uses the bitmatp creation function provided by the Core Graphics framework.
spriteContext = CGBitmapContextCreate(spriteData, width, height, 8, width * 4, CGImageGetColorSpace(spriteImage), kCGImageAlphaPremultipliedLast);
// After you create the context, you can draw the sprite image to the context.
CGContextDrawImage(spriteContext, CGRectMake(0.0, 0.0, (CGFloat)width, (CGFloat)height), spriteImage);
// You don't need the context at this point, so you need to release it to avoid memory leaks.
CGContextRelease(spriteContext);
// Use OpenGL ES to generate a name for the texture.
glGenTextures(1, &spriteTexture);
// Bind the texture name.
glBindTexture(GL_TEXTURE_2D, spriteTexture);
// Speidfy a 2D texture image, provideing the a pointer to the image data in memory
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, spriteData);
// Release the image data
free(spriteData);
// Set the texture parameters to use a minifying filter and a linear filer (weighted average)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// Enable use of the texture
glEnable(GL_TEXTURE_2D);
// Set a blending function to use
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
// Enable blending
glEnable(GL_BLEND);
}
return spriteTexture;
}
@end
Error Output:
Code:
Undefined symbols:
"_CGContextRelease", referenced from:
-[Texture initWithImage:] in Texture.o
"_CGContextDrawImage", referenced from:
-[Texture initWithImage:] in Texture.o
"_CGBitmapContextCreate", referenced from:
-[Texture initWithImage:] in Texture.o
"_CGImageGetColorSpace", referenced from:
-[Texture initWithImage:] in Texture.o
"_CGImageGetWidth", referenced from:
-[Texture initWithImage:] in Texture.o
"_CGImageGetHeight", referenced from:
-[Texture initWithImage:] in Texture.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Again, any help would be greatly appreciated.
Thanks,
-Limb