Jump to content
  • Advertisement
Sign in to follow this  
fcoutel

Tooltip question

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

Hi, In my OGL scene I have some objects and I know their name. What I would like to do is some kind of Tooltip i.e draw a rectangle with the object's name when I hover on it with the mouse. Would someone have some example source code for doing this? Many thanks!

Share this post


Link to post
Share on other sites
Advertisement
Determining if you're hovering over the object is the trickiest part. You should be able to do it with "Picking", though. Check out nehe or the redbook - they both have examples of how to do this.

After you've done that, you can simply draw a quad with some text inside it above the object to show the tooltip.

Cheers,
--Brian

Share this post


Link to post
Share on other sites
Ok but I need to draw the rectangle in orthographic proj I think? Would you have an example on how to do this?

Thanks!

Share this post


Link to post
Share on other sites
just use glOrtho()

Note the part that says "typically the matrix mode is GL_PROJECTION", you probably already know that, but then again it probably didnt hurt to reiterate :-).

so to draw in orthographic mode you want something like:


glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, 640, 0, 480, -1, 1);
//this describes a matrix where the viewport covers a 640 x 480 rectangle
//where the upper left hand corner is the point <0,0>
//wheras glOrtho(0, 640, 480, 0, -1, 1);
//would describle a matrix where the lower left hand corner is the point <0,0>
//(note the -1, 1) this affects the depth buffer, i'll assume you know a bit about it
//this means that things will be drawn from z=-1 to z=1, but since you're drawing
//in 2d anyways chances are z will be 0


//Drawing Code

glPopMatrix();



hope that helps
-Dan

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!