hi.
can someone try this on their windows box? i’m running xp with integrated graphics in the intel 810 chipset. the chipset documentation says it supports openGL so i’m not sure what the problem is.
thanks
/* The GLUT include files*/
#include <GL/glut.h>
#include <stdio.h>
/* Constants */
#define MENU_CLEAR 1
#define COLOR_RED 2
#define COLOR_ORANGE 3
#define COLOR_GREEN 4
#define MENU_EXIT 99
#define Max(A,B) ((A) >= (B) ? (A) : (B))
/* The scene can be in one of three state, nothing, point, or line */
#define NOTHING 1
#define POINT 2
#define LINE 3
/* Global variables */
float pointSize = 8.0;
float startX, startY, endX, endY;
int sceneState = NOTHING;
/----------------------------------------------------------------------------------
- Other Painting functions to try:
-
glLineWidth(float w) *
----------------------------------------------------------------------------------/
void drawPoint(int x, int y)
{
glPointSize(pointSize);
glBegin(GL_POINTS);
glVertex2i(x, y);
glEnd();
}
void drawLine(int x0, int y0, int x1, int y1)
{
glPointSize(pointSize);
glBegin(GL_LINES);
glVertex2i(x0, y0);
glVertex2i(x1, y1);
glEnd();
}
void drawScene()
{
switch(sceneState) {
case NOTHING:
break;
case POINT:
drawPoint(startX,startY);
drawLine(startX,startY,endX,endY);
break;
case LINE:
drawLine(startX,startY,endX,endY);
drawPoint(startX,startY);
drawPoint(endX,endY);
break;
}
}
/-------------------
- Window Functions: *
-------------------/
void reshape(int w, int h)
{
printf("Entered reshape with: %d %d; glutGet: %d %d
", w, h,
glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
glutReshapeWindow(Max(w,200), Max(h,200));
glViewport(0, 0, Max(w,200), Max(h,200));
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,(double)Max(w,200), (double)Max(h,200), 0.0); /* l,r,bot,top */
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glutPostRedisplay();
}
/---------------------------------------------------------
- Display Function: *
- NB: the display function should draw the whole scene! *
---------------------------------------------------------/
void display ()
{
glClear(GL_COLOR_BUFFER_BIT);
drawScene();
}
/-----------------
- Menu Functions: *
-----------------/
void handleMenu(int value)
{
switch(value) {
case MENU_CLEAR: /* Set scene state to nothing /
sceneState = NOTHING;
break;
case MENU_EXIT: / Exit program */
exit(0);
}
glutPostRedisplay();
}
void colorMenu(int value)
{
GLfloat r, g, b;
switch(value) {
case COLOR_RED:
r = 1.0; g = 0.0; b = 0.0;
break;
case COLOR_ORANGE:
r = 1.0; g = 0.5; b = 0.0;
break;
case COLOR_GREEN:
r = 0.0; g = 1.0; b = 0.0;
}
/* Set GL color state to the color requested */
glColor3f(r,g,b);
}
/-----------------
- The mouse code: *
-----------------/
void mouseclick(int button, int state, int x, int y)
{
printf("button: %d %s, %d, %d
",
button, state == GLUT_UP ? “UP” : “down”, x, y);
if (button == GLUT_LEFT_BUTTON) {
if (state == GLUT_DOWN) {
startX = x; startY = y;
endX = x; endY = y;
sceneState = POINT;
} else {
endX = x; endY = y;
sceneState = LINE;
}
}
glutPostRedisplay();
}
/---------------------------------------------
- What happens while the mouse is down… *
---------------------------------------------/
void userFeedback(int x, int y)
{
endX = x; endY = y;
glutPostRedisplay();
}
/--------------------------
- Initialize Window: *
--------------------------/
void init()
{
int c_menu;
//printf(“get here”);
/* Select “clearing” (background) color */
glClearColor(0.0,0.0,1.0,0.0);
/* Set an initial foreground color */
glColor3f(1.0, 0.0, 0.0);
/* create color sub-menu */
c_menu = glutCreateMenu(colorMenu);
glutAddMenuEntry(“Red”,COLOR_RED);
glutAddMenuEntry(“Orange”,COLOR_ORANGE);
glutAddMenuEntry(“Green”,COLOR_GREEN);
/* Create mode menu: */
glutCreateMenu(handleMenu);
glutAddMenuEntry(“Clear Display”, MENU_CLEAR);
glutAddSubMenu(“Change Color”, c_menu);
glutAddMenuEntry(“Exit”, MENU_EXIT);
glutAttachMenu(GLUT_RIGHT_BUTTON);
}
/--------------------
- The main routine: *
--------------------/
int main (int argc, char *argv)
{
/ GLUT initialization: */
glutInit(&argc, argv);
/* Note that the SUN’s in 304 Hammond do not support color
/* indexing. Thus, we do everything in RGB */
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowSize(500, 500);
glutInitWindowPosition(200, 200);
glutCreateWindow(“CSE 418 – Example 1”);
/* Initialize our window: */
init();
/* Post Event Handlers */
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMouseFunc(mouseclick);
glutMotionFunc(userFeedback);
/* Enter the main loop: */
glutMainLoop();
return 0;
}