leszpol
Joined: 25 Apr 2008 Posts: 29 Location: Gdynia-TriCity
|
Posted: Wed May 28, 2008 7:30 am Post subject: Problem with simple handle menu in OpneGL classic window |
|
|
Thank you for any help. I have source code in C as below:
Code: |
#include <GL/glut.h>
#include <stdlib.h>
void Display ()
{
glClearColor (1.0,1.0,1.0,1.0);
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0,0.0,0.0);
glBegin (GL_POLYGON);
glVertex3f (0.0, 0.0, 0.0);
glVertex3f (0.0, 1.0, 0.0);
glVertex3f (1.0, 1.0, 0.0);
glVertex3f (1.0, 0.0, 0.0);
glEnd ();
glFlush ();
glutSwapBuffers();
}
void Reshape (int width, int height)
{
Display ();
}
enum
{
EXIT
};
void Menu (int value)
{
switch (value)
{
case EXIT:
exit (0);
}
}
int main (int argc, char *argv[])
{
glutInit (&argc,argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (400,400);
glutCreateWindow ("SQUARE 1");
glutDisplayFunc (Display);
glutReshapeFunc (Reshape);
glutCreateMenu (Menu);
glutAddMenuEntry ("END OF PROGRAM",EXIT);
glutAttachMenu (GLUT_RIGHT_BUTTON);
glutMainLoop ();
return 0;
}
|
It makes simple read square in the classic OpenGL window. The part in main program:
Code: |
glutCreateMenu (Menu);
glutAddMenuEntry ("END OF PROGRAM",EXIT);
glutAttachMenu (GLUT_RIGHT_BUTTON);
|
and the parat in the subroutine part of the program
Code: |
enum
{
EXIT
};
void Menu (int value)
{
switch (value)
{
case EXIT:
exit (0);
}
}
|
realise simple handle menu. When I am pushing a right mouse button I can see "EXIT" word in the region of my window. After choosing it I can exit, stop the program. I tried to rewrite it in FORTRAN and done evrything apart simple handle menu. It seems to be very simply but I am familiar with fortran 77 standard and I don't understand meaning of EXTERNAL variable. I done tha part of the program responsible for drawing red square and commented code it is what should be add to make handle menu and I can't menage with it.
My working part looks like this:
Code: |
subroutine display
include 'GL/fgl.h'
include 'GL/fglut.h'
call fglClear(GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT)
call fglColor3f(1.0, 0.0, 0.0)
call fglBegin (GL_POLYGON)
call fglVertex3f (0.0, 0.0, 0.0)
call fglVertex3f (0.0, 1.0, 0.0)
call fglVertex3f (1.0, 1.0, 0.0)
call fglVertex3f (1.0, 0.0, 0.0)
call fglEnd ()
call fglFlush ()
call fglutSwapBuffers()
return
end
Cenum
C{
C EXIT
C};
Cvoid Menu (int value)
C{
C switch (value)
C {
C case EXIT:
C exit (0);
C }
C}
PROGRAM OpenGL01
include 'GL/fglut.h'
integer okno1,menu1,menu
external display
call fglutInit
call fglutInitDisplayMode(GLUT_DOUBLE+GLUT_RGB)
call fglutInitWindowSize(400, 400)
okno1 = fglutCreateWindow('SQUARE 1')
call fglutDisplayFunc(display)
menu1=fglutCreateMenu (Menu)
C call fglutAddMenuEntry ("END OF PROGRAM",EXIT)
call fglutAttachMenu (GLUT_RIGHT_BUTTON)
call fglutMainLoop
end
|
I have to write in quot |
|