iDevGames Forums
Starting OpenGL ES - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Starting OpenGL ES (/thread-2518.html)

Pages: 1 2


Starting OpenGL ES - DylanE - Jul 19, 2008 04:03 PM

Does anyone know of any good tutorials or resources for OpenGL ES (particularly 1.1)? I'd like to learn it, and all I can find are tutorials for platforms like Windows Mobile and Symbian, and with lots of platform-specific code.


Starting OpenGL ES - kodex - Jul 19, 2008 05:36 PM

try http://developer.apple.com/iphone tons of examples on OpenGL ES there.


Starting OpenGL ES - DylanE - Jul 19, 2008 08:04 PM

I found their examples to lack useful explanation (maybe it's just me), but a friend suggested this (http://www.amazon.com/Mobile-3D-Graphics-Kaufmann-Computer/dp/0123737273) book. I went out and bought it, and it seems to do a pretty good job explaining things. If you have prior experience with graphics programming, you can skip a great deal of the beginning right up to the ES stuff, but it's all good material.

Kind of answered my own question, but figured I'd at least try to be helpful and throw you guys the link to the book.


Starting OpenGL ES - DylanE - Jul 21, 2008 08:00 PM

I'm trying to figure out how to detect collision in a game. The way I understand it, I need to write code myself to detect if objects are touching/intersecting, and OpenGL doesn't have support for this built in.

I've been throwing around ideas, and at this point I'm just looking for some confirmation that what I'm saying make sense (or for somebody to tell me a better way to do this).

My idea is to create a class to represent drawn objects. The class will contain information such as its position and bounds in a coordinate system (derived from screen size), and every time I draw a frame, I update the coords and whatnot of my class using knowledge of the animation timer and the magnitude of translations that have been made. After I've got this kind of tracking working, I can just check the bounds of these objects in the draw loop to see if they're intersecting and act accordingly.

I don't really expect anyone to give me a detailed lesson in collision programming or anything, but I'd like to know if I'm doing this right, so any feedback is appreciated.

Thanks Grin


Starting OpenGL ES - kodex - Jul 21, 2008 08:20 PM

That method can get very processor intensive if you have many many objects and are working in a 3d world.

In a 2d environment with only a couple dozen objects it may be very doable. Just keep in mind that your processor will need to preform a lot of additional math each frame to make sure nothing has collided.

Take a look at http://www.codeproject.com/KB/GDI-plus/PolygonCollision.aspx has some very simple (for collision detection at least) examples and pseudo code.


Starting OpenGL ES - DylanE - Jul 21, 2008 08:30 PM

Looks good, thanks a ton.


Starting OpenGL ES - JustinFic - Jul 22, 2008 12:10 AM

I'd say just use normal OpenGL tutorials (NeHe, etc) while keeping in mind the things you won't be able to use in ES, namely Immediate Mode. If you use NeHe make a point of skipping ahead to the Vertex Array tutorial, and implement that while you work through the first 10-20. After that, you can pretty much pick and choose your topics from NeHe based on what you need.

DylanE Wrote:My idea is to create a class to represent drawn objects. The class will contain information such as its position and bounds in a coordinate system (derived from screen size), and every time I draw a frame, I update the coords and whatnot of my class using knowledge of the animation timer and the magnitude of translations that have been made. After I've got this kind of tracking working, I can just check the bounds of these objects in the draw loop to see if they're intersecting and act accordingly.

The way I approached this is to separate an object's visual representation from its physical representation, but have both representations tied to just one point (or point + vector, for rotations.) That way I can mix + match representations, so if I have a bunch of objects on screen I can switch them all to using bounding circles/spheres, or use more accurate bounds if there's only a few objects.


Starting OpenGL ES - DylanE - Jul 22, 2008 01:36 PM

I had been ignoring NeHe with the assumption that it was useless without immediate mode, so I've been teaching myself based on the spec and the book above. Looking at the tutorials, it looks like they could be pretty useful. Thanks for the tip.

Referring to your collision technique: do you mean you would use the data from the visual representation for accuracy and the physical representation using bounding circles/spheres?


Starting OpenGL ES - JustinFic - Jul 22, 2008 03:06 PM

Yeah, just replace the NeHe immediate mode stuff with vertex arrays, and proceed as normal. There's some good stuff in there.

On collision, the stuff used for visual representation (3d models, sprites) is separate from the stuff used for physics and collision (bounding volumes.) So a sprite can use a bounding sphere, circle, or 3D axis-aligned bounding box, or I can switch the sprite out for a 3d model and keep the same physical representation. Essentially, it's one thing to the renderer, and something totally different to the physics system.


Starting OpenGL ES - TomorrowPlusX - Jul 23, 2008 08:26 AM

I noticed the Oolong Engine a while back on the Bullet Physics homepage. It's for the iPhone, and has builtin physics.

http://oolongengine.com/

Thought it might be useful!


Starting OpenGL ES - DylanE - Jul 23, 2008 03:25 PM

Even more useful stuff...

I'll take a look at Oolong, as it looks like it could save me a lot of trouble. Thanks for the tip.


Starting OpenGL ES - TomorrowPlusX - Jul 24, 2008 05:25 AM

I had no idea OpenGL ES doesn't support immediate mode! I suppose this is a natural evolution of GL, but what a surprise.

( That being said, the only place I still use immediate mode is in drawing my GUI, and a couple debug visualizations, like drawing AABBs, frustums, etc. All my real rendering is with VBOs ).

I'm buying an iPod touch one of these days, I'm looking forward to learning GL development on it.


Starting OpenGL ES - DylanE - Jul 24, 2008 07:38 PM

I'm relatively new to OpenGL and I'm having a really weird (maybe) problem drawing a pyramid. I can't figure out what I'm doing wrong after a couple hours googling around. Basically, I draw a pyramid and rotate it, but it looks as though I can see through it at times as it rotates. The relevant code is below. Any feedback would be appreciated, as I am totally lost on this one.

Code:
    const GLfloat pyramid[] = {
        -1.0f,-1.0f,1.0f,
        0.0f,1.0f,0.0f,
        1.0f,-1.0f,1.0f,
        
        1.0f,-1.0f,1.0f,
        0.0f,1.0f,0.0f,
        1.0f,-1.0f,-1.0f,
        
        1.0f,-1.0f,-1.0f,
        0.0f,1.0f,0.0f,
        -1.0f,-1.0f,-1.0f,
        
        -1.0f,-1.0f,-1.0f,
        0.0f,1.0f,0.0f,
        -1.0f,-1.0f,1.0f,
    };
    
    const GLubyte pyramidColors[] = {
        255, 0, 0, 255,
        0, 255, 0, 0,
        0, 0, 255, 0,
        
        255, 0, 0, 255,
        0, 0, 255, 0,
        0, 255, 0, 0,
        
        255, 0, 0, 255,
        0, 255, 0, 0,
        0, 0, 255, 0,
        
        255, 0, 0, 255,
        0, 0, 255, 0,
        0, 255, 0, 0,
    };

    [EAGLContext setCurrentContext:context];
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
    glViewport(0, 0, backingWidth, backingHeight);
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrthof(-5.0f, 5.0f, -7.5f, 7.5f, -10.0f, 10.0f);
    glMatrixMode(GL_MODELVIEW);    
    glLoadIdentity();
    
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    
    glRotatef(rtri, 0.0f, 1.0f, 0.0f);
    
    glVertexPointer(3, GL_FLOAT, 0, pyramid);
    glColorPointer(4, GL_UNSIGNED_BYTE, 0, pyramidColors);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 9);
    
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
    [context presentRenderbuffer:GL_RENDERBUFFER_OES];
    
    rtri+=1.0f;



Starting OpenGL ES - kodex - Jul 24, 2008 07:49 PM

Dylan do you happen to have a screen shot of what you mean by "can see through it" it can be any number of issues and a picture says a 1000 words =).


Starting OpenGL ES - DylanE - Jul 24, 2008 08:03 PM

Yes, this is rotated 45 degrees around the X-axis to make the problem more visible. Images of the triangle in various positions as it rotates.

[Image: 2.png]
[Image: 1.png]
[Image: 3.png]

EDIT: Note, there is not supposed to be a bottom on the triangle