PDA

View Full Version : Creating two windows



Cesar Ghali
05-14-2008, 12:36 AM
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...

Dark Photon
05-14-2008, 05:01 AM
I am trying to create two windows, but the program close right after I run it.
Here with freeglut (http://freeglut.sourceforge.net/), I get:

freeglut ERROR: Function <glutCreateWindow> called without first calling 'glutInit'.

Cesar Ghali
05-14-2008, 05:56 AM
Instaed of the previous code you can use the following one, if you are using Linux





#include <GL/gl.h>
#include <GL/glut.h>
#include <stdio.h>

void redraw(void);
void keyboardPress(unsigned char, int, int);

int main( int argc, char** argv )
{
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

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;
}
}

Cesar Ghali
05-14-2008, 07:01 AM
Dear friends,

My main question is how we can create more than one window in OpenGL. I tryed the previous programs, but it did not work.


Thanks in advance for your help.

fldz
05-14-2008, 11:38 AM
You have to have a callback for both windows.
That seems to work.
Thanks for the topic, I couldnt figure this either.


glutInitDisplayMode,GLUT_DOUBLE or GLUT_RGBA or GLUT_BORDERLESS ;(freeglut)

glutInitWindowPosition, 100,100
glutInitWindowSize,100,100
glutCreateWindow,offset GMS1
glutDisplayFunc, offset display1

glutInitWindowPosition, 250,100
glutInitWindowSize,100,100
glutCreateWindow,offset GMS3
glutDisplayFunc, offset display2

display1 PROC
glClear, GL_COLOR_BUFFER_BIT
draw blah blah
glutSwapBuffers
ret
display1 ENDP

display2 PROC
glClear, GL_COLOR_BUFFER_BIT
draw blah blah
glutSwapBuffers
ret
display2 ENDP