How to get cursor position visibl in opengl screen

Hii Friends
I am very new to opengl. Please help me out.
I am using opengl with c. I have done a program which Displays a picture & then i hav created 2 text boxs which asks for input from user. Now in this textbox how to make the cursor visible so tat the user can type the input & its visible on opengl screen with cursor position also…

For Getting user input, we use keyboard func. But now i want the cursor position also to be visible on opengl screen…How is it.

Help me out i am trying it out from past few days not getting it…

Check out these links:

Thanks i checked out But not exactly getting how to put this in the program…If you can please explain me with an example program of just displaying text which user enters from keyboard & this text is visible on the screen with cursor position also visible.

What aren’t you getting?

Try GLUT first. Google “glut text”, and you’ll come up with tutorials.

I know how to display text on opengl screen but i need to make my cursor position visible.
For displayinging text on screen i use this code as shown below


using keyboard func i get text from user with the help of ts code.
void get_text(char msg[], void (*call_with_text)())
{
  getting_text = 1;
 the_text = msg;
 text_entered = call_with_text;
}

void output1(int x, int y, char *string)
{
  int len, i;
  glRasterPos2f(x, y);
  len = (int) strlen(string);
  for (i = 0; i < len; i++)
  {
    glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, string[i]);
  }
}
then i use
 output1(935,678,ww1);

now this just display text on opengl screen…i want even cursor position to be visible when its asking for input from user on screen…how is tat

What about rendering “_”?

No tat rendering “_” also is also not visible…So only i am asking help if possible a sample code example…

Well, you know where you want the cursor to display. You can use GL_LINES and draw a line.

Ya using glLines i can display the line…but i want cursor position for my text what i enter…Help me out, a sample codeia given below of my program of how i am using keyboard function to get input & display it…Not full program a part of code i hav put…check out & tell if i can modify anyting to get cursor position also visible


static void clear_text(char msg[])

{

  msg[0]='\0';

}


static void get_text(char msg[], void (*call_with_text)())

{

  getting_text = 1;

 the_text = msg;

 text_entered = call_with_text;

}


static void stop_text(char msg[])

{

  getting_text = 0;

}


static void convert_int(char ww1[])

{

  int i1;

  i1 = atoi(ww1);

  printf("user text converted to integer w1=%d
", i1);

}


void textbox(int x1, int y1, int x2 ,int y2,int r,int g,int b)

{


glColor3f(r,g,b);

glBegin(GL_POLYGON);

glVertex2i(x1,y1);

glVertex2i(x2,y1);

glVertex2i(x2,y2);

glVertex2i(x1,y2);

glVertex2i(x1,y1);

glEnd();

glColor3f(0,0,0);

}

void output1(int x, int y, char *string)

{

  int len, i;

  glRasterPos2f(x, y);

  len = (int) strlen(string);

  for (i = 0; i < len; i++)

  {

    glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, string[i]);

  }

}
void display(void)

{

    GLfloat xsize, ysize;     /* Size of image */

    GLfloat xscale, yscale;   /* Scaling of image */

         glutSetWindow(win);

         glutShowWindow();



       a1=0;

       no_of_pts1=0;

       cheak=0;

       glutSetCursor(GLUT_CURSOR_LEFT_ARROW);



      // glClearColor(0.0, 0.0, 0.0, 1.0);

     glClear(GL_COLOR_BUFFER_BIT);

      if (BitmapInfo)

        {

        xsize = Width;

        ysize = BitmapInfo->bmiHeader.biHeight * xsize /

                BitmapInfo->bmiHeader.biWidth;

        if (ysize > Height)

            {

            ysize = Height;

            xsize = BitmapInfo->bmiHeader.biWidth * ysize /

                    BitmapInfo->bmiHeader.biHeight;

            }



        xscale  = xsize / BitmapInfo->bmiHeader.biWidth;

        yscale  = ysize / BitmapInfo->bmiHeader.biHeight;



        glRasterPos2f(0,0);

        glPixelZoom(xscale, yscale);



       glDrawPixels(BitmapInfo->bmiHeader.biWidth,  BitmapInfo->bmiHeader.biHeight,

                     GL_RGB, GL_UNSIGNED_BYTE, BitmapBits);
   textbox(905,660,1037,740,1,1,0);//magn
   output1(930,715,"Magnitude")  ;

 glBegin(GL_POLYGON);

    glColor3f(0.8, 0.8, 0.8);

    glVertex2f(915,670);

    glVertex2f(915,700);

    glVertex2f(965,700);

    glVertex2f(965,670);

    glEnd();

    glColor3f(0.0, 0.0, 0.0);

    output1(935,678,ww1);

    glLoadIdentity();
 glFinish();

    }

}

void cmouse(int but,int state,int x , int y)

{

char st2[4];

int y1;

y1=875-y;

//char ww1[3], ww2[3]; 

if(cheak==2)

cheak=0;

if(cheak==0)

{

//y1=850-y;



if(but==GLUT_LEFT_BUTTON)

{

if(x>893 && x<[b]1049[/b] )

{

if(y>441 && y<[b]448[/b])

{

a1=0;

no_of_pts1=0;

glutSetWindow(win);

glutShowWindow();

}

else

 if(y>61 && y<[b]85[/b] && x>945 && x<[b]1004[/b])

exit(0);

else



if(x>915 && x<[b]965[/b] && y>175 && y<205)

{

clear_text(ww1);

get_text(ww1,convert_int);

}

int w1;
w1 = atoi(ww1);

printf("w1=%d
",w1);

}
}

static int add_text(unsigned char key)

{

  char msg[] = "x";

  int len;

  if(!getting_text) return 0;

  if(key==8) /* backspace */

  {

    len = strlen(the_text);

    the_text[len-1] = '\0';

  }

  else if(key==13 || key==9)

  {

    getting_text = 0;

    text_entered(the_text);

  }

  else

  {

    msg[0] = key;

    strcat(the_text, msg);

  }

  glutPostRedisplay();

  return 1;

}



void keyboard(unsigned char key, int x, int y)

{

if(add_text(key)) return;



  switch (key)

  {

    case 'a':

      break;

    default :

      break;

  }

  glutPostRedisplay();

}


Help me out by modifying this functions

You didn’t state what the specific problem you are having is.

Also, you’ll get more feedback on this if you post your “specific” question on the Beginners forum.

i know for windows systems, tutorials are thier but for linux system not able to get how…anyways ok i wil post this question in beginners…thanks for your help…

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.