Game Development Community

Billboard Problems

by JohnT · in Torque Game Engine · 03/31/2006 (4:09 am) · 1 replies

Hoping someone can tell me what I'm doing wrong in the following code. All I am trying to do is place multiple billboards at various locations using different PNG images. For some reason that I have not been able to figure out, the image that is displayed ends up being various other images loaded in the level and not the ones that I set it to. Also, as I move my view around the image changes to other images none of which is mine.

I have verified that the image is loaded correctly into the handle and did not want to include that code since it would make the code snippet too long.

Thanks in advance for any suggestions.
John

// Enable Texturing.
glEnable ( GL_TEXTURE_2D );
glTexEnvi ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

MatrixF modelview;
dglGetModelview( &modelview );
modelview.transpose();

for(int i=0; i {
glBegin(GL_QUADS);
glBindTexture(GL_TEXTURE_2D, mpBillboard[i]->mpHandle.getGLName());

// Draw Billboard.
F32 width = 200;
Point3F points[4];
points[0] = Point3F(-width, 0.0, -width);
points[1] = Point3F(-width, 0.0, width);
points[2] = Point3F( width, 0.0, width);
points[3] = Point3F( width, 0.0, -width);

for( int j=0; j<4; j++ )
modelview.mulP( points[j] );

// Draw Top part of billboard.
glTexCoord2f (0,0);
glVertex3fv (points[0] + mpBillboard[i]->pt);
glTexCoord2f (1,0);
glVertex3fv (points[1] + mpBillboard[i]->pt);

glTexCoord2f (1,1);
glVertex3fv (points[2] + mpBillboard[i]->pt);
glTexCoord2f (0,1);
glVertex3fv (points[3] + mpBillboard[i]->pt);
glEnd();
}

// Restore rendering state.
glTexEnvi ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
glDisable ( GL_BLEND );
glDisable ( GL_TEXTURE_2D );

#1
04/03/2006 (4:00 am)
Figured it out. I thought I'd go ahead and document the fix in case anyone runs into this down the road.

The only change that I needed to make to the above code was to move the line:
glTexEnvi ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

to just below:
glBindTexture(GL_TEXTURE_2D, mpBillboard[i]->mpHandle.getGLName());

Once I did that, things started working perfectly!