Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

TheMightyDude

Displaying a 2d HUD onto a 3d display?

This topic is 5295 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all I am trying to display a 2D Image which is to be a HUD onto a 3D Display. But I have had no luck This is the code that I use to use, which creates a square object and displays the image on it. glPushMatrix(); // Load Image // glLoadIdentity(); glEnable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); glColor4ub(0,32, 0,100); glTranslatef (-0.1397f, -0.165f, -0.55f); glBindTexture(GL_TEXTURE_2D, HUD_texture[0]); glEnable(GL_BLEND); vuX=0.154f; vuY=(0.083f/2); glBegin(GL_QUADS); glNormal3f(0, 0, 1); glTexCoord2f(0, 0); glVertex2f(-vuX,-vuY); glTexCoord2f(1, 0); glVertex2f( vuX,-vuY); glTexCoord2f(1, 1); glVertex2f( vuX, vuY); glTexCoord2f(0, 1); glVertex2f(-vuX, vuY); glEnd(); glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); glPopMatrix(); But 3d objects that are moving towards you over write this image Does anyone know of any code that will display an image at the front of the screen as a 2D Image. Or if you know of a nehe Tutorial that does this can you let me know please. Thanks in advance Paul Kirby

Share this post


Link to post
Share on other sites
Advertisement
glMatrixMode( GL_MODELVIEW );
glLoadIdentity( );
glMatrixMode( GL_PROJECTION );
glLoadIdentity( );

glOrtho( 0, screen_width, screen_height, 0, -1, 1 );

glBindTexture( GL_TEXTURE_2D, tex);

glBegin( GL_QUADS );
glTexCoord2i( 0, 0 );
glVertex2i( hud_x, hud_y );
glTexCoord2i( 1, 0 );
glVertex2i( hud_x+hud_width, hud_y );
glTexCoord2i( 1, 1 );
glVertex2i( hud_x+hud_width, hud_y+hud_height );
glTexCoord2i( 0, 1 );
glVertex2i( hud_x, hud_y+hud_height );
glEnd( );

The important part of this code is the call to glOrtho, which basically sets up opengl to draw in 2d. In this case, using screen_width and screen_height set up the coordinate system to use pixels in a 1:1 manner with the screen. glOrtho can also do other stuff, so check the docs on it.

Edit: forgot glBindTexture. And now that I think about it, the texture coords in my pseudocode are probably vertically flipped.

[edited by - Melekor on May 21, 2004 11:13:59 PM]

Share this post


Link to post
Share on other sites
screenwidth/2 - hudwidth/2
screenwidth/2 + hudwidth/2

screenheight/2 - hudheight/2;
screenheight/2 + hudheight/2;

will center the hud on screen

Share this post


Link to post
Share on other sites
Thanks that displayed the image fine
Oh and yes I hade to swap it around to the following:
glOrtho(0,screen_width,0,screen_height,-1,1);
i.e. Bottom Left is (0,0)

The only problem now is I have tried to used the same sort of code in another function of my code but I cannot get it to display lines using the follwing coed
Sorry for the long code and I know it''s a bit messy

This if from my dll that I am creating...
Which draws a Bar Graph like in Winamp of the music/sounds being played.

It all was fine when I didnt use the new above code.

SPECTRUM_API void SPECTRUM_DrawVU2 (void)
{
int e_bnd=0,b0=0,BANDS=64,j=0,k=0; // 0 = 32 band and 1 = 64 band.
int red,green,blue,alpha=100;

float vuX,vuY;
long x;
float gap=7.915f; // for default
double equVal,y1=0;
float AV_peak_falloff = 0.8f; // Spead the Peaks fall.

int n;

// Screen Size.
int screen_width = 800;
int screen_height = 600;

// Set Image Size.
int hud_width = 406;
int hud_height = 112;

// Start pos of image.
int hud_x = 10;
int hud_y = 25;

glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);

// Select Our VU Meter Background Texture
glBindTexture(GL_TEXTURE_2D, SPEC_texture[0]);
glPushAttrib(GL_LIGHTING_BIT | GL_TRANSFORM_BIT);

glDisable(GL_LIGHTING);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0,screen_width,0,screen_height,-1,1); // Set Up An Ortho Screen
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
glEnable(GL_BLEND);
glBegin(GL_QUADS);
glTexCoord2i(0, 0); glVertex2i(hud_x, hud_y);
glTexCoord2i(1, 0 ); glVertex2i( hud_x+hud_width, hud_y );
glTexCoord2i( 1, 1 ); glVertex2i( hud_x+hud_width, hud_y+hud_height );
glTexCoord2i( 0, 1 ); glVertex2i( hud_x, hud_y+hud_height );
glEnd();
glDisable(GL_BLEND);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glPopAttrib();
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
// End of Background image code.

// Now for the VU Bars Section.
BASS_ChannelGetData(SPEC_chan,SPEC_FFT2048,BASS_DATA_FFT2048);
if (SPEC_band64) {e_bnd=1;BANDS=128;}
for (x=0;x {
float sum=0;
int sc,b1=int(pow(2,x*10.0/(BANDS-1)));
if (b1>1023) b1=1023;
if (b1<=b0) b1=b0+1; // make sure it uses at least 1 FFT bin
sc=10+b1-b0;
for (;b0 equVal=(sqrt(sum/log10(sc))*1.7*SPECHEIGHT)-4; // scale it

if(equVal<0.0f) equVal=0.0f;
if(equVal>100.0f) equVal=100.0f;

//Comment out the line below to display audio levels.
equVal=70; // Force the VU level to 70%

if(equVal>=70){red=255; green=0; blue=0;}
else if(equVal>=50){red=255; green=255; blue=0;}
else if(equVal>=20){red=5; green=255; blue=0;}
else{red=0; green=255; blue=0;}

if (SPEC_band64) glLineWidth(2.0f);
else glLineWidth(5.0f);
glEnable(GL_BLEND);
glBegin(GL_LINES);
SPEC_gl_Color4d(red, green, blue,255);
glVertex2d( x/ (pow(double(2.0f),double(gap+(1.0f*e_bnd)))), (equVal/200.0f)*0.09f);

if(equVal>=50)
{
SPEC_gl_Color4d(255, 255, 0,255);
glVertex2d( x/ (pow(double(2.0f),double(gap+(1.0f*e_bnd)))), ((equVal/1.25)/200.0f)*0.09f);
SPEC_gl_Color4d(255, 255, 0,255);
glVertex2d( x/ (pow(double(2.0f),double(gap+(1.0f*e_bnd)))), ((equVal/1.25)/200.0f)*0.09f);

SPEC_gl_Color4d(127, 255, 0,255);
glVertex2d( x/ (pow(double(2.0f),double(gap+(1.0f*e_bnd)))), ((equVal/1.5)/200.0f)*0.09f);

SPEC_gl_Color4d(127, 255, 0,255);
glVertex2d( x/ (pow(double(2.0f),double(gap+(1.0f*e_bnd)))), ((equVal/1.5)/200.0f)*0.09f);
}

SPEC_gl_Color4d (0, 255, 0,255);
glVertex2d( x/ (pow(double(2.0f),double(gap+(1.0f*e_bnd)))) , 0.0f);
glEnd();

if(equVal>=SPEC_equVal2[x]) SPEC_equVal2[x] = float(equVal);
if(SPEC_equVal2[x]>0.0f) SPEC_equVal2[x] = SPEC_equVal2[x] -AV_peak_falloff;
if(SPEC_equVal2[x]<0.0f) SPEC_equVal2[x]=0.0f;

glBegin(GL_LINES);
SPEC_gl_Color4d(255, 255, 255,255);
glVertex2d( x/ (pow(double(2.0f),double(gap+(1.0f*e_bnd)))),((SPEC_equVal2[x]+1.6f)/200.0f)*0.09f);
glVertex2d( x/ (pow(double(2.0f),double(gap+(1.0f*e_bnd)))),((SPEC_equVal2[x])/200.0f)*0.09f);
glEnd();
glDisable(GL_BLEND);
}
}

I hope this displays ok, and is enough info

Share this post


Link to post
Share on other sites
It''s ok I have figuared it out

I have done it the same way I had done the displaying of the 2d image with some slight code changing but the bars/lines seemed to be a bit dim/dark so I had to glDisable(GL_TEXTURE_2D); before I did the displaying of the bars/lines

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!