Solved

how to draw ° using OpenGL

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

Could someone tell me how to draw ° using OpenGL?
Thanks
Alison
0
Comment
Question by:lzha022
  • 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now