Results 1 to 6 of 6

Thread: Gtk and Glut animation

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2003
    Posts
    15

    Gtk and Glut animation

    Hi !
    I have made a little glut animation, with a triangle which rotates. And i wanted to put it with a gtk menu.
    The probleme is, there is no more rotation. It seems to be, that gtk stop the opengl (glut) loop.
    How can I make this animation working ?
    I make it with gluut because, later I wanted to make some more complicated thing with it, and use de glui too.
    I need to make an animation (glut), with a menu(gtk). I don't very well gtk, and glut is for me the best to make a scene with interactions with the mouse and keyboard, use glui widgets, and etc...
    Please help me.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    374

    Re: Gtk and Glut animation

    You just should not mix glut with gtk. If you want to have gtk you should use a gtk widget for your rendering context.

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2003
    Posts
    15

    Re: Gtk and Glut animation

    Originally posted by satan:
    You just should not mix glut with gtk. If you want to have gtk you should use a gtk widget for your rendering context.
    I don't understand. Is it , if I want to use gtk with glut this story of widget ?

    Please, give a look at my source, I've tried to make it with 2 threads :

    #include <stdio.h>
    #include <stdlib.h>

    #include <gtk/gtk.h>
    #include <GL/glut.h>

    float angle = 0.0;


    //************ Glut Init ****************//
    void Initialisation()
    {
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
    glClearColor(0, 0, 0, 1);
    }

    void Reshape(int largeur, int hauteur)
    {
    if(hauteur == 0)
    hauteur = 1;

    float ratio = 1.0* largeur / hauteur;
    // Reset the coordinate system before modifying
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    // Set the viewport to be the entire window
    glViewport(0, 0, largeur, hauteur);
    //gluOrtho2D(-1, 1, -1, 1);
    gluPerspective(45,ratio,1,1000);

    // Set the correct perspective.
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0.0,0.0,5.0,
    0.0,0.0,-1.0,
    0.0f,1.0f,0.0f);
    }

    //******* Gl Paint *************//
    void Dessin(void)
    {

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();
    glRotatef(angle,0.0,1.0,0.0);
    glBegin(GL_TRIANGLES);
    glColor3f(1.0,0,0);glVertex3f(-0.5,-0.5,0.0);
    glColor3f(0,1.0,0);glVertex3f(0.5,0.0,0.0);
    glColor3f(0,0,1.0);glVertex3f(0.0,0.5,0.0);
    glEnd();
    glPopMatrix();
    angle++;

    //glFinish();
    glFlush();
    glutSwapBuffers();
    }

    static void Touche(unsigned char key, int x, int y)
    {
    printf("Touche: %d\n",key);
    switch (key)
    {
    case 27:
    exit(0);
    break;
    }
    }

    //*************** Glut Function ***************//
    void opengl_thread(void)
    {
    glutInitWindowSize(200,200 );
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
    glutCreateWindow("Fenetre OpenGL");
    Initialisation();
    glutReshapeFunc(Reshape);
    glutDisplayFunc(Dessin);
    glutKeyboardFunc(Touche);
    Initialisation();
    glutMainLoop();
    }

    void cb_ok()
    {
    printf("Ok Clicked...\n");
    }

    //********* GTK Interface *********//
    int menuInterface(void)
    {
    GtkWidget *pwindow;

    GtkWidget *pMenuBar;
    GtkWidget *pMenu;
    GtkWidget *pMenuItem;

    GtkWidget *pvbox;
    //GtkWidget *pBUT_Quit;
    //GtkWidget *pBUT_Ok;

    pwindow=gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(pwindow),"Menu thread !");
    gtk_window_set_default_size(GTK_WINDOW(pwindow),20 0,320);
    g_signal_connect(G_OBJECT(pwindow),"destroy",G_CAL LBACK(gtk_main_quit),NULL);

    /* GTKvbox */
    pvbox=gtk_vbox_new(FALSE,0);
    gtk_container_add(GTK_CONTAINER(pwindow),pvbox);

    /* Menu */
    pMenuBar=gtk_menu_bar_new();

    pMenu=gtk_menu_new();

    pMenuItem=gtk_menu_item_new_with_label("New !");
    gtk_menu_shell_append(GTK_MENU_SHELL(pMenu),pMenuI tem);

    pMenuItem=gtk_menu_item_new_with_label("Open !");
    gtk_menu_shell_append(GTK_MENU_SHELL(pMenu),pMenuI tem);

    pMenuItem=gtk_menu_item_new_with_label("Save !");
    gtk_menu_shell_append(GTK_MENU_SHELL(pMenu),pMenuI tem);

    pMenuItem=gtk_menu_item_new_with_label("Close !");
    gtk_menu_shell_append(GTK_MENU_SHELL(pMenu),pMenuI tem);


    pMenuItem=gtk_menu_item_new_with_label("Quit !");
    g_signal_connect(G_OBJECT(pMenuItem),"activate",G_ CALLBACK(gtk_main_quit),(GtkWidget*)pwindow);
    gtk_menu_shell_append(GTK_MENU_SHELL(pMenu),pMenuI tem);

    pMenuItem=gtk_menu_item_new_with_label("Fichier");

    gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem) ,pMenu);

    gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar),pMe nuItem);

    /* Menu to window */
    gtk_box_pack_start(GTK_BOX(pvbox),pMenuBar,FALSE,F ALSE,0);

    gtk_widget_show_all(pwindow);

    return EXIT_SUCCESS;

    }

    int main(int argc, char **argv)
    {
    //threads Initialisation...
    g_thread_init(NULL);

    //Initialisation GTK, GLUT...
    gtk_init (&argc, &argv);
    glutInit(&argc, argv);

    //GTK Window Creation ...
    menuInterface();

    //threads activation ...
    gdk_threads_enter();

    //GL and Gtk loops
    g_thread_create((GThreadFunc)opengl_thread,NULL,FA LSE,NULL);
    gtk_main ();

    //quit...
    gdk_threads_leave();
    return 0;

    }

  4. #4
    Junior Member Newbie
    Join Date
    Apr 2003
    Posts
    15

    Re: Gtk and Glut animation

    Probleme solved, I forgot the method glutPostRedisplay() at the end of my scene.
    It works now !!!

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Gtk and Glut animation

    Great if you got it to work, normaly I don't think you should mix the two together.
    You should rewrite your openGL animation using only gtk with no glut functions.

    Originally posted by Mao:
    Hi !
    I have made a little glut animation, with a triangle which rotates. And i wanted to put it with a gtk menu.
    The probleme is, there is no more rotation. It seems to be, that gtk stop the opengl (glut) loop.
    How can I make this animation working ?
    I make it with gluut because, later I wanted to make some more complicated thing with it, and use de glui too.
    I need to make an animation (glut), with a menu(gtk). I don't very well gtk, and glut is for me the best to make a scene with interactions with the mouse and keyboard, use glui widgets, and etc...
    Please help me.


    [This message has been edited by nexusone (edited 04-30-2003).]

  6. #6
    Junior Member Newbie
    Join Date
    Apr 2003
    Posts
    15

    Re: Gtk and Glut animation

    Originally posted by nexusone:
    Great if you got it to work, normaly I don't think you should mix the two together.
    You should rewrite your openGL animation using only gtk with no glut functions.
    Why not ? i had the feeling that GTK is fully objectoriented, and it will be too bad that it doesn't works, just for de OS portability. GlutPostRedisplay was for me here a good help, why making a method to force a redisplay, when we don't need it ?
    It is practical, when glut should work with other interface, isn't it ?

    M@o

Similar Threads

  1. GL2 2D animation w/o GLUT... I think I almost got it?
    By NathanHawks_US in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-30-2017, 03:55 PM
  2. Animation with glut
    By debinair in forum OpenGL: Basic Coding
    Replies: 10
    Last Post: 09-07-2013, 12:21 AM
  3. how to do animation using glut
    By qawded in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 07-08-2013, 12:49 AM
  4. glut & animation?
    By apocalexiz in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-17-2003, 05:16 AM
  5. simple animation w/glut
    By pbrisk in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 12-08-2001, 03:23 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