PDA

View Full Version : glutDisplayFunc problems :(



Nelah
02-12-2003, 06:12 PM
I'm trying to make a "simple" turtle graphics program, and I almost have it, I think. I have the options for movement in a menu attached to the right mouse button, but the option for forward will not plot the line. It's most distressing. I've tried glutDisplayFunc and glutPostRedisplay but I'm really kind of lost. My window displays but that's all. Any help would be much appreciated.

Stack Overflow
02-12-2003, 06:52 PM
Hello Nelah,

Here is an easy approach to creating a Sub Window in your program. Now if you are looking for something else, please let me know:




int mainWnd, newWnd;

void init_2( void ) {
glLoadIdentity();
glClearColor( 0.0, 0.0, 0.0, 0.0 );
glShadeModel( GL_SMOOTH );
}

// This will be in your main function
int main( int argc, char **argv ) {
mainWnd = glutCreateWindow("My Main Window");
// Your main Window display stuff will go here

newWnd = glutCreateSubWindow( mainWnd, 120, 110, 550, 510 ); // Create sub window in main window
init_2(); // use second initialization for any animation for this window only
glutDisplayFunc(display_2); // Use a second display function for any new display techniques
glutReshapeFunc(reshape); // Use normal reshape function


Edit: you can place your Sub-Window where ever you want, and here is an overview of the glutCreateSubWindow local variables:

glutCreateSubWindow(int win, int x, int y, int width, int height);

This is just an example of how to create a window, and then display another window in the first window, but again, if this is not what you are looking for, please expound on this situation some more.

- VC6-OGL

[This message has been edited by VC6-OGL (edited 02-12-2003).]

Nelah
02-12-2003, 06:59 PM
this is in my menu method

case FORWARD:
{
xend = xin + cos(theta);
yend = yin + sin(theta);

glutDisplayFunc(display);

xin = xend;
yin = yend;
}

but it won't display anything. As a matter of fact I have a GL_POINTS in my main function that won't work either. I don't know what's wrong. I have the background color and the draw color set to different colors.

Stack Overflow
02-12-2003, 07:01 PM
Hello Nelah,

What does you display function look like? Have you been able to see anything in your window at all?

- VC6-OGL

Nelah
02-12-2003, 07:05 PM
void display()
{
glClear(GL_COLOR_BUFFER_BIT);

glColor3f(0,1,0);

glBegin(GL_LINES);
glVertex2f(xin, yin);
glVertex2f(xend, yend);
glEnd();

glFlush();
}

I haven't seen anything in this program yet.
Logically, I don't understand OpenGL yet, so maybe my thinking is all wrong.

Stack Overflow
02-12-2003, 07:08 PM
Hello Nelah,

Are you defining a reshape function?, for example:

glutReshapeFunc( reshape );

Edit: here is an example of how to use the reshape function.

void reshape( int w, int h ) {
h = h < 1 ? 1 : h;

float ratio = 1.0 * w / h;

glMatrixMode( GL_PROJECTION );
glLoadIdentity();

glViewport( 0, 0, w, h );

gluPerspective( 60, ratio, 1, 1000 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}

- VC6-OGL

[This message has been edited by VC6-OGL (edited 02-12-2003).]

Nelah
02-12-2003, 07:11 PM
void myReshape(GLsizei w, GLsizei h)
{

/* adjust clipping box */

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, (GLdouble)w, 0.0, (GLdouble)h, - 1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

/* adjust viewport and clear */

glViewport(0,0,w,h);
glClearColor (0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();

/* set global size for use by drawing routine */

ww = w;
wh = h;
}

here's the reshape function, I cut and pasted it from another program.

Stack Overflow
02-12-2003, 07:17 PM
Hello Nelah,

I can help you at my Chat room at www.bluedev.net (http://www.bluedev.net)

- VC6-OGL

Nelah
02-12-2003, 07:25 PM
int main(int argc, char** argv)
{
int t_menu;

glutInit(&argc,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutCreateWindow("Turtle");
glutDisplayFunc(display);
glBegin(GL_POINTS);
glVertex2f(xin,yin);
glEnd();

t_menu = glutCreateMenu(turtle_menu);
glutAddMenuEntry("Forward",1);
glutAddMenuEntry("Backward",2);
glutAddMenuEntry("Turn Clockwise",3);
glutAddMenuEntry("Turn Counterclockwise",4);
glutAddMenuEntry("Quit",5);
glutAttachMenu(GLUT_RIGHT_BUTTON);

myinit ();
glutReshapeFunc (myReshape);
glutMainLoop();
}

The GL_POINTS is just there so I can see if it displays. Right now, it doesn't display.

Stack Overflow
02-12-2003, 07:45 PM
Hello Nelah,

Here is the full code:

#include <GL/glut.h>

void init( void ) {
glClearColor( 0.0, 0.0, 0.0, 0.0 );
glShadeModel( GL_SMOOTH );
}

void reshape( int w, int h ) {
h = h < 1 ? 1 : h;

float ratio = 1.0 * w / h;

glMatrixMode( GL_PROJECTION );
glLoadIdentity();

glViewport( 0, 0, w, h );

gluPerspective( 35, ratio, 1, 1000 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}

void display( void ) {
glClear( GL_COLOR_BUFFER_BIT );
glLoadIdentity();
glTranslatef( 0.0, 0.0, -5.0 );

glColor3f( 1.0, 1.0, 1.0 );

glPushMatrix();
glBegin(GL_POINTS);
glVertex3f(1.0,0.5,0.3);
glVertex3f(-1.0,0.5,0.3);
glVertex3f(1.0,-0.5,0.3);
glVertex3f(-1.0,-0.5,0.3);
glEnd();
glPopMatrix();

glFlush();
}

void keyboard( unsigned char key, int x, int y ) {
switch ( key ) {
case 27:
exit( 0 );
break;
}
}

void main( int argc, char **argv ) {
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );
glutCreateWindow( "GL_POINTS" );
glutFullScreen();

init();
glutReshapeFunc( reshape );
glutDisplayFunc( display );
glutKeyboardFunc( keyboard );

glutMainLoop();
}

- VC6-OGL

[This message has been edited by VC6-OGL (edited 02-13-2003).]