0

Currently, I have GL_DEPTH_TEST enabled and use it for textures. However, I'd like to draw a untextured rectangle with a certain depth/z value.

glDisable(GL_TEXTURE_2D);
glColor3f(colour.x, colour.y, colour.z);
glRects((short) rect.x, (short) rect.y, (short) rect.z, (short) rect.w);
glEnable(GL_TEXTURE_2D);

The code above draws the square. How do I set a Z or depth value for the square so that depth testing works with it?

1 Answers1

0

The glRect family of functions always draw with z implicitely at 0. So you have two options:

  1. Set up same transformation which puts the z=0 plane to where you like it.
  2. Don't use glRect at all and just draw a rectangle using 4 vertices at the z coordinate of your liking.

You should be aware that every line in the code you pasted is relying on deprecated OpenGL functionality and glRect itself is a rather obscure function even for deprecated code.

derhass
  • 43,833
  • 2
  • 57
  • 78
  • How would one go about drawing a rectangle the _best_ way? (I am currently using VBOs for textures.) – user5204762 Aug 08 '15 at 17:23
  • VBOs are not for textures. They are for vertex data, as the _V_ in VBO explicitely states. I really don't know what you mean by that. But you should be using VBOs for any geometry data in the GL, as this is the only non-deprecated path to specify vertex attributes. – derhass Aug 08 '15 at 18:21
  • Yeah, one VBO for destination position and one for texture position in the sprite sheet. Thanks for the answer! – user5204762 Aug 08 '15 at 19:18