Texture2d rainbow effect on flip
Hi everyone.
I've been using OpenGL ES on the iPhone for a while. My purpose is to draw charts. But when it comes to displaying numbers things become tough
I use Texture2D class to draw numbers but when one texture draws on top of another I get rainbow effect when I flip my view 
Here's my code.
![[Image: RmcCI3wvWQ.jpg]](http://pic.ipicture.ru/uploads/090318/RmcCI3wvWQ.jpg)
Any clues?
I've been using OpenGL ES on the iPhone for a while. My purpose is to draw charts. But when it comes to displaying numbers things become tough
I use Texture2D class to draw numbers but when one texture draws on top of another I get rainbow effect when I flip my view 
Here's my code.
Code:
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
for(int i = 0; i != 2; i++)
{
Texture2D* testTex = [[Texture2D alloc] initWithString:@"Hello" dimensions:CGSizeMake(20, 20) alignment:UITextAlignmentCenter fontName:@"Helvetica" fontSize:14];
[testTex drawAtPoint:CGPointMake(200.0f, 200.0f)];
[testTex release];
}
glDisable(GL_BLEND);![[Image: RmcCI3wvWQ.jpg]](http://pic.ipicture.ru/uploads/090318/RmcCI3wvWQ.jpg)
Any clues?
First off, for debugging graphics issues, screenshots are worth more than a thousand words. 
Are you sure that you can delete textures before the rendering is complete? I would expect that it would be fine, but I've never actually tried it before.

Are you sure that you can delete textures before the rendering is complete? I would expect that it would be fine, but I've never actually tried it before.
Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
I've made a screenshot but I forgot to paste it 
Here it is

Here it is
your texture is 20 * 20 pixels right? GL_TEXTURE_2D requires your textures to have dimensions of powers of 2.
Hog Wrote:your texture is 20 * 20 pixels right? GL_TEXTURE_2D requires your textures to have dimensions of powers of 2.I've set dimensions to 32x32 but it works the same

I suppose that Texture2D rounds dimensions to be pow of 2 but I've never heard of such rules. It works with my size fine
Texture2D uses malloc when loading images and should use calloc instead to avoid getting garbarge in images less that 64 x64. You'll have to go in there and mod it yourself.
Does it have anything to do with "rainbow" effect?
According to your screenshots, yes it [might].
Cant see where a memory leak might be...
Each malloc call is followed by free call. Why is there a need to use calloc? Memory is allocated for one object not for an array
Each malloc call is followed by free call. Why is there a need to use calloc? Memory is allocated for one object not for an array
Using calloc has nothing to do with memory leaks. It has to do with the way Core Graphics fills in the buffer. If you're just using the string function of Texture2D you might be unaffected. If you're loading images though, just change them to calloc and save yourself the grief.
Sorry don't understand what should I do.Could you point me in the code?
Try this: In Texture2D, do a search and replace of malloc with calloc. Then when you build it'll say there are too few arguments to calloc. So highlight each line where the error occurs and add , 1 to the parameter list. So something that used to say:
data = malloc(height * width * 4);
Should now be:
data = calloc(height * width * 4, 1);
data = malloc(height * width * 4);
Should now be:
data = calloc(height * width * 4, 1);
The issue is that malloc gives you memory with some random junk in it and calloc makes sure that all of the memory is set to 0's before giving you the pointer.
When you draw the texture into that memory, it draws over the random garbage leaving you with the rainbow speckles. If the memory was set to 0's first it would have been drawn over white and would have looked normal.
When you draw the texture into that memory, it draws over the random garbage leaving you with the rainbow speckles. If the memory was set to 0's first it would have been drawn over white and would have looked normal.
Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Right. Apparently, Core Graphics overwrites everything in the buffer if over 64x64, but doesn't for buffers less than that, which is why calloc is needed to clear the buffer first.
Thanks for the tip but it didn't remove that "rainbow"
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Texture2d crash lander | ajrs84 | 0 | 2,241 |
Apr 1, 2012 08:54 AM Last Post: ajrs84 |
|
| Water effect | markhula | 9 | 6,878 |
May 10, 2011 12:03 AM Last Post: markhula |
|
| Problem using Texture2D sub-section | bendell | 0 | 2,083 |
Mar 20, 2010 02:06 AM Last Post: bendell |
|
| Create a texture2d with contents of other textures | godexsoft | 6 | 3,772 |
Nov 12, 2009 10:24 PM Last Post: godexsoft |
|
| Creating a water effect | iamflimflam1 | 0 | 2,192 |
Aug 4, 2009 06:46 AM Last Post: iamflimflam1 |
|

