Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

OpenGL GLBegin() - GLEnd()

  • 22-09-2007 3:07pm
    #1
    Registered Users, Registered Users 2 Posts: 8,449 ✭✭✭


    Hey I'm dipping my toe into the openGL water and I have read that there is an overhead involved with using GLBegin and GLEnd so you are encouraged to do as much in between them as possible instead of calling them for each polygon etc...

    But how do you do model specific rotations without calling GLBegin and GLEnd for each model because you can't rotate anything once you're inside the begin-end block so all rotations have to be done before but then the rotations apply to everything inside the block. So this means you can't rotate more than one polygon independently in one begin-end block?


Comments

  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    I wouldn't worry too much about the overhead - as long as you're not caling begin/end for every triangle in a big scene, it won't be a problem.


  • Registered Users, Registered Users 2 Posts: 8,449 ✭✭✭Call Me Jimmy


    satchmo wrote:
    I wouldn't worry too much about the overhead - as long as you're not caling begin/end for every triangle in a big scene, it won't be a problem.

    I had an idea that it would be ok for small programs but I'm just wondering am I understanding correctly because it says to try and call it as few times as possible but from what I understand ye can't do more than one polygon (assuming the polygons need to be independently rotated) inside a begin-end block. Am I missing something?


  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    Well that is true alright, but in practice you don't need to specify an independent rotation for each polygon, as that would be impossible to manage and isn't really how you're meant to construct a scene.

    Instead, you specify the polygons for each model (be it a simple cube or a complex mesh) in object space - in other words, relative to that object's centre. Then you rotate & translate the entire model where you want it to go with the modelview matrix, so the model's polygons stay in the same place relative to each other, while changing in world space - ie., relative to the entire scene. So if the coordinate (0,0,0) is the centre of a cube in object space, that same point in world space might actually be at the coordinate (0,10,0) because you've translated the entire model up 10 units in Y relative to the centre of the entire world.

    This means that since the coordinates of each polygon in a model never change relative to each other, you can call glBegin(), list a whole bunch of vertices to make many polygons, and then call glEnd(). This way you only need to specify a transformation (ie translation, rotation and/or scale) for the entire model, and not per-polygon.

    This probably doesn't make a whole lot of sense right now (and I probably didn't explain it very well), but try reading up on coordinate spaces - here's a good place to start - and look at some simple code examples to see how it's done, like some of NeHe's early lessons.


  • Registered Users, Registered Users 2 Posts: 8,449 ✭✭✭Call Me Jimmy


    satchmo wrote:

    This means that since the coordinates of each polygon in a model never change relative to each other, you can call glBegin(), list a whole bunch of vertices to make many polygons, and then call glEnd(). This way you only need to specify a transformation (ie translation, rotation and/or scale) for the entire model, and not per-polygon.

    Thanks for explaining and I think I understand coordinate spaces but you say each polygon in a model never change relative to each other but what if they're it's an animated model. Say you have a bunch of cubes to represent a robot and each cube represents head torso limbs etc. then they move relative to each other and the arms rotate in independent of the torso, same applies to the legs etc.

    Each cube in said robot couldn't possibly be done without a fresh call to glbegin and glend right?


  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    Sorry when you said polygon I presumed you meant a triangle or quad. Yeah in that case each cube would need its own transformation matrix alright.

    Like I said, don't worry about how many times you call glBegin/glEnd. When the polycount of your scene gets higher you'll be using vertex buffers anyway :)


  • Advertisement
Advertisement