Advertisement Jump to content
Sign in to follow this  


This topic is 5003 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 :)

Share this post

Link to post
Share on other sites
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)


Share this post

Link to post
Share on other sites
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).

Share this post

Link to post
Share on other sites
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).

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!