PDA

View Full Version : passing arguments to display function??????????



07-24-2001, 06:21 AM
I'm writing my first program with opengl: itīs a tic tac toc game and from the main function i call another function to ask the next move to the user.The problem is that i want to pass arguments from this function to the one where i've written the graphics code and i don't now how, because the drawing is made in the function display (wich is callen from the general one that contains all the graphical part). Can you help me? How can I pass the arguments?

Eric
07-24-2001, 06:34 AM
We can help you but we'd need to see how you organized your program in order to help you.

Some questions though: do you know C (or C++) ? If you are familiar with one of these programming languages, you must be familiar with arguments/parameters.

If your problem is that you are using GLUT and that the display() function cannot have parameters, the answer is simple: make the variables you need there global to the program (using pointers if necessary).

But anyway, for a precise answer, you should post some of your code. You can e-mail me directly if you want.

Good luck !

Eric

07-25-2001, 12:41 AM
I'm working with glut and my problem is that i donīt know how to draw the
board and draw the tokens at the same time.To draw the tokens I use the
mouse function, drawing a circle when the rbutton is pressed.When I add the
board part, (with all the lines) there's no way: if i put that part of the
source in the mouse function, it only draws the tokens.If I put it in the
display parte, then the tokens are not drawn.What can I do?
I paste the graphic part of my program, that is only a firs draft:

#include <windows.h>
#include <iostream.h>
#include <stdlib.h>
#include<time.h>
#include <gl\gl.h>
#include <gl\glut.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.1415926
#endif

int xDim=600;
int yDim=500;
int xpos, ypos;

void init(void)
{
glClearColor(1.0f ,1.0f ,1.0f ,1.0f);
glColor3f(0.0f,0.0f,1.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)250/(GLfloat)250,0.1f,100.0f);
}


void circle(int x, int y, int r)
{
int n=50, i;
glBegin(GL_POLYGON);
for(i=0; i<n; i++){
glVertex2i((int)(x+r*cos(2.0*i*M_PI/n)),
(int)(y+r*sin(2.0*i*M_PI/n)));
}
glEnd();
}

void mouse(int btn, int state, int x, int y)
{
file://Drawing a token.This part will be changed to draw several
tokens at a time.

if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN){
xpos = x;
ypos = yDim-y;
glColor3f(0.0,0.0,1.0);
circle(xpos,ypos,10);
glFlush();

}

}

void display(void)
{

glClear(GL_COLOR_BUFFER_BIT);

file://Drawing the board


glBegin(GL_LINES);

file://Horizontal lines

glVertex3f( -3.0f, 3.0f, -10.0f);
glVertex3f(3.0f,3.0f, -10.0f);
glVertex3f( -3.0f, -3.0f, -10.0f);
glVertex3f(3.0f,-3.0f, -10.0f);
glVertex3f( -3.0f, 1.0f, -10.0f);
glVertex3f(3.0f,1.0f, -10.0f);
glVertex3f( -3.0f, -1.0f, -10.0f);
glVertex3f(3.0f,-1.0f, -10.0f);

file://Vertical lines

glVertex3f( -3.0f, 3.0f, -10.0f);
glVertex3f(-3.0f,-3.0f, -10.0f);
glVertex3f( 3.0f, 3.0f, -10.0f);
glVertex3f(3.0f,-3.0f, -10.0f);
glVertex3f( 1.0f, 3.0f, -10.0f);
glVertex3f(1.0f,-3.0f, -10.0f);
glVertex3f( -1.0f, 3.0f, -10.0f);
glVertex3f(-1.0f,-3.0f, -10.0f);
glEnd();


glutSwapBuffers();
}


int main(int argc,char *argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(350,350);
glutInitWindowPosition(200,200);
glutCreateWindow("Noughts and crosses");
init();
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();

return 0;
}

Eric
07-25-2001, 12:56 AM
Sara,

I have answered to this post by e-mail (if we post too much code in the forum, it quickly becomes unreadable !).

Regards.

Eric