Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-09-2010, 05:00 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 177
Default A little openGL help please ?

In order to support text in my game I wrote a class for handling textures that generates textures from images or text. It works fine when I generate a string texture upon program initialization but when a string texture is generated dynamically while in the game the texture comes out like pixel noise. You can sort of see the string but not really because you get all these random pixels of random colors all over the place where the texture is drawn.

Has anyone had this issue before or have a probable cause for this? What was causing it and how was it solved ?

I tried adding glFlush() calls after my GL code and CGContextFlush calls after my CG calls and it makes no difference.

Im using CG to draw the string to an image buffer than I then pass to openGL to generate a texture. It works very well when the string is static, but when it is generated as needed all I get is noise.
__________________
Tipper
DChat
Abel is offline   Reply With Quote
Old 02-09-2010, 05:26 PM   #2 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 177
Default

Problem solved. Turns out I was expecting malloc to not return junk. By clearing the memory allocated I got it to work flawlessly. It still doesn't explain why the simulator stops working with my collision detection when I do this, and yet it works perfectly on the device.
__________________
Tipper
DChat
Abel is offline   Reply With Quote
Old 02-09-2010, 06:31 PM   #3 (permalink)
Registered Member
 
Mr Jack's Avatar
 
Join Date: Nov 2009
Location: Coventry, UK
Posts: 283
Default

Quote:
Originally Posted by Abel View Post
Problem solved. Turns out I was expecting malloc to not return junk.
C is a language written to be efficient. If you might not require it to do something it won't. So malloc returns a chunk of memory; if you, for some reason, need it to be filled with zeros it's your responsibility to do so.

This applies to all the C parts of Objective C.
__________________


Visit Mr Jack Games for my blog and more about my games
Mr Jack is offline   Reply With Quote
Old 02-09-2010, 06:38 PM   #4 (permalink)
Pro. Game Developer
iPhone Dev SDK Supporter
 
Join Date: Feb 2009
Location: ¿La Islas Hermosas?
Posts: 1,420
Default

Quote:
Originally Posted by Mr Jack View Post
C is a language written to be efficient. If you might not require it to do something it won't. So malloc returns a chunk of memory; if you, for some reason, need it to be filled with zeros it's your responsibility to do so.

This applies to all the C parts of Objective C.
Adding: if you've found that you do indeed need it zero-filled, use calloc() instead of malloc(), as you may already know.
__________________
piña para la niña interactive
Kalimba is offline   Reply With Quote
Old 02-09-2010, 06:39 PM   #5 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 177
Default

thanks for your reply, ye I notice this now haha, I feel silly. On my first version of the texture class I wrote I had bzeroed the memory assuming something like this might happen but being as it worked flawlessly with so many textures upon loading I did not think twice about doing this in this class rewrite as it was working just fine when tested upon launch. I suppose the problem doesn't present itself at launch since the memory is pretty much cleared at that moment.
__________________
Tipper
DChat
Abel is offline   Reply With Quote
Old 02-09-2010, 07:52 PM   #6 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 96
Default

I prefer to rename my files to .mm and use new and delete. Seems much cleaner than malloc. I'm about to play with my texture class to generate digits 1-9 in a single texture so I can easily render numbers
mlfarrell is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Online Users: 74
4 members and 70 guests
dljeffery, Max, mlo, Rossco
Most users ever online was 779, 05-11-2009 at 09:55 AM.
» Stats
Members: 24,142
Threads: 38,919
Posts: 170,747
Top Poster: smasher (2,565)
Welcome to our newest member, p2digital
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:15 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0