Solved

how to draw ° using OpenGL

Posted on 2006-06-22
14
1,147 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I lock down a trademark? 11 76
Tetris download for windows 7 17 168
any RTS game state byte array size advice? 6 228
Recording what a camera sees for future playback. 5 40
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…
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.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

16 Experts available now in Live!

Get 1:1 Help Now