PDA

View Full Version : can someone try this?



cubbie
09-18-2002, 02:23 PM
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\n", 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\n",
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;
}

tinak
09-18-2002, 05:23 PM
Once I altered this routine it worked fine... glClearColor sets the background color remember ;-)

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);
glClearColor(r,g,b,0);
}

Tina

cubbie
09-18-2002, 06:05 PM
i tried what you said, the same thing happened.
the problem occurs on initialization of the window ... do you see anything wrong with that?

thanks!

Deiussum
09-19-2002, 04:28 AM
You don't say what your problem is. I've also got an integrated Intel chip on my work computer and I tried running that. I ran into a problem where it didn't appear that anything was getting drawn. It would come up and would contain an image of the everything behind it as if you were looking through the window.

I changed it to use double buffering and it seemed to work at least to the point of clearing the screen. This chip must have some weirdness associated with single buffered OpenGL apps.

cubbie
09-19-2002, 07:33 AM
that is the same problem i had. since i am entirely new to opengl and because the program i posted was just given to me to test opengl on my computer, i am not particularly familiar with the concept of single/double buffering and how to switch between the two.
could you please show me?
thanks.

tinak
09-19-2002, 07:48 AM
Ah, it seems your problem is restricted to that Intel chip you are using. Apart from that slight change the program worked perfectly with the background colour changing as per right click menu option selection.

Ah, interesting..

When I changed the following line (which I assume is the code that solved the problem) the program did not update the screen at all... Much like what you are experiencing without it... very weird. Can't see what would resolve it though..

glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);

Tina

Deiussum
09-19-2002, 09:26 AM
To switch to double buffering you have to do what tinak described and change the GLUT_SINGLE to GLUT_DOUBLE.

You also (and this is probably what tinak forgot to do) need to add glutSwapBuffers() at the end of your display routine.

tinak
09-19-2002, 11:10 AM
d'oh...

no surely I didn't ... hehe

hey, what do you know... that was the reason... shucks ;-)

Tina