Solved

how to draw ° using OpenGL

Posted on 2006-06-22
14
1,171 Views
Last Modified: 2013-12-06
Hello experts,

Could someone tell me how to draw ° using OpenGL?
Thanks
Alison
0
Comment
Question by:lzha022
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 4
14 Comments
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 16972754
void drawCircle( float radius )
{
   glBegin( GL_LINE_LOOP ) ;
   
   int i;
   for ( i=0; i<360; i++ )
   {
      float angle = i * 0.01745329252 ;
      glVertex2f( cos(angle)*radius, sin(angle)*radius ) ;
   }
   
   glEnd() ;
}


E.g., of use:

drawCircle( 2.0f ) ;
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 16972769
And to specify the central position of the circle on the display:


void drawCircle( float x, float y, float radius )
{
   glBegin( GL_LINE_LOOP ) ;
   
   int i;
   for ( i=0; i<360; i++ )
   {
      float angle = i * 0.01745329252 ;
      glVertex2d( x+cos(angle)*radius, y+sin(angle)*radius ) ;
   }
   
   glEnd() ;
}


Example of use:

drawCircle( 100, 200, 2 ) ;
0
 

Author Comment

by:lzha022
ID: 16979974
Hi InteractiveMind,

Thanks for your reply.
I am sorry, i did not make it clear. I want to draw degree in symbol, not a circle. It is a special character, does OpenGL have some functions to draw special characters?

Thanks
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 25

Expert Comment

by:InteractiveMind
ID: 16980069
Are you able to draw ordinary text to the display?
0
 

Author Comment

by:lzha022
ID: 16980820
yes, i can draw text displayed on keyboard.
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 16982559
But special characters are not supported with this? :\
0
 
LVL 2

Expert Comment

by:davidnsc1
ID: 16987908
If your program is unicode, then pre-render character 0x00B0.  If your program isn't, then you can try using WideCharToMultiByte on character 0x00B0 to figure out the proper character code in the current codepage.  Either way you'll have to extend your font pre-rendering to either render through (bad) or jump to (better) that character.
0
 

Author Comment

by:lzha022
ID: 16987977
Hi Davidnsc1,
I find your comment is quite hard to understand - lots of new things to me.
I am programming in vs .net 2003.
Do you mean it is very complicately to print degree sign using openGL?
0
 
LVL 2

Expert Comment

by:davidnsc1
ID: 16988008
Ah, I'll take a step back then.  What method are you currently using to render text to the OpenGL window?
0
 

Author Comment

by:lzha022
ID: 16988073
I implemented a method like this to draw strings.
void drawBitmapFonts(char *string, float x, float y, void *font)
{
  if (string != (char *)NULL)
  {
    glRasterPos3f(x, y, 1.0);
    int len = (int) strlen(string);
    for (int i = 0; i < len; i++)
    {
      glutBitmapCharacter(font, string[i]);
    }
  }
}
0
 
LVL 2

Expert Comment

by:davidnsc1
ID: 16988187
Oh!  Wow, I was expecting the wgl and display lists method--I didn't realize you were using GLUT.
Try character 0xB0 (176).
0
 

Author Comment

by:lzha022
ID: 16988288
Sorry for the confusion. I just started to use OpenGL - so still not clear about it. I tried 176 in my code, but it does not show anything.
here is my code:
label = cimSprintf("%s  (%2.0f %c)", p->getGPName(),  theta*360/(2*PI), 176 );
drawBitmapFonts(label, startX, startY, GLUT_BITMAP_HELVETICA_18);
0
 
LVL 2

Accepted Solution

by:
davidnsc1 earned 100 total points
ID: 16988320
Well, I'm just taking a stab at this, but try putting a (unsigned char) before string[i] in your drawBitmapFonts procedure.  Since 176 is greater than 128, in a signed char the number will be negative.  If glutBitmapCharacter's second parameter is an int or something, then it'd stay negative and give you the wrong character.  So casting it to unsigned could hopefully fix it.
0
 

Author Comment

by:lzha022
ID: 16988434
Great!
It is working now.
Thank you very much.
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question