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: 
  - Make sure that the 'GNOME' build
environment is installed
correctly,
 
  -    if not then read 'setup
C build
environment.txt' and also  'setup
GNOME build
environment.txt'. 
     
  - Make sure that you have read ' GNOMEC
Demos 1
and 2' and ' GTKC
Demo 1' and 'GTKCGL3 Demo 1'.
 
  - Make sure that Glade-3.6.3 or better is
installed
!!!!!!!!
 
  - Make sure that you have a working
OpenGLtm type library installed and working, try 'glxgears' from a
terminal, it does not need to work very fast!
 
  - Make sure you have the required openGLtm
( Mesa probably ) 'dev' packages e.g. 'libgl1-mesa-dev' and
'libglu1-mesa-dev' or similar!
 
Exercise-1: Start
the program
'Sample1'.
  - Open 'side4linux' and click on 'Project>Open Project' in
the Main Menue.
 
  - Select '--/SIDE/DEMOS/SIDEdemos/GTKCGL3/Sample1/sample1.prf'
as in figure-1 below and click on 'Open'
in the Dialog Box.
 
  - Click on 'Build>Autogen
Project' and then click on the Toolbar 'Build' button.
 
  - Once the Project is Built, close the project. 
     
  - 'Project>Close
Project'
 
  - Note that it will be stored in the 'GTKCGL' section of the 'SIDEdemos' Folder.
 
  - Change directory to your new program ( that is
'~/SIDE/DEMOS/SIDEdemos/GTKCGL3/Sample1/src/'  ).
 
  -   and run the program in a terminal,  (
in my case that is
'db@wks1:~/Data/Projects/SIDE/DEMOS/SIDEdemos/GTKCGL3/Sample1/src/$
./sample1' 
).
 
  -   Note: Do not forget the 'dot forward slash' which
says look in the 'current' directory for the program.
 
  - This brings up the program 'sample1' as in figure-2.
 
  - 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,
  - We have found the Glade GUI build file ( 'sample1.glade' )
needed for GTK+ Builder to build our Widgets.
 
  -      and a host of unsatisfied
'callback' signals that will need 'handlers' written for them.  (
check GTKC projects in the Help for callback handlers ).
 
 
Now Click on the buttons ( one
at a time! ) and observe....
  - Draw1  : Draws a
circle and line in 'Wireframe' mode ( figure-3 ).
 
  - Draw2  : Draws a
disc in 'Surface' mode ( figure-4 ).
 
  - Clear1  : Clears
the screen of drawn artifacts.
   
  
 
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.
  - All of the GTK+ widgets in the program are
instantiated in the call to
'mainWindow = buildWidgets(cmdString);' 
at
program start in 'main.c'.
 
  -  There needs to be 'signal
handler functions' created
( often referred to as 'callback'
functions ) to match the callback signals created in Glade-3.
 
  - The callback function names must exactly match the
callback signal
names or
they will appear on the command line as warnings!
 
  - The side4linux IDE builds you a skeleton 'glade' XML file in the top
directory of your Project ( [Project-Name].glade ) for you to edit with
Glade-3.
 
  - You must provide a 'container'
widget for the GL World to be inserted into.
     
  - You must 'Save'
your edited 'glade' XML file
in Glade-3 and then click the 'Build'
Toolbar button in the IDE before changes are evident in running the
program.
 
  - Always use 'Project>Close
Project' when closing the IDE to ensure that all 
altered files have been saved.
 
  - The IDE has included the necessary 3D staticly linked
libraries and placed them in the 'src'
directory (' libgtkglS4L' and
'libdraw3dS4L' ) for you to use.
 
  - We have not yet done anything to our 3D widget except 'draw' on it, we will do more in
Demo-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
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
