Cesar Ghali
05-13-2008, 11:36 PM
Dear friends...
I am trying to create two windows, but the program close right after I run it.
This is the code of the program:
#include <GL/gl.h>
#include <GL/glut.h>
#include <stdio.h>
void redraw(void);
void keyboardPress(unsigned char, int, int);
int main()
{
glutInitWindowPosition(100, 100);
glutInitWindowSize(100, 100);
glutCreateWindow("Window 1");
glutInitWindowPosition(250, 100);
glutInitWindowSize(100, 100);
glutCreateWindow("Window 2");
glutDisplayFunc(redraw);
glutKeyboardFunc(keyboardPress);
glutMainLoop();
return 0;
}
void redraw(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_POLYGON);
{
glVertex2f(-0.5, -0.5);
glVertex2f(0.5, -0.5);
glVertex2f(0.5, 0.5);
glVertex2f(-0.5, 0.5);
}
glEnd();
glFlush();
}
void keyboardPress(unsigned char key, int x, int y)
{
switch(key)
{
case '1':
glutSetWindow(1);
glutPostRedisplay();
break;
case '2':
glutSetWindow(2);
glutPostRedisplay();
break;
}
}
Thanks in advance for your help...
I am trying to create two windows, but the program close right after I run it.
This is the code of the program:
#include <GL/gl.h>
#include <GL/glut.h>
#include <stdio.h>
void redraw(void);
void keyboardPress(unsigned char, int, int);
int main()
{
glutInitWindowPosition(100, 100);
glutInitWindowSize(100, 100);
glutCreateWindow("Window 1");
glutInitWindowPosition(250, 100);
glutInitWindowSize(100, 100);
glutCreateWindow("Window 2");
glutDisplayFunc(redraw);
glutKeyboardFunc(keyboardPress);
glutMainLoop();
return 0;
}
void redraw(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_POLYGON);
{
glVertex2f(-0.5, -0.5);
glVertex2f(0.5, -0.5);
glVertex2f(0.5, 0.5);
glVertex2f(-0.5, 0.5);
}
glEnd();
glFlush();
}
void keyboardPress(unsigned char key, int x, int y)
{
switch(key)
{
case '1':
glutSetWindow(1);
glutPostRedisplay();
break;
case '2':
glutSetWindow(2);
glutPostRedisplay();
break;
}
}
Thanks in advance for your help...