Results 1 to 5 of 5

Thread: Creating two windows

  1. #1
    Junior Member Newbie
    Join Date
    May 2008
    Location
    Syria, Aleppo
    Posts
    11

    Creating two windows

    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:

    Code :
    #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...

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,655

    Re: Creating two windows

    Quote Originally Posted by Cesar Ghali
    I am trying to create two windows, but the program close right after I run it.
    Here with freeglut, I get:

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

  3. #3
    Junior Member Newbie
    Join Date
    May 2008
    Location
    Syria, Aleppo
    Posts
    11

    Re: Creating two windows

    Instaed of the previous code you can use the following one, if you are using Linux



    Code :
    #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;
    	}
    }

  4. #4
    Junior Member Newbie
    Join Date
    May 2008
    Location
    Syria, Aleppo
    Posts
    11

    Re: Creating two windows

    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.

  5. #5
    Junior Member Newbie fldz's Avatar
    Join Date
    Mar 2007
    Posts
    11

    Re: Creating two windows

    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

Similar Threads

  1. creating multiple windows using glfw
    By imranrobotics in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 07-28-2012, 06:16 PM
  2. Creating two Opengl Windows
    By gottijay in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-28-2011, 02:03 AM
  3. Creating a few OpenGL windows in win 32 api
    By real_crusader in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 03-24-2003, 11:37 PM
  4. Creating sub windows
    By TolTol in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 11-27-2002, 01:21 AM
  5. creating multiple windows?
    By the_student in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-28-2001, 07:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean