Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

OpenGL ES on the iPhone

2456

Replies

  • spideyleaderspideyleader Posts: 2
    edited May 2009
    are there books for openGL es for the iphone if so which are the best ones to read?
  • KMcNamaraKMcNamara Posts: 8
    edited May 2009
    I am wondering the same :cool:
  • mauriceatronmauriceatron Posts: 29 @
    edited May 2009
    I've looked but there's nothing iPhone specific but you don't really need it to be iPhone specific. The only parts which are iPhone unique with OpenGL ES is the screen size, user interaction, and setting up of your rendering. Everything else is standard across all platforms.

    So any OpenGL ES book should apply to the iPhone. Apple's template takes care of most of the iPhone specific stuff which the book won't cover.

    The other things such as touches, accel etc are covered on this site and others.
  • mauriceatronmauriceatron Posts: 29 @
    edited May 2009
    Guys,

    No new tutorial this past week, I've been out of action with the flu and right now trying to catch up on everything with work etc.

    I'll try and find some time this week to get back to putting one up in time for the weekend.

    Cheers
    Simon
  • mauriceatronmauriceatron Posts: 29 @
    edited May 2009
    smasher wrote: »
    If you enabled textures, they'll stay enabled until you turn them off again. If you want to draw your triangle with no texture, call glDisable(GL_TEXTURE_2D) before you draw it.

    Yeah, I really should go back to that tutorial and fix a few things in that. I get so much email from people who are taking that tutorial in particular way, way, way, way beyond what that tutorial was designed for :eek:

    Never mind, at least it's being used.
  • mauriceatronmauriceatron Posts: 29 @
    edited May 2009
    Just a quick note to all of the new tutorial out. Sorry for the delay (damn swine flu :D ), and of course the associated

    bumpity, bumpity, bumpity, bump, bump, bump, bump.... :p
  • KMcNamaraKMcNamara Posts: 8
    edited May 2009
    Hey simon,

    Thanks for posting the touch tutorial...I'm having some problems at the beginning though where I'm trying to set the app to open in landscape mode. When I click the + sign to add a new key to my Info.plist, the option "Initial Interface Orientation" is not there. Any idea why?

    Thanks!
  • mauriceatronmauriceatron Posts: 29 @
    edited May 2009
    KMcNamara wrote: »
    Hey simon,

    Thanks for posting the touch tutorial...I'm having some problems at the beginning though where I'm trying to set the app to open in landscape mode. When I click the + sign to add a new key to my Info.plist, the option "Initial Interface Orientation" is not there. Any idea why?

    Thanks!

    I think it's because I'm using the latest and greatest version of Xcode (v3.1.3 at the moment which is marked as "Pre-release") and have OS 3 installed as well. I thought I a general upgrade had made editing plists easier but I guess not.

    Anyway, the way to fix this is to edit the same plist file and add the following:

      < key >UIInterfaceOrientation <  /key >
       < string >UIInterfaceOrientationLandscapeRight < /string >
    

    That will get you going. Note skip the spaces around the "<"'s above. Even using the CODE tag, for some reasong the key and value tags were not being displayed.

    hooroo
    Simon
  • KMcNamaraKMcNamara Posts: 8
    edited May 2009
    Awesome, and what should we put to disable the status bar?

    Thanks!
  • mauriceatronmauriceatron Posts: 29 @
    edited May 2009
    From memory, it's
    < key >UIStatusBarHidden< /key > < true />
    

    Otherwise in applicationDidFinishLaunching it's:
    [app setStatusBarHidden:YES animated:NO];
    

    That one I can remember for sure.

    Hope that fixes it.

    Simon
  • KMcNamaraKMcNamara Posts: 8
    edited May 2009
    You're the man :)
  • SteffanSteffan Posts: 3
    edited June 2009
    Thanks for writing these tutorials! They've been my first ever introduction to Open GL ES.

    In the last tutorial, how are these equations used for drawing a circle? I understand that sin = O/A and cos = A/H.

    newX = eyeX + radius * cos(TURN_SPEED)*deltaX -
    sin(TURN_SPEED)*deltaZ

    newZ = eyeZ + radius * sin(TURN_SPEED)* deltaX +
    cos(TURN_SPEED)*deltaZ
  • mauriceatronmauriceatron Posts: 29 @
    edited June 2009
    Steffan wrote: »
    Thanks for writing these tutorials! They've been my first ever introduction to Open GL ES.

    In the last tutorial, how are these equations used for drawing a circle? I understand that sin = O/A and cos = A/H.

    newX = eyeX + radius * cos(TURN_SPEED)*deltaX -
    sin(TURN_SPEED)*deltaZ

    newZ = eyeZ + radius * sin(TURN_SPEED)* deltaX +
    cos(TURN_SPEED)*deltaZ

    Hi Steffan,

    Yes, I tried to sneak that one past everyone... :p

    Im writing a follow up to that at the moment and will have that posted later on today to explain everything in more detail, as well as covering some other things.

    Hooroo
    Simon
  • antilantilantilantil Posts: 35
    edited June 2009
    Hi
    Thanx for writing these useful tutorials on openGl Es .
    Actually i want to know how to detect collision between two moving objects.
    Iam new to openGl. Plz provide help regading this
  • gravitygravity Posts: 21
    edited June 2009
    Maurice, - Thanks a lot for the excellent tutorials! If I ever make it big with an app, I'll be sure to donate for your dedication!

    For tutorial 8 (labeled 7), I noticed what I think is an error. You say the normal vector is perpendicular to the plane which the vertices make up:

    normalvector.png

    Shouldn't the normal vector point in the opposite direction here? The vertices are going in a clockwise direction, 0 -> 1 -> 2 and by the right-hand rule, the normal should be opposite.
  • mauriceatronmauriceatron Posts: 29 @
    edited June 2009
    gravity wrote: »
    Maurice, - Thanks a lot for the excellent tutorials! If I ever make it big with an app, I'll be sure to donate for your dedication!

    For tutorial 8 (labeled 7), I noticed what I think is an error. You say the normal vector is perpendicular to the plane which the vertices make up:

    Shouldn't the normal vector point in the opposite direction here? The vertices are going in a clockwise direction, 0 -> 1 -> 2 and by the right-hand rule, the normal should be opposite.

    Hi gravity,

    Perhaps, don't really remember what I was trying to achieve there as that diagram is a bit pointless except that it shows that the normal is perpendicular to a primitive's face. Also, that's a surface normal.

    Nah, that section isn't my best work (not that I have any particularly good work). I'll re-write that bit.

    Oh, and to answer your question, the normal is the cross product of two of the polygon's edges. That's what gives you the direction, not the right hand rule.

    Simon
  • gravitygravity Posts: 21
    edited June 2009
    Hi gravity,

    Perhaps, don't really remember what I was trying to achieve there as that diagram is a bit pointless except that it shows that the normal is perpendicular to a primitive's face. Also, that's a surface normal.

    Nah, that section isn't my best work (not that I have any particularly good work). I'll re-write that bit.

    Oh, and to answer your question, the normal is the dot product of two of the polygon's edges. That's what gives you the direction, not the right hand rule.

    Simon

    Well, I thought it was done quite well- all of your tutorials are succinct, but clear, which makes it easy to tackle one subject at a time. Especially when you bring in screenshots for when you pass differ GL_* parameters in as arguments.

    The dot product actually does not return a vector, rather a scalar (which is just a number without a direction). Rather the cross product would return a direction, and using the cross product on any two sides of the polygon in order (going in a loop) will follow the right hand rule.

    If somebody is reading this and doesn't know what the right hand rule is, here is a quick definition. If you were to curl your four fingers in the direction that the vertices are loaded, the normal would be in the direction of your upright thumb. It's easier to show visually, here is a quick youtube video showing this, it's the magnetic field induced by an electric current, but don't let that confuse you, just imagine the red circles as the shapes being drawn and the arrows represent the vertices, and they are pointing in the direction that they are created in your array. The blue arrow coming out orthogonal (perpendicular in 3d) from your surface is the normal.

    You load the vertices in anti-clockwise direction if you were looking down upon the surface of the polygon, which defines the normal as going outwards. The right-hand rule gives you the normal, which is also the axis that glRotate() calls will rotate around (in the same anti-clockwise direction). As well, when you drop a texture onto it, it faces normal side up (or so I've been led to believe).
  • mauriceatronmauriceatron Posts: 29 @
    edited June 2009
    Yes, correct: it is a cross product, not the dot product to calculate the normal. :confused:

    I rushed that last post so I should really explain that I do not use the right hand grip rule to work out the surface normal. Before OpenGL became "the standard", it was common to use clockwise vertex order to achieve normal calculation for backface removal. X-Sharp, the first 3D library I ever worked with, followed clockwise sequence which the right hand grip rule doesn't apply.

    For that reason, I've never relied on the right hand rule. I used the calculated normal. That's not because I'm more hardcore than you, I'm just old and was around when we used the clockwise vertex sequence, so I learned a different way. That's all.

    Like I said, I need to go back and fix that section. It's pretty scrappy and I clearly wasn't thinking when I did that drawing because I just "labelled" the 3 points rather than think about what I was trying to say.

    Cheers
    Simon
  • jimjim Posts: 2
    edited June 2009
    Simon,

    Thank you so much for the tutorials! They are very well done and extremely useful. I have only been working with OpenGL ES for a week now and they have helped me a great deal. I look forward to many more!

    To anyone who may be interested,

    I have spent quite a bit of time over this last week trying to get an object to rotate around it's origin with touch input from the user. Countless Google searches turned up page after page of "lecture notes" on angle/axis, quaternions, and rotation matrices, but nothing to tie it all together -- at least for me. It had been quite a few years since I had to deal with those concepts, and it was pretty rough trying to cram all of that back into my head. But, as I read more, and derived quite a bit on my own, I began to understand most of it. I was almost done implementing my own algorithms (though they had a few issues) when I revisited an example I had seen previously. The difference this time was that I actually understood what it was doing. :D

    So, using Simon's OpenGL ES 10 Tutorial as a starting point, and the code I found at opengl.org, I was able to get the cube to rotate around it's origin the way I wanted. You can download the source files I used from my web site (BizarreSoftware.com) and use them with the tutorial #10 from Simon's site.

    Please let me know if there is a better way to do the rotations. It looks like it's working, but I know things are not always as they seem.

    Jim
  • kingbombskingbombs Posts: 112
    edited June 2009
    Hey,

    The tutorials are awesome!
    I don't know if you are able to explain a few things or help me with my coding problems to do with 2D textures
    I have 2 threads ( both quite similar, although top one is more understandable i think)

    http://www.iphonedevsdk.com/forum/iphone-sdk-development/21430-texture-question.html

    http://www.iphonedevsdk.com/forum/iphone-sdk-game-development/21415-texture-problem-opengl-es.html

    If you can help me at all with anything i mention on either of those two threads, that would be greatly appreciated! :D
  • mauriceatronmauriceatron Posts: 29 @
    edited June 2009
    kingbombs wrote: »
    Hey,

    The tutorials are awesome!
    I don't know if you are able to explain a few things or help me with my coding problems to do with 2D textures
    I have 2 threads ( both quite similar, although top one is more understandable i think)

    Yes, top one understandable, the bottom one, not so. Just replied to your top thread.

    Simon
  • mauriceatronmauriceatron Posts: 29 @
    edited June 2009
    jim wrote: »
    Please let me know if there is a better way to do the rotations. It looks like it's working, but I know things are not always as they seem.

    Jim

    Hi Jim,

    Sounds like you had an long search. I thought there would have been something out there on that. I'll have a quick look over your code later this week and see if there's an easier way.

    Let you know.

    Simon
  • kingbombskingbombs Posts: 112
    edited June 2009
    Hey,

    so i have been searching quite a while for my problem, and if you are stuck on thinking of new tutorials, unless someone messages me a tutorial that is useful it might be a good tutorial to do:
    http://www.iphonedevsdk.com/forum/iphone-sdk-development/21870-writing-opengl-es.html#post98040

    Bassicly creating text in OpenGL ES that doesn't worry about code to change the font selected and just uses the standard font used.
  • kingbombskingbombs Posts: 112
    edited July 2009
    Hey,
    I have a question regarding your code for loading textures.
    - (void)loadTexture:(NSString *)name intoLocation:(GLuint)location {....}
    this is the method im refering to
        CGContextRef textureContext = CGBitmapContextCreate(textureData,	texWidth, texHeight, 8, texWidth * 4, CGImageGetColorSpace(textureImage),
    kCGImageAlphaPremultipliedLast);
    
    	// This is code added
    	CGContextClearRect(textureContext, CGRectMake(0, 0, (float)texWidth, (float)texHeight));
    
    	CGContextDrawImage(textureContext, CGRectMake(0.0, 0.0, (float)texWidth, (float)texHeight), textureImage);
    	CGContextRelease(textureContext);
    

    I had noticed that if i applied a block image to the texture, then apply an image thats not square, then around the outside of the last image the block texture would appear.
    I used that line to stop the last texture being drawn behind the current one. (this works and fixes it)

    But i noticed behind the image thats not a square it appears black. (for example a leg image takes up apart of the square and the rest is black around it (as a texture))
    I was wondering how i could get the outside part of the texture transparent, so only the leg image would be applied and around it would be transparent. (so if i had a texture having two legs that doesnt move you could see between its legs)

    (sorry if i made no sense),
    Is there also a reason why you haven't used that line of code? Or am i being an idiot for using that and should be using something else?
  • atomriotatomriot Posts: 8
    edited July 2009
    first off, great tutorials! i have not ever ventured into open gl of any flavor and these were very descriptive. i couldn't help but get lost playing while reading through your tutorials.

    i do have a question though regarding the click handling. you show how to capture the clicks and test the area to see if its within the square, is this the only way to do this?

    my real question is if i have 4 or 5 or more button areas (squares or other gl drawn shapes), do i just have to test to see where the click was in a bunch of ifs? or can you assign some sort of actual type to those squares and have those square inherit the touch events and act like a normal button?

    thanks for any guidance.
Sign In or Register to comment.