Jump to content
  • Advertisement
Sign in to follow this  
BangorRipper

icons and text on screen

This topic is 5088 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

if i have my screen with my models on and they move and do their own thing and so on. can i place text and images on top as if it was a 2d screen or do i have to place in 3d space as with everything else. what i'm trying to do is display stuff such as high score and number of lives left and so forth, what would be the best way to approach this and is there source code out there that has such things, icons ofr lives left maybe and so on. thanks everyone

Share this post


Link to post
Share on other sites
Advertisement
There is a simple trick. First do all your drawings (models, background and so on) and in the end, load the idenitity matrix and translate a litte 'into the screen', like in the first tutorials of NeHe.

For example:

void RenderGameScene ()
{
//here do all your drawing and translations

//now everything is rendered, load identity matrix
glLoadIdentity();
//disable depth testing, as you always want to display your HUD
glDisable(GL_DEPTH_TEST);
//move 'into' the screen
glTranslatef(0.0f,0.0f,-10.0f); //depends on the size of the things you want to draw

//now draw your images and your text
//...

//re-enable depth testing
glEnable(GL_DEPTH_TEST);

//swap buffers if you use double buffering
//...
};



Hope that helps.

Share this post


Link to post
Share on other sites
Try using ortho mode.
First draw all your 3D stuff, then setup your ortho screen;
use something like this:

void CreateOrthoScreen()
{
glDisable(GL_DEPTH_TEST); // Disables Depth Testing
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glPushMatrix(); // Store The Projection Matrix
glLoadIdentity();
glOrtho(0,640,0,480,-1,1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
}


This creates a screen which has its origin in the bottom left corner while the coordinates of the top right one are (640,480).
Now you can draw whatever you want (as long as it is 2D) and it will stay on top of everything else you have previously drawn.
Once you're done with your HUD you can switch back to "normal" mode:

void DestroyOrthoScreen()
{
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glEnable(GL_DEPTH_TEST);
}


This is how NeHe does it in one of his tutorials, I've just copied the code here. Perhaps some of the function called are useless or wrong. If so, let me know, so that I can improve my code, too.

Share this post


Link to post
Share on other sites
cheers for the replies, will probably try suing ortho mode.
is there free source code out there though for games that have high scores etc displayed on the screen, so i have something to refer to
thanks

Share this post


Link to post
Share on other sites
i realize that i can only draw 2d things when i use the ortho view but are there ways that i can make the text, scores and so on look impressive without it being 3d??

Share this post


Link to post
Share on other sites
Sure there are. Use texture mapped fonts for scores etc, looks very impressive. Good textures go a long way in making things look good. Also its very much possible to draw 3d models/3d stuffs in ortho view, its just not perspective correct. Its 1:1 ratio.

Share this post


Link to post
Share on other sites
texture mapped fonts are in lesson 15 of nehe right? unfortunately i'm coding in lwjgl and nobody has been able to convert the lesson into lwjgl. can lesson 17 be useful at all as that has been converted, sorry to drag on about the bloody fonts, i really appreciate the replies though, thanks

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

Lazork357 is correct about weaving in and out of the projection matrix from glu perspective to ortho, which is better suited for 2d text and bitmaps, ect.


For a 2d bitmap for a radar or something similar, try:

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f );
glMatrixMode( GL_MODELVIEW );
glBindTexture( GL_TEXTURE_2D, radarIDTexture );
glEnable( GL_TEXTURE_2D ); //enable your bitmaps texture
glDisable( GL_LIGHTING ); // disable lighting
glDisable( GL_DEPTH_TEST ); // disable depth testing

// White is a great color for material to texture
glColor3f( 1.0, 1.0, 1.0 );

// draw a quad to texture with
glBegin( GL_QUADS );
glTexCoord2f( 0.0, 0.0 );
glVertex2f( 0.0, 0.0 );
glTexCoord2f( 1.0, 0.0 );
glVertex2f( 0.3, 0.0 );
glTexCoord2f( 1.0, 1.0 );
glVertex2f( 0.3, 0.2 );
glTexCoord2f( 0.0, 1.0 );
glVertex2f( 0.0, 0.2 );
glEnd( );

Then.....destroy the ortho projection similar to lazork357' s approach
and disable glBlend


Also, in your init() function set up for blending :
glEnable(GL_BLEND);

// give blending translucensy to your bitmaps by calling this function
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);





Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!