Draw texture behind another


#1

Hi guys (it’s me again haha) :

I wanted to know if it was possible to draw a texture2d behind another, for the intant I tried to translate the texture in the z axis but my texture does not appear at all.

Thanks you.

MrFlavZz


#2

Hi,

if it’s just 2D drawing you’re after, disable the depth buffer (it’s disabled by default) and simply draw the 2 textures. You want to draw the front texture last.

Translating in the z-axis without a proper camera set up, will result in the texture being culled from the view frustum (it will be too close or too far away).

To setup your camera for 2D drawing with support for z axis ordering, try calling:

const auto width = getWindowWidth();
const auto height = getWindowHeight();
const auto fieldOfView = 40.0f; // in degrees
const auto nearPlane = 0.05f; // distance from camera, should be > 0
const auto farPlane = 100.0f; // distance from camera, should be > nearPlane
gl::setMatricesWindowPersp( width, height, fieldOfView, nearPlane, farPlane );

This will allow you to position your texture at a z depth between 0.05 and 100. Note, however, that the texture will be smaller if further away.

-Paul