gl::drawBillboard has no texture


#1

Hi,

Recently discovered the gl::drawBillboard feature and I have been trying to get it to work and have no idea why I can not get the texture to show on a billboard.
I can see the geometry, its just untextured.
I have made a simplest example below and if someone could give me heads up where I am going wrong I would appreciate it.

#include “cinder/app/App.h”
#include “cinder/app/RendererGl.h”
#include “cinder/gl/gl.h”

using namespace ci;
using namespace ci::app;
using namespace std;

class CinderProject1App : public App {
public:
void setup() override;
void update() override;
void draw() override;
private:
CameraPersp mCam;
gl::TextureRef bbTex;
};

void CinderProject1App::setup()
{
mCam.lookAt(vec3(3, 2, 4), vec3(0));

auto img2 = loadImage(loadAsset(“CARROT2.png”));
bbTex = gl::Texture::create(img2);
bbTex->bind();

gl::enableDepthWrite();
gl::enableDepthRead();
}

void CinderProject1App::update()
{
}

void CinderProject1App::draw()
{
gl::setMatrices(mCam);

gl::clear(Color(0.2f, 0.2f, 0.2f));

glm::vec3 bbup, bbright;
mCam.getBillboardVectors(&bbright, &bbup);

bbTex->bind();
gl::drawBillboard(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec2(1.0f, 1.0f), 0.0, bbright, bbup,cinder::Rectf(0.25f, 0.25f, 0.75f, 0.75f));
bbTex->unbind();

}

CINDER_APP( CinderProject1App, RendererGl )


#2

Hi,

you haven’t created a proper shader for it. With no shader bound, Cinder will bind a default shader which does not sample a texture. One exception is the gl::draw( texture ) call, which actually does create and bind a shader that samples the texture.

I haven’t tried your code, nor my solution, but my guess is that the following code change will fix your issue:

void CinderProject1App::draw()
{
    gl::setMatrices(mCam);
    gl::clear(Color(0.2f, 0.2f, 0.2f));

    glm::vec3 bbup, bbright;
    mCam.getBillboardVectors(&bbright, &bbup);

    auto shader = gl::getStockShader( gl::ShaderDef().texture() );
    shader->bind();

    bbTex->bind();
    gl::drawBillboard(vec3(0.0f), vec2(1.0f), 0.0, bbright, bbup, Rectf(0.25f, 0.25f, 0.75f, 0.75f));
    bbTex->unbind();
}

#3

Ahh your right of course. :tired_face: Knew it would be something obvious!
I did come to this from messing about with gl::draw(texture) as you mentioned too, but I should have known.
Thanks for the fast and helpful reply!

Got billboards! Next is figure out why they are upsidedown… :sunglasses:


#4

Hey, that’s great!

Try this:

auto fmt = gl::Texture2d::Format().loadTopDown();
auto image = loadImage( loadAsset( "carrot2.png" ) );
auto texture = gl::Texture2d::create( image, fmt );