PDA

View Full Version : Help with successive calls to methods



Pikachelsea
01-19-2005, 07:28 PM
Hi,

I'm just starting out with OpenGL, and have only coded a few introductory level programs. I've already run into a little problem, which will probably sound dumb, but that's why I'm in the beginners coding area... :eek:

Anyway, I'm trying to make successive calls to one of my own user-written methods using glutDisplayFunc(), and it doesn't seem to be working.

I noticed that glutDisplayFunc() only likes to take a single parameter. So, I can pass one method to it. Multiple calls of glutDisplayFunc() in main do not seem to call the method numerous times.

This works fine for most programs where I only have one method that I wish to pass. However, in my current program, I wrote a method called parameterizedHouse, which has several parameters which determine what the house looks like when it's drawn. I want to call this method a few times with different parameters so that the houses are drawn multiple times, and look different, but I'll be darned if I can figure out how.

This is what I have (note that the functional code for the parameterizedHouse method is elsewhere in the program):

//myDisplay
void myDisplay(void)
{
GLintPoint aPoint;
aPoint.x = 100;
aPoint.y = 150;

parameterizedHouse(aPoint, 100, 200);

GLintPoint bPoint;
bPoint.x = 200;
bPoint.y = 300;

parameterizedHouse(bPoint, 150, 275);

glFlush();
}

Then, in the main function, I pass myDisplay to glutDisplayFunc:

glutDisplayFunc(myDisplay); // Register redraw function

This works for other programs, but like I said, it doesn't seem to work for this since I'm calling parameterizedHouse more than once. Only the last house in myDisplay shows up; it's like the first call to parameterizedHouse doesn't register or something.

What am I doing wrong? Sorry for the long post, and thanks to anyone who can help. Please let me know if I need to provide any more information about this.

CWiC
01-19-2005, 11:05 PM
Can you see the result of first call to parameterizedHouse if comment all other lines in myDisplay? Maybe code from parameterizedHouse will help in diagnosis.

-NiCo-
01-20-2005, 12:48 AM
Glut only allows one display function callback which is called each time the screen needs to be refreshed, so it is called when an overlapping window is being moved or manually by calling glutPostRedisplay().

There are 2 ways to solve your problem, either with keyboard interaction:

//global variables
int index=0;

GLintPoint points[2];
int params[2][2];

points[0].x=100;
points[0].y=150;
params[0][0]=100;
params[0][1]=200;
points[1].x=200;
points[1].y=300;
params[1][0]=150;
params[1][1]=275;

//myDisplay
void myDisplay(void)
{

parameterizedHouse(points[index], params[index][0], params[i][1]);

glFlush();
}

void key(unsigned char key, int x, int y) {
switch (key) {

case 's':
index=(index+1)%2;
glutPostRedisplay();
break;

}
}

int main(int argc, char **argv) {

...

glutDisplayFunc(myDisplay);
glutKeyboardFunc(key);

}

This code switches between the two views by pressing the s-key.

Or you can do it automatically by updating the point and parameter values and calling glutPostRedisplay() using the glutIdleFunc, or at the end of MyDisplay itself.

Greetz

Nico