Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

seventoes

macrumors newbie
Original poster
Feb 5, 2008
28
0
This is probably something simple, but I cant seem to spot whats wrong with it.

http://img386.imageshack.us/my.php?image=picture4gk6.png

:confused:

I load the image just like the GLSprite example,
Code:
tempImage = [UIImage imageNamed:@"BackgroundGrid.png"].CGImage;
width = next_power_of_2(CGImageGetWidth(tempImage));
height = next_power_of_2(CGImageGetHeight(tempImage));
		
	// Allocate memory for bitmap context
	tempData = (GLubyte *) malloc(width * height * 4);
	tempContext = CGBitmapContextCreate(tempData, width, height, 8, width*4, CGImageGetColorSpace(tempImage), kCGImageAlphaPremultipliedLast);
	// Draw sprite on the context
	CGContextDrawImage(tempContext, CGRectMake(0, 0, (CGFloat)width, (CGFloat)height), tempImage);

// etc...
My power of 2 function is working fine, but it looks like some size is being messed up somewhere. I'm thinking it has something to do with the arrays im using for glTexturePointer and glTexCoordPointer, since i still dont fully get what those 2 are for. I tried to go through the Texture2D code to figure out what values to use, and i came up with this:
Code:
// Sets up an array of values to use as the sprite vertices.
const GLfloat spriteVertices[] = {
0, 0, 1,
320, 0, 1,
0, 480, 1,
320, 480, 1,
};

// Sets up an array of values for the texture coordinates.
const GLshort spriteTexcoords[] = {
0, 1,
1, 1,
0, 0,
1, 0,
};
Drawing with:
Code:
glBindTexture(GL_TEXTURE_2D, sprites[eTexBackground].tex);
glVertexPointer(3, GL_FLOAT, 0, spriteVertices);
glTexCoordPointer(2, GL_FLOAT, 0, spriteTexcoords);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
Also the texture randomly flashes on and off the screen :-/

Anyone tell me what noob mistake I'm making?
 

DipDog3

macrumors 65816
Sep 20, 2002
1,193
814
Try

tempContext = CGBitmapContextCreate(tempData, width, height, 8, width, CGImageGetColorSpace(tempImage), kCGImageAlphaPremultipliedLast);

Changed the width*4 to width for bytesPerRow.
 

ThaBunny

macrumors newbie
Aug 2, 2008
10
0
You're passing your texcoords as FLOAT, but they're SHORTs

Change the texcoord array to

const float spriteTexcoords[] = {
0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
};
 

seventoes

macrumors newbie
Original poster
Feb 5, 2008
28
0
You're passing your texcoords as FLOAT, but they're SHORTs

Change the texcoord array to

const float spriteTexcoords[] = {
0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
};
That was it!! I knew it was something stupid. :p Thanks so much!

Now the texture is showing up just fine, but its randomly flashing :(

EDIT: Nevermind on that one, my erase function was swapping the buffers :|

Thanks for the help!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.