Solved

how to draw ° using OpenGL

Posted on 2006-06-22
14
1,149 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How many Python RTS servers on one host? 1 299
Trigonometry for game star field help 1 119
scoresAverage challenge 8 105
count8 challlenge 13 143
Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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