Interacting with GLUT from GLUI

Started by
3 comments, last by Deadpenguin 18 years, 7 months ago
I'm just starting out with OpenGL.. I'm creating a simple drawing program but I'm having trouble clearing the GLUT window from a GLUI control panel. I have this button in my glui window: glui->add_button( "Reset", 0, (GLUI_Update_CB)clear ); When I click on the "Reset" button, I do not immediately see the GLUT window cleared. Instead, I have to click in the glut window to clear the contents. How do interact with GLUT when GLUI calls my clear() function? I have tried inserting GLUT commands into the clear() function only to have it manipulate the GLUI control panel. Thanks for any help.
Advertisement
Have you called glui->set_main_gfx_window( <your main window here> ) to set the graphics window that receives redisplay events? Only thing I can think of off the top of my head. Can you whittle down the program and post the code?
Here's my code. I'll look into glui->set_main_gfx_window

void init(void)
{
glClearColor( 0.0, 0.0, 0.0, 0.0 );
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 600, 0, 400);
}

void doDisplay (void)
{
int iX;
glClear(GL_COLOR_BUFFER_BIT);

glColor3f(0.0, 1.0, 0.0);
glLineWidth(3.0);
glBegin(GL_LINE_STRIP);
for (iX = 0;iX < curPos; iX++) {
glVertex2i(gx[iX], gy[iX]);
}
glEnd();

glEnd();
glFlush();
}

void sideGlutMouse(int button, int state, int x, int y )
{

if ( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN && curPos < TOTAL_V) {
gx[curPos] = (float)x;
gy[curPos] = (float)(400 - y);
curPos++;
}

doDisplay();
glutPostRedisplay();
}

void clear()
{
curPos = 0;
}

int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(50, 100);
glutInitWindowSize(600, 400);
glutCreateWindow("HW1");

init( );

glutMouseFunc( sideGlutMouse );
glutDisplayFunc(doDisplay);

glui = GLUI_Master.create_glui( "Control", 0, 400, 50 );
glui->add_button( "Reset", 0, (GLUI_Update_CB)clear );

glutMainLoop();
return 0;
}
Nevermind, that fixed it. Thanks a lot.
Hmmmmmm, this looks suspiciously like the homework for CS116a at San Jose State (assigned last week). Though, your original question was to a particular problem and not a "how do I do this assignment" so its not really a big deal, but be forewarned that asking about homework problems is generally frowned upon at gamedev. Also you put yourself at risk of someone plagiarizing your code and turning it in as their own (which may get you and the other person in quite a bit of trouble if it's a person who also attends SJSU). I don't want to discourage you from posting here for help, as this is a great place to get it. Always feel free to ask questions about specific problems and just be mindful that you don't ask questions that would solve your whole assignment.

Now comments on your code:
First, this code does not satisfy the requirements as it stands. The requirements clearly state that along with lines being displayed there must also be red points at each vertex (size 5).

Secondly, it's probably me just being overly picky but your reset button does not clear the screen until the mouse is clicked again in the main window. This may get you marked down as it means that a new click has to be registered (creating an unwanted starting vertex) in order to complete the reset process and that's assuming that the grader takes the time to try and click into the window (they may not and assume that your reset button is non-functional).

This topic is closed to new replies.

Advertisement