Demo-1  <<--PREV           UP --^           NEXT-->>  Demo-3
side4linux, a simple integrated development environment!

GTKCGL3 Demo-2  Running a GTK+ Builder project with an OpenGLtm type widget.

Purpose:  To provide a basic introduction to running an OpenGLtm type 3D Widget in a GTK+ Builder Project.

Requirements:

Exercise-1: Start the program 'Sample1'.
  1. Open 'side4linux' and click on 'Project>Open Project' in the Main Menue.
  2. Select '--/SIDE/DEMOS/SIDEdemos/GTKCGL3/Sample1/sample1.prf' as in figure-1 below and click on 'Open' in the Dialog Box.


Fig-1
  1. Click on 'Build>Autogen Project' and then click on the Toolbar 'Build' button.
  2. Once the Project is Built, close the project.
  3. 'Project>Close Project'
  4. Note that it will be stored in the 'GTKCGL' section of the 'SIDEdemos' Folder.
  5. Change directory to your new program ( that is '~/SIDE/DEMOS/SIDEdemos/GTKCGL3/Sample1/src/'  ).
  6.   and run the program in a terminal,  ( in my case that is 'db@wks1:~/Data/Projects/SIDE/DEMOS/SIDEdemos/GTKCGL3/Sample1/src/$ ./sample1'  ).
  7.   Note: Do not forget the 'dot forward slash' which says look in the 'current' directory for the program.
  8. This brings up the program 'sample1' as in figure-2.
  9. Look at the text behind the program ( a good place to start when something does not work as expected ) and see the startup output generated.

Draw3D_CheckForOpenGL, OpenGL is supported
Trying local 'glade' file
Local 'glade' file found!

(sample1:9542): Gtk-WARNING **: Could not find signal handler 'on_programQuitToolbutton_clicked'
(sample1:9542): Gtk-WARNING **: Could not find signal handler 'on_fileSaveAsToolbutton_clicked'
(sample1:9542): Gtk-WARNING **: Could not find signal handler 'on_fileSaveToolbutton_clicked'
(sample1:9542): Gtk-WARNING **: Could not find signal handler 'on_fileOpenToolbutton_clicked'
(sample1:9542): Gtk-WARNING **: Could not find signal handler 'on_fileOpenToolbutton_clicked'
(sample1:9542): Gtk-WARNING **: Could not find signal handler 'on_aboutMenuitem_activate'
(sample1:9542): Gtk-WARNING **: Could not find signal handler 'on_programQuitMenuitem_activate'
(sample1:9542): Gtk-WARNING **: Could not find signal handler 'on_saveFileAsMenuitem_activate'
(sample1:9542): Gtk-WARNING **: Could not find signal handler 'on_openFileMenuitem_activate'
(sample1:9542): Gtk-WARNING **: Could not find signal handler 'on_newFileMenuitem_activate'
get fences failed: -1
param: 6, val: 0
GLworld_CreateWorld Select = 0                                                          <--------- We have managed to create an OpenGL World to 'draw' in!
Draw3D_SetCurrentWorld, currentWorld = 0
Insert 'GLworld1' glworld into GTK widget
In main.c, WorldContainer = 'viewport1'
Draw3D_InsertWorld, trying to add 'GLworld1' World
Draw3D_InsertWorld, trying to show 'GLworld1' World
Draw3D_InsertWorld, trying to add callbacks to 'GLworld1' World
Draw3D_InsertWorld, trying to set events in 'GLworld1' World
Draw3D_InsertWorld, exit.                                                              
<--------- We have managed to insert our OpenGL World into the GTK 'holder' widget!
Draw3D:world_expose_event, entering
                                             <--------- The 'expose' event is a callback that activates if our GL World becomes visible.
Draw3d:blackWorlds, enter
entering  Draw3D_ClearCurrentWorldToBlack
entering GLworld_ClearWorldToBlack, select = 0
done GLworld_ClearWorldToBlack
leaving  Draw3D_ClearCurrentWorldToBlack
done GLworld_CaptureDisplayImage
Draw3d:blackWorlds, image captured

Draw3d:blackWorlds, recreate all GL display images
Draw3d:reshapeWorld[0]                                                                 
<--------- The 'reshape' event is a callback that activates if our GL World changes shape.
Draw3D:reshapeWorld, Attempt to ClearAllWorldsToBlack
Draw3d:reshapeWorld, exit
Draw3d:blackWorlds, enter
entering  Draw3D_ClearCurrentWorldToBlack
entering GLworld_ClearWorldToBlack, select = 0
done GLworld_ClearWorldToBlack
leaving  Draw3D_ClearCurrentWorldToBlack
done GLworld_CaptureDisplayImage
Draw3d:blackWorlds, image captured
Draw3d:blackWorlds, recreate all GL display images
Draw3D:world_expose_event, entering


So as you can see the 'Draw3D' commands ( in libdraw3dS4L ) have setup our GL World widget ready for user interaction.

Also note,

Now Click on the buttons ( one at a time! ) and observe....
 


Fig-2

Fig-3

Fig-4


Exercise-2: Check some files of interest in the program 'Sample1'.

Open 'main.c' and note,

mainWindow = buildWidgets(cmdString);          <------- build all of our GTK+ widgets using GTK BUILDER and return the pointer to mainWindow.

if(mainWindow == NULL)
                                          <------- if the GTK+ widgets are not built then kill the program!
{
  g_warning("From 'main': Something bad happened while creating the gtkXML interface");

  return(1);
}


    // now reset all glworlds allowed by 'MAXWORLDS' defined in libgtkglS4L:gdkgl.h
    // and 'MAXWORLDS_ALLOWED' defined in libdraw3dS4L:Draw3D.c
    Draw3D_ResetAllWorlds();

    // create all needed glworlds
    Draw3D_CreateWorld(GLworld1);

    while(g_main_context_iteration(NULL,FALSE)); // use this anytime for GTK to catch up, if needed!

    Draw3D_SetCurrentWorldIndex(GLworld1); // if there are more than one GL Worlds then set it to the first one!

    gtk_widget_set_size_request(Draw3D_GetCurrentWorld(),200,200); //  set the minimum size of our GL widget

    // Insert "GLworld1" glworld into GTK widget "viewport1"
    glWorld1Container = Draw3D_InsertWorld(getWorldContainer("viewport1"),"viewport1","GLworld1",GLworld1);

    gtk_main(); // finally we can start the GTK main loop.
  }

Open 'callbacks.c' and note,

void gtkQuit() // no parameter type since it is a callback function
{

// specialised kill function to remove the OpenGL widget/s before the program is terminated.

  if(glWorld1Container != NULL)
  {
    g_print("Trying to remove GLworld1\n");
    Draw3D_SetCurrentWorldIndex(GLworld1);
    gtk_container_remove(GTK_CONTAINER(glWorld1Container),Draw3D_GetCurrentWorld());  <------- GL World widget removal from 'container' widget.
  }
  gtk_main_quit();
  g_print("\nProgram Terminated by user!\n");
}


Callback functions set up using Glade-3


void buttonDraw1_clicked_cb()  // to draw the 'wireframe' circle and line.

void buttonDraw2_clicked_cb()  // to draw the 'surface' disc.

void buttonClear1_clicked_cb()  // to clear the GL World screen.



Summary: Running a new 3D Visual Project built using side4linux and Glade-3.


Further reading: Check out the following books for some GTK+ and OpenGLtm programming references..


http://www.gtkbook.com/home.php



Foundations of GTK+ Development
by Andrew Krause

Publisher: Apress
Pub Date: April 2007
Print ISBN: 978-1-59059-793-4
Web ISBN: 1-59059-793-1
Pages: 630




Also you will need books on OpenGLtm



http://www.amazon.com

                                                                                         

OpenGL(R) Programming Guide: The Official Guide to Learning OpenGL(R), Version 2.1 (6th Edition) (Paperback)

You can read the old version on the web,

  http://www.glprogramming.com/red


Also checkout the OpenGL website!




We will provide other demos as 'side4linux' develops to cover GTK+ visual programming and integration into a real world machine controller.

GUI interface made with Gtk and Glade GUI demo built with Glade