glBegin(gl.GL_QUADS)

Started by
3 comments, last by Kalidor 18 years, 11 months ago
Is it bad practise to put the glBegin(gl.GL_QUADS) and glEnd in a loop? Eg building a block of buildings: for(){ begin quads draw quads to make building end quads } is that bad practice? should i hve the begin and end outside the loop? Thanks in advance, Nick :)
Advertisement
It is good practice to put glBegin() and glEnd() around as much as possible. But there are a lot of things you can't do between glBegin() and glEnd(), so sometimes you have to call glBegin and end for every little thing.

Things you *can* do between begin and end:
- Send vertex data (glVertex ...)
- Send normal data (glNormal ...)
- Send texture coordinate data (glTexCoord ...)
- Send colour data (glColor ...)

Things you might want to do between a begin and end, but unfortunately can't:
- Change texture (glBindTexture ...)
- Change the primitive type (glBegin(GL_QUADS to GL_TRIANGLE_STRIP for example))
- Change blender settings (glBlendFunc, glEnable(...

Basically, you can't do very much between begin and end - you can change hardly *any* of the state of the renderer.

I believe this is by design, so that the hardware can accelerate operations better, but it's also quite annoying.

If you're having problems wanting to render an object with several textures, you could use a single larger texture and chop up the texture coords instead. I don't know if this is a common technique though (I have yet to do anything interesting enough to require it)

Mark
Unless you're doing really low poly stuff (like a couple of HUD polys, etc.) or temp testing/development code, avoid glBegin/End as much as possible. Replace them with vertex arrays (or better).

Of course now you get the near-identical issue of how much you can fit in a single array and how much you do to avoid switching state (eg. texture packing).
Sorry im really new to OpenGL lol could u please explain what a vertex array is.

Cheers, Nick
Quote:Original post by NickyP101
Sorry im really new to OpenGL lol could u please explain what a vertex array is.

Cheers, Nick
Read the Red Book (there's a link to an older version in the forum faq).

This topic is closed to new replies.

Advertisement