OpenGLEAN
OpenGLEAN User Support
Home page | Introduction | Documentation | Files | Examples | Proposals | Authors | Links


OpenGLEAN Development
Summary | CVS | (discussion via home page) | (contact via home page) | (suggestion box) | License | Todo | Bugs

cursors.c File Reference

OpenGLEAN glutSetCursor() demo.

This is just a hum-drum program that shows the OpenGLEAN mouse cursors. There is one top-level window with two subwindows. Each window has the same menu for controlling the mouse cursor inside of the window. Each window may have a separate cursor. More...

Include dependency graph for cursors.c:


Detailed Description

OpenGLEAN glutSetCursor() demo.

This is just a hum-drum program that shows the OpenGLEAN mouse cursors. There is one top-level window with two subwindows. Each window has the same menu for controlling the mouse cursor inside of the window. Each window may have a separate cursor.

This demo program falls into the category of "test" and "shows how a feature works". It is not meant to make you say "ooh" and "ahh".

In late 2003, I saw a bug report in freeglut about the mouse cursors mostly not working. I looked at the code and saw that it didn't make much of an effort to provide mouse cursors. Both the WIN32 and UNIX_X11 branches were pretty vacant. I had another program lying around that was kind of a guinea-pig for my freeglut development, and added a menu to set the mouse cursor. Using that program and alternately compiling with freeglut and old GLUT, I was able to completely fix the freeglut X11 mouse cursors in 2003. The bug report remains open due to the WIN32 side being incomplete.

This program is essentially a recreation of that part of that program. It was never included with freeglut or OpenGLUT, though it is old enough to have been part of freeglut.

Author:
Copyright 2003, 2004, 2005, the OpenGLEAN Project.
#include <stdlib.h>
#include <GL/openglean.h>

#define MAX(a,b)    (((a) < (b)) ? (b) : (a))
#define NUMBEROF(x) ((sizeof (x)) / (sizeof (*x)))

struct cursor_name
{
    char *name;
    int  cursor;
};
struct cursor_name cursors [] =
{
    {"GLUT_CURSOR_RIGHT_ARROW", GLUT_CURSOR_RIGHT_ARROW},
    {"GLUT_CURSOR_LEFT_ARROW", GLUT_CURSOR_LEFT_ARROW},
    {"GLUT_CURSOR_INFO", GLUT_CURSOR_INFO},
    {"GLUT_CURSOR_DESTROY", GLUT_CURSOR_DESTROY},
    {"GLUT_CURSOR_HELP", GLUT_CURSOR_HELP},
    {"GLUT_CURSOR_CYCLE", GLUT_CURSOR_CYCLE},
    {"GLUT_CURSOR_SPRAY", GLUT_CURSOR_SPRAY},
    {"GLUT_CURSOR_WAIT", GLUT_CURSOR_WAIT},
    {"GLUT_CURSOR_TEXT", GLUT_CURSOR_TEXT},
    {"GLUT_CURSOR_CROSSHAIR", GLUT_CURSOR_CROSSHAIR},
    {"GLUT_CURSOR_UP_DOWN", GLUT_CURSOR_UP_DOWN},
    {"GLUT_CURSOR_LEFT_RIGHT", GLUT_CURSOR_LEFT_RIGHT},
    {"GLUT_CURSOR_TOP_SIDE", GLUT_CURSOR_TOP_SIDE},
    {"GLUT_CURSOR_BOTTOM_SIDE", GLUT_CURSOR_BOTTOM_SIDE},
    {"GLUT_CURSOR_LEFT_SIDE", GLUT_CURSOR_LEFT_SIDE},
    {"GLUT_CURSOR_RIGHT_SIDE", GLUT_CURSOR_RIGHT_SIDE},
    {"GLUT_CURSOR_TOP_LEFT_CORNER", GLUT_CURSOR_TOP_LEFT_CORNER},
    {"GLUT_CURSOR_TOP_RIGHT_CORNER", GLUT_CURSOR_TOP_RIGHT_CORNER},
    {"GLUT_CURSOR_BOTTOM_RIGHT_CORNER", GLUT_CURSOR_BOTTOM_RIGHT_CORNER},
    {"GLUT_CURSOR_BOTTOM_LEFT_CORNER", GLUT_CURSOR_BOTTOM_LEFT_CORNER},
    {"GLUT_CURSOR_FULL_CROSSHAIR", GLUT_CURSOR_FULL_CROSSHAIR},
    {"GLUT_CURSOR_NONE", GLUT_CURSOR_NONE},
    {"GLUT_CURSOR_INHERIT", GLUT_CURSOR_INHERIT},
};

int quit_value;


void cb_display1 (void)
{
    glClearColor (1, 0, 0, 0);
    glClear (GL_COLOR_BUFFER_BIT);
}
void cb_display2 (void)
{
    glClearColor (0, 1, 0, 0);
    glClear (GL_COLOR_BUFFER_BIT);
}
void cb_display3 (void)
{
    glClearColor (0, 0, 1, 0);
    glClear (GL_COLOR_BUFFER_BIT);
}

void cb_menu (const int choice)
{
    if (choice == quit_value)
        exit (0);
    glutSetCursor (choice);
}


int main (int argc, char **argv)
{
    unsigned int i;
    int menu;
    int main_window;

    for (i = 0; i < NUMBEROF (cursors); ++i)
        quit_value = MAX (quit_value, cursors [i].cursor + 1);

    glutInitWindowSize (550, 300);
    glutInit (&argc, argv);
    main_window = glutCreateWindow ("OpenGLEAN cursors");
    glutDisplayFunc (cb_display1);
    menu = glutCreateMenu (cb_menu);
    for (i = 0; i < NUMBEROF (cursors); ++i)
        glutAddMenuEntry (cursors [i].name, cursors [i].cursor);
    glutAddMenuEntry ("Quit", quit_value);
    glutAttachMenu (2);

    glutCreateSubWindow (main_window, 50, 50, 200, 200);
    glutDisplayFunc (cb_display2);

#ifdef OPENGLEAN // OpenGLEAN's menus are buggy; GLUT does not require this.
    menu = glutCreateMenu (cb_menu);
    for (i = 0; i < NUMBEROF (cursors); ++i)
        glutAddMenuEntry (cursors [i].name, cursors [i].cursor);
    glutAddMenuEntry ("Quit", quit_value);
#endif
    glutAttachMenu (2);

    glutCreateSubWindow (main_window, 300, 50, 200, 200);
    glutDisplayFunc (cb_display3);

#ifdef OPENGLEAN // OpenGLEAN's menus are buggy; GLUT does not require this.
    menu = glutCreateMenu (cb_menu);
    for (i = 0; i < NUMBEROF (cursors); ++i)
        glutAddMenuEntry (cursors [i].name, cursors [i].cursor);
    glutAddMenuEntry ("Quit", quit_value);
#endif
    glutAttachMenu (2);

    glutMainLoop ();

    return 0;
}




SourceForge.net Logo Supported in part by SourceForge.net.

Generated on Fri Sep 16 20:15:22 2005 for OpenGLEAN by doxygen 1.4.3
The OpenGLEAN project is hosted by olib.org and SourceForge.