# billboarding

## Recommended Posts

pex22    139
hi, its me again i used glOrtho for billboarding but my text isn't billboarded when i move in 2D directions (up,down,west,east). it is billboarded only when i rotate the camera or move foreward/backward. this is my billboard function:
/* math.h */
#define BILLBOARD_BEGIN 0
#define BILLBOARD_MASK  1
#define BILLBOARD_IMAGE 2
#define BILLBOARD_END   3
void billboard(int level=-1);
static int bblevel;

/* math.cpp */
void billboard(int level)
{
if (level!=-1)
bblevel=level;
if (bblevel==1)
goto BBMASK;
else if (bblevel==2)
goto BBIMAGE;
else if (bblevel==3)
goto BBPERSPECTIVE;
else
bblevel=0;
// Set ortho mode
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0,0,glutGet(GLUT_WINDOW_WIDTH),glutGet(GLUT_WINDOW_HEIGHT),0,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
goto BBEND;
BBMASK:
// Draw mask
glDisable(GL_DEPTH_TEST);
glBlendFunc(GL_DST_COLOR,GL_ZERO);
glEnable(GL_BLEND);
goto BBEND;
BBIMAGE:
// Draw image
glBlendFunc(GL_ONE,GL_ONE);
goto BBEND;
BBPERSPECTIVE:
// Set perspective mode
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
BBEND:
bblevel++;
}


and in main():
	billboard(BILLBOARD_BEGIN);
billboard(BILLBOARD_MASK);
text.color(1.0,0.0,0.0);
text.pos(cam.getPosition().x,cam.getPosition().y);
text.print("pex");
billboard(BILLBOARD_IMAGE);
text.color(1.0,0.0,0.0);
text.pos(cam.getPosition().x,cam.getPosition().y);
text.print("pex");
billboard(BILLBOARD_END);


the text class uses bitmap fonts (glutBitmapCharacter) well, maybe billboard() doesn't need to be in math.h/cpp, but i dont know where to put it. anyway, thats not matter. what is the solution to my problem? thnx, pex. [Edited by - pex22 on October 21, 2004 1:58:08 PM]

#### Share this post

##### Share on other sites
pex22    139
anyone?
everybody uses it in games or testing features (fps text is billboarded)
so i tried to use glOrtho but its not fully billboarded
so what should i do? or its the glOrtho settings?..

pex.

#### Share this post

##### Share on other sites
zedzeek    529
billboarding is where u draw the an object and it faces the camera always in a 3d world, u keep the same projection matrix for both the billboards and the normal 3d stuff.
perhaps what u want to do is draw a HUD heads up display (when normally info is written on the screen eg fps, players score etc)
to do this draw the 3d scene first and then switch to a 2d projection matrix with glOrtho2D(..) and draw the text , the text will remain in the aame position on the screen

matrix mode PROJECTION
glPerspective(...)
matrixmode MODELVIEW
aim camera
..draw world

matrix mode PROJECTION
glOrtho2d()
matrixmode MODELVIEW
glLoadIdentity();
draw HUD

#### Share this post

##### Share on other sites
grekster    640
could you use [ source ] and [ /source ] around your code please :)

#### Share this post

##### Share on other sites
pex22    139
oh, so i should use glOrtho2D instead of glOrtho? ok, thanks!

@grekster, so thats the difference between [code] and [ source], i see. thanks!

#### Share this post

##### Share on other sites
pex22    139
gluOrtho2D is same as glOrtho where the last parameters are 0 and 1, exactly as what i did in my code.
any other solution to my problem?..

#### Share this post

##### Share on other sites
Ajare    174
As said, billboarding is rotating a 3d polygon so that it is facing the screen. 'fps text' is not billboarded, it is simply printed using Ortho mode. NeHe has a tutorial on printing text using Ortho mode.

I'm not sure exactly what you want. If you want a kind of signpost, then use standard 3d billboarding, and texturemap the text onto it.

#### Share this post

##### Share on other sites
Trienco    2555
Quote:
 Original post by pex22gluOrtho2D is same as glOrtho where the last parameters are 0 and 1, exactly as what i did in my code.any other solution to my problem?..

you seem to be missing, that ortho will NOT magically billboard everything you have. in fact the only difference is that things wont look smaller if they are far away (ok, very simplified).

if you just want text, then load the identity and dont even think about calling lookat after that or do any kind of camera setup

#### Share this post

##### Share on other sites
pex22    139
Quote:
 Original post by Triencoif you just want text, then load the identity and dont even think about calling lookat after that or do any kind of camera setup

oh i get it.
works thanks.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

## Sign in

Already have an account? Sign in here.

Sign In Now