Display all glut cursors

Alec Jacobson

September 23, 2013

weblog/

Here's a little program to see all of the glut cursors available on your implementation.

#include <GLUT/glut.h>
#include <OpenGL/OpenGL.h>
#include <iostream>
#include <map>
#include <cstring>

std::map<int,const char *> m;
std::map<int,const char *>::const_iterator c;
const char * GLUT_CURSOR_STR[23]
{
  "GLUT_CURSOR_RIGHT_ARROW",        
  "GLUT_CURSOR_LEFT_ARROW",       
  "GLUT_CURSOR_INFO", 
  "GLUT_CURSOR_DESTROY",    
  "GLUT_CURSOR_HELP", 
  "GLUT_CURSOR_CYCLE",  
  "GLUT_CURSOR_SPRAY",  
  "GLUT_CURSOR_WAIT", 
  "GLUT_CURSOR_TEXT", 
  "GLUT_CURSOR_CROSSHAIR",      
  "GLUT_CURSOR_UP_DOWN",    
  "GLUT_CURSOR_LEFT_RIGHT",       
  "GLUT_CURSOR_TOP_SIDE",     
  "GLUT_CURSOR_BOTTOM_SIDE",        
  "GLUT_CURSOR_LEFT_SIDE",      
  "GLUT_CURSOR_RIGHT_SIDE",       
  "GLUT_CURSOR_TOP_LEFT_CORNER",            
  "GLUT_CURSOR_TOP_RIGHT_CORNER",             
  "GLUT_CURSOR_BOTTOM_RIGHT_CORNER",                
  "GLUT_CURSOR_BOTTOM_LEFT_CORNER",               
  "GLUT_CURSOR_FULL_CROSSHAIR",           
  "GLUT_CURSOR_NONE", 
  "GLUT_CURSOR_INHERIT"
};

int width,height;
void reshape(int width,int height)
{
  ::width = width;
  ::height = height;
  glViewport(0,0,width,height);
}

void display()
{
  using namespace std;
  glClearColor(1,1,1,0);
  glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

  glMatrixMode( GL_PROJECTION ) ;
  glPushMatrix() ; // save
  glLoadIdentity();// and clear
  glMatrixMode( GL_MODELVIEW ) ;
  glPushMatrix() ;
  glLoadIdentity();
  gluOrtho2D(0,width,0,height);
  glDisable( GL_DEPTH_TEST ) ; // also disable the depth test so renders on top
  glTranslated(10,height/2,0);
  glScaled(.09,.09,.09);
  glLineWidth(2);

  //glRasterPos2f( 0,0 ) ; // center of screen. (-1,0) is center left.
  glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
  char buf[300];
  sprintf( buf,"%s", c->second ) ;
  const char * p = buf ;
  do glutStrokeCharacter( GLUT_STROKE_ROMAN, *p ); while( *(++p) ) ;
  glutSwapBuffers();
  glutPostRedisplay();
}


void key(unsigned char k, int, int)
{
  if(k == ' ')
  {
    if(++c == m.end())
    {
      c = m.begin();
    }
    glutSetCursor(c->first);
  }
}

int main(int argc, char * argv[])
{
  using namespace std;
  m[GLUT_CURSOR_RIGHT_ARROW] = "GLUT_CURSOR_RIGHT_ARROW";        
  m[GLUT_CURSOR_LEFT_ARROW] = "GLUT_CURSOR_LEFT_ARROW";       
  m[GLUT_CURSOR_INFO] = "GLUT_CURSOR_INFO"; 
  m[GLUT_CURSOR_DESTROY] = "GLUT_CURSOR_DESTROY";    
  m[GLUT_CURSOR_HELP] = "GLUT_CURSOR_HELP"; 
  m[GLUT_CURSOR_CYCLE] = "GLUT_CURSOR_CYCLE";  
  m[GLUT_CURSOR_SPRAY] = "GLUT_CURSOR_SPRAY";  
  m[GLUT_CURSOR_WAIT] = "GLUT_CURSOR_WAIT"; 
  m[GLUT_CURSOR_TEXT] = "GLUT_CURSOR_TEXT"; 
  m[GLUT_CURSOR_CROSSHAIR] = "GLUT_CURSOR_CROSSHAIR";      
  m[GLUT_CURSOR_UP_DOWN] = "GLUT_CURSOR_UP_DOWN";    
  m[GLUT_CURSOR_LEFT_RIGHT] = "GLUT_CURSOR_LEFT_RIGHT";       
  m[GLUT_CURSOR_TOP_SIDE] = "GLUT_CURSOR_TOP_SIDE";     
  m[GLUT_CURSOR_BOTTOM_SIDE] = "GLUT_CURSOR_BOTTOM_SIDE";        
  m[GLUT_CURSOR_LEFT_SIDE] = "GLUT_CURSOR_LEFT_SIDE";      
  m[GLUT_CURSOR_RIGHT_SIDE] = "GLUT_CURSOR_RIGHT_SIDE";       
  m[GLUT_CURSOR_TOP_LEFT_CORNER] = "GLUT_CURSOR_TOP_LEFT_CORNER";            
  m[GLUT_CURSOR_TOP_RIGHT_CORNER] = "GLUT_CURSOR_TOP_RIGHT_CORNER";             
  m[GLUT_CURSOR_BOTTOM_RIGHT_CORNER] = "GLUT_CURSOR_BOTTOM_RIGHT_CORNER";                
  m[GLUT_CURSOR_BOTTOM_LEFT_CORNER] = "GLUT_CURSOR_BOTTOM_LEFT_CORNER";               
  m[GLUT_CURSOR_FULL_CROSSHAIR] = "GLUT_CURSOR_FULL_CROSSHAIR";           
  m[GLUT_CURSOR_NONE] = "GLUT_CURSOR_NONE"; 
  m[GLUT_CURSOR_INHERIT] = "GLUT_CURSOR_INHERIT";
  c = m.begin();

  glutInit(&argc,argv);
  glutInitDisplayString( "rgba depth double samples>=8 ");
  glutInitWindowSize(300,70);
  glutCreateWindow("cursor");
  glutKeyboardFunc(key);
  glutReshapeFunc(reshape);
  glutDisplayFunc(display);
  glutMainLoop();
  return 0;
}

On my Mac OS X machine, the built-in apple implementation looks like this:

glut cursors mac

whereas freeglut using X11 looks like

freeglut cursors mac

Notable freeglut doesn't manage to make the cursor disappear with GLUT_CURSOR_NONE, but it does have a much better GLUT_CURSOR_DESTROY.