Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 11-25-2011, 04:04 PM   #1 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,002
Duncan C has a spectacular aura about
Default OpenGL ES 2 and/or GLKit under iOS 5

Is anybody else out there developing for OpenGL ES 2 and/or GLKit, and having success?

I've got a fair amount of experience in OpenGL for the Mac, but I'm tackling my first project in OpenGL ES.

I'm using OpenGL ES 2.0, and it's driving me nuts.

The first problem is that none of the simple drawing commands that I'm used to work any more. Everything is do-it-yourself with shaders. Ok, I can get through that. It's just a (very steep) learning curve that I am having to climb.

The more serious problem I'm facing relates to setup and configuration.

I've got an app that's working quite well, doing mesh warping and rendering a texture onto a warped mesh. However, nothing but glClear appears on the screen when I run the app on my iPad. My other commands (either drawing my mesh using textures and GL_TRIANGLE_STRIPS) or simple line strips or even GL_LINES, don't appear at all.

Everything works perfectly on the simulator.

There must be something I'm doing wrong, but I'm darned if I can figure out what it is.

I've built test apps using both a subclass of UIVIew with a backing CAEAGLLayer, and the new GLKView. (My GLKView needs to be stand-alone, and not contained in a GLKViewController, since I need to draw 2 OpenGL Views, along with UIKit views, in a single view controller, and GLKViewController forces you to make the view controller's main view a GLKView.)

Both the GLKView approach and the custom UIView approach fail to draw anything but a glClear on my development iPad, and I am at a loss despite flogging at this problem full time for over a week.

I just went back and tried the GLKView approach again, and got a dirt simple "draw a blue square" app working with GLKView on the simulator, but it still won't draw on the device. Arghhhhh!!!!!!

This is an app I'm developing for a client, so I need to get this resolved. I logged a tech support "incident" on it with apple last Friday, only to find out that Apple was closed the entire week of Thanksgiving, and I expect them to take a number of days to get to me even after they reopen on Monday. I'm still slogging away to find the problem in the meantime.

Can anybody out there suggest things that I might be doing wrong? Is anybody willing to take a look at my test program and figure out what I'm doing wrong?
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 11-26-2011, 12:50 PM   #2 (permalink)
Registered Member
 
headkaze's Avatar
 
Join Date: Feb 2010
Posts: 359
headkaze is on a distinguished road
Default

Post your project and I'll take a look. I can't promise anything though as I am porting my own engine to ES 2.0 and having my fair share of problems. Anyway I may be able to help.
__________________
Headsoft | Jungool
headkaze is offline   Reply With Quote
Old 11-26-2011, 03:12 PM   #3 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,002
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by headkaze View Post
Post your project and I'll take a look. I can't promise anything though as I am porting my own engine to ES 2.0 and having my fair share of problems. Anyway I may be able to help.
Here's a link to the dirt-simple GLKView project from my public dropbox

http://dl.dropbox.com/u/19926891/GLKView%20test.zip

It's based on the design for my real project, so the shader has a uniform that lets me turn textured drawing on and off.

The sample project just draws a blue square against a red background. It works perfectly on the simulator, but not on the device. On the device (my iPad 1) only the glClear is visible.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 11-26-2011, 10:35 PM   #4 (permalink)
Registered Member
 
headkaze's Avatar
 
Join Date: Feb 2010
Posts: 359
headkaze is on a distinguished road
Default

I'm not getting what you describe.

I am getting a yellow square on a white background with a blue square inside on the iPad 5 simulator.

On the iPad 2 I get a yellow square on a white background.
Attached Images
File Type: jpg iPad5Sim.jpg (10.5 KB, 4 views)
File Type: jpg iPad2HW.jpg (5.3 KB, 4 views)
__________________
Headsoft | Jungool
headkaze is offline   Reply With Quote
Old 11-27-2011, 02:35 PM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,002
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by headkaze View Post
I'm not getting what you describe.

I am getting a yellow square on a white background with a blue square inside on the iPad 5 simulator.

On the iPad 2 I get a yellow square on a white background.
Same here.

The yellow square is the glClear, filling the entire GLKView view with yellow. The blue square, which only appears on the simulator, is drawing that's done using GL_LINE_STRIP commands.

As I said, only the glClear command actually does anything on the device. Drawing commands (like GL_LINE_STRIP) are not appearing on the device.

If it was working correctly, it would look the same on the simulator and the iPad.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 11-27-2011, 04:24 PM   #6 (permalink)
Registered Member
 
headkaze's Avatar
 
Join Date: Feb 2010
Posts: 359
headkaze is on a distinguished road
Default

You said the background was red not yellow.

Anyway if you change the near and far of your projection matrix the box will appear on hardware.

Code:
  GLKMatrix4 
    projection = GLKMatrix4MakeOrtho(0,
                                     1,
                                     1,
                                     0,
                                     0,
                                     1);
__________________
Headsoft | Jungool
headkaze is offline   Reply With Quote
Old 11-27-2011, 06:31 PM   #7 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,002
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by headkaze View Post
You said the background was red not yellow.

Anyway if you change the near and far of your projection matrix the box will appear on hardware.

Code:
  GLKMatrix4 
    projection = GLKMatrix4MakeOrtho(0,
                                     1,
                                     1,
                                     0,
                                     0,
                                     1);
OMG, thank you! Thank you thank you thank you! You have no idea how nuts this has been making me. I've been flailing at this problem (on a more complex app) for about 2 weeks now, with absolutely no progress.

Why do you suppose the projection matrix works on the sim, but not the device? And why does your projection matrix need to have a Z volume for 2D rendering?
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 11-27-2011, 07:27 PM   #8 (permalink)
Registered Member
 
headkaze's Avatar
 
Join Date: Feb 2010
Posts: 359
headkaze is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
OMG, thank you! Thank you thank you thank you! You have no idea how nuts this has been making me. I've been flailing at this problem (on a more complex app) for about 2 weeks now, with absolutely no progress.
Sometimes some fresh eyes can pick up things easily missed. Anyway I'm glad I could help out

Quote:
Originally Posted by Duncan C View Post
Why do you suppose the projection matrix works on the sim, but not the device? And why does your projection matrix need to have a Z volume for 2D rendering?
Yes you would think an ortho view wouldn't need any depth but I set my ortho depth range 0.0 - 1.0 so that is what I tried. I find that the depth buffers on devices can vary so that might be the reason it worked on the simulator and not on hardware. I'm not entirely sure though.
__________________
Headsoft | Jungool

Last edited by headkaze; 11-27-2011 at 07:43 PM.
headkaze is offline   Reply With Quote
Old 11-27-2011, 09:03 PM   #9 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,002
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by headkaze View Post
Sometimes some fresh eyes can pick up things easily missed. Anyway I'm glad I could help out



Yes you would think an ortho view wouldn't need any depth but I set my ortho depth range 0.0 - 1.0 so that is what I tried. I find that the depth buffers on devices can vary so that might be the reason it worked on the simulator and not on hardware. I'm not entirely sure though.
It's especially odd since I don't have depth buffers enabled at all.

I have another one for you.

How do you enable drawing with alpha? In my code, I either draw a texture where there's no blending of source color and fragment color, or I want to be able to draw into the color buffer using a source color with alpha. If the alpha is less than 1.0, I want the color to blend with the existing pixel color.

If you change the code in my sample project to set my source color uniform to a color with an alpha of .5, it still draws the primitives as fully opaque.

The line in question looks like this:

Code:
  glUniform4f(sourceColorUniform, 0.0, 0.0, 1.0, 1.0);
I changed it to

Code:
  glUniform4f(sourceColorUniform, 0.0, 0.0, 1.0, 0.5);
But it doesn't make any difference.

I pass the color in as a vec4 uniform (including an alpha) and use the color in my fragment shader.
When I'm not drawing with a texture, my fragment shader simply does this:

Code:
    gl_FragColor = DestinationColor;
From the reading I've done, the driver should blend the color I draw with the current color in the render buffer at that location.



I tried calling glEnable(GL_ALPHA) and/or glEnable(GL_BLEND) but both of those return an error, making me think those calls aren't supported in OpenGL 2.

I know quite a bit about the fixed rendering pipeline for Desktop OpenGL, but I'm more than a little lost in OpenGL 2.0.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 11-27-2011, 09:54 PM   #10 (permalink)
Registered Member
 
headkaze's Avatar
 
Join Date: Feb 2010
Posts: 359
headkaze is on a distinguished road
Default

You don't need depth buffers unless you're doing depth testing. An ortho matrix is just a way of setting up your projection matrix. You are still using what is essentially 3d hardware.

You can use GL_BLEND in ES 2.0. Try this

Code:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  
glUniform4f(sourceColorUniform, 0.0, 0.0, 1.0, 0.5);
__________________
Headsoft | Jungool
headkaze is offline   Reply With Quote
Old 11-27-2011, 10:07 PM   #11 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,002
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by headkaze View Post
You don't need depth buffers unless you're doing depth testing. An ortho matrix is just a way of setting up your projection matrix. You are still using what is essentially 3d hardware.

You can use GL_BLEND in ES 2.0. Try this

Code:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  
glUniform4f(sourceColorUniform, 0.0, 0.0, 1.0, 0.5);
That's what I'm doing, but no love. All my drawing is coming up fully opaque.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 11-28-2011, 01:05 AM   #12 (permalink)
Registered Member
 
headkaze's Avatar
 
Join Date: Feb 2010
Posts: 359
headkaze is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
That's what I'm doing, but no love. All my drawing is coming up fully opaque.
It works for me using your own example on both simulator and hardware.
__________________
Headsoft | Jungool
headkaze is offline   Reply With Quote
Old 11-28-2011, 12:56 PM   #13 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,002
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by headkaze View Post
It works for me using your own example on both simulator and hardware.
Curious. It works for me too on the example project, but not in my "real" project. Odd, that.

The real project creates an OpenGL view manually as a subclass of UIView with an EAGLLayer, and sets it up manually. Can you think of any configuration I might be missing that would enable alpha blending?

Edit: Never mind. Bonehead mistake on my part. There was an additional line to set the color (to an opaque value) that I missed. It was overriding my code to set a partly transparent color.

Once I set GL_BLEND then glBlendFunc, it works (I had those two lines in reversed order, which apparently DOESN'T work.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.

Last edited by Duncan C; 11-28-2011 at 01:09 PM.
Duncan C 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



» Advertisements
» Online Users: 414
13 members and 401 guests
bignoggins, djqbert, epaga, flamingliquid, jcdevelopments, leighec68, LunarMoon, markolo, mrtdmb, omagod, pinacate, revg, taylor202
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,645
Threads: 94,111
Posts: 402,861
Top Poster: BrianSlick (7,990)
Welcome to our newest member, leighec68
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:00 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0