DESS Technologies et Stratégies Industrielles
Option : Mécanique des Matériaux
Etudiants : HALASSA M’hand




PROJET INFORMATIQUE

RECHERCHE DE BIBLIOTHEQUES GRAPHIQUES POUR « C » ET « C++ »



Enseignant IPST
M. Patrick TRAU

 

 

Année Universitaire 2004/2005

 

SOMMAIRE :


1/ But du projet.

2/Les différentes bibliothèques disponibles.

3/Tableau récapitulatif.


1/But du projet :

Le but de ce projet est la recherche des différentes bibliothèques graphiques disponibles sur le WEB et fonctionnant sous C ou C++.

2/Les différentes bibliothèques :

a/ GTK :

Gimp ToolKit. Boîte à outil utilisé d'abord par Gimp(The GNU Image Manipulation Program : Logiciel de retouche d'images, dont la puissance est comparable à Photoshop. Sauf que Gimp est un logiciel libre et gratuit), puis étendu pour pouvoir être utilisée pour n'importe quelle application. Le tout sous licence LGPL (Lisser General Public License, idem GPL).

Cette bibliothèque est multi plateformes (Unix, Windows) et multi langages (C, C++, Ada, Python).

-Exemple : Liste déroulante

// combo.c
// exemple de combobox en gtk
+ (liste deroulante)

#include
<stdio.h>
#include
<gtk/gtk.h>



int main(int argc, char *argv[])
{

    GtkWidget *Dialogue, *Combo, *Bouton;
    GList *list = NULL;
    gint i;

    gtk_init(&argc, &argv);

    Dialogue = gtk_dialog_new();
    gtk_window_set_title(GTK_WINDOW(Dialogue),
"Exemple de combo box");

    gtk_widget_show(Dialogue);

    
for(i=0; i<10; i++)
        list = g_list_append(list, g_strdup_printf(
"chaine %d", i)); // ajoute une chaine a le liste


    Combo = gtk_combo_new(); // cree une liste deroulante
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(Dialogue)
->vbox), Combo, TRUE, TRUE, 0);
    gtk_combo_set_popdown_strings( GTK_COMBO(Combo), list) ; // met la liste dans la conbo box
    gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(Combo)
->entry), "coucou"); // definit le texte de la conbo box


    gtk_widget_show(Combo);

    Bouton = gtk_button_new_with_label(
"Fermer");
    gtk_signal_connect_object(GTK_OBJECT(Bouton),
"clicked", (GtkSignalFunc)gtk_exit, NULL);
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(Dialogue)
->action_area), Bouton , TRUE, TRUE, 0);

    gtk_widget_show(Bouton);

    gtk_main();
    
    
return(0);
}

B/ OpenGL :

Open Graphic Library. Bibliothèque de fonctions graphiques permettant de réaliser de jolis effets en 3D et en 2D (mais on la connaît surtout pour la 3D). Apparue en 1992.

C’est une bibliothèque aussi multi plateformes (Unix, Windows).

Exemple : triangle tournant

/**************************
* Includes
*
**************************/
#include <windows.h>
#include <gl/gl.h>
/**************************
* Function Declarations
*
**************************/
LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam);
void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC);
void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC);
/**************************
* WinMain
*
**************************/
int WINAPI
WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int iCmdShow)
{
WNDCLASS wc;
HWND hWnd;
HDC hDC;
HGLRC hRC;
MSG msg;
BOOL bQuit = FALSE;
float theta = 0.0f;
/* register window class */
wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "GLSample";
RegisterClass (&wc);



/* create main window */
hWnd = CreateWindow (
"GLSample", "OpenGL Sample",
WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
0, 0, 256, 256,
NULL, NULL, hInstance, NULL);



/* enable OpenGL for the window */
EnableOpenGL (hWnd, &hDC, &hRC);



/* program main loop */
while (!bQuit)
{
/* check for messages */
if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{
/* handle or dispatch messages */
if (msg.message == WM_QUIT)
{
bQuit = TRUE;
}
else
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
else
{
/* OpenGL animation code goes here */



glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glClear (GL_COLOR_BUFFER_BIT);



glPushMatrix ();
glRotatef (theta, 0.0f, 0.0f, 1.0f);
glBegin (GL_TRIANGLES);
glColor3f (1.0f, 0.0f, 0.0f); glVertex2f (0.0f, 1.0f);
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (0.87f, -0.5f);
glColor3f (0.0f, 0.0f, 1.0f); glVertex2f (-0.87f, -0.5f);
glEnd ();
glPopMatrix ();
SwapBuffers (hDC);
theta += 1.0f;
Sleep (1);
}
}
/* shutdown OpenGL */
DisableOpenGL (hWnd, hDC, hRC);
/* destroy the window explicitly */
DestroyWindow (hWnd);
return msg.wParam;
}



/********************
* Window Procedure
*
********************/
LRESULT CALLBACK
WndProc (HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
return 0;
case WM_CLOSE:
PostQuitMessage (0);
return 0;
case WM_DESTROY:
return 0;
case WM_KEYDOWN:
switch (wParam)
{
case VK_ESCAPE:
PostQuitMessage(0);
return 0;
}
return 0;


default:
return DefWindowProc (hWnd, message, wParam, lParam);

}

}

/*******************

* Enable OpenGL

*

*******************/
void
EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC)
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;
/* get the device context (DC) */
*hDC = GetDC (hWnd);
/* set the pixel format for the DC */
ZeroMemory (&pfd, sizeof (pfd));
pfd.nSize = sizeof (pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ChoosePixelFormat (*hDC, &pfd);
SetPixelFormat (*hDC, iFormat, &pfd);


/* create and enable the render context (RC) */
*hRC = wglCreateContext( *hDC );
wglMakeCurrent( *hDC, *hRC );

}
/******************
* Disable OpenGL
*
******************/
void
DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC)
{
wglMakeCurrent (NULL, NULL);
wglDeleteContext (hRC);

ReleaseDC (hWnd, hDC);

}

C /Qt :

La librairie graphique Qt, développée par la société Trolltech est principalement connue dans le monde Linux pour être à la base de l’environnement graphique KDE. Il ne faut cependant pas oublier que cette librairie existe tant sous Linux et autres Unix, mais également sous Windows, et désormais pour MacOS. Cette librairie peut donc intéresser beaucoup de développeurs.

D /Motif :

C’est une librairie graphique à licence payante mais lesstif est gratuite ,cette bibliothèque fonctionne sous le programme C++ et sous les plateformes Unix et MacOS.



Tableau récapitulatif des Librairies graphiques les plus répandues

Librairie

Langage(s)

Plateforme(s)

Licence

Commentaire

Gtk

C, C++, Ada, Perl, Python, Eiffel

Unix, Windows, BeOS

LGPL

Utilisé dans Gnome

OpenGL

C++

Windows, Unix

LGPL

Une partie de la librairie Microsoft est utilisable librement

Motif (lesstif)

C, C++

Unix, MacOS X, OS/2

LGPL

Motif est payant mais lesstif en est une implémentation libre (OpenMotif également)

Qt (Qt/X11)

C++

Unix, Windows, MacOS X

GPL

Version libre d'un projet commercial (utilisée dans KDE)



BIBLIOGRAPHIE :

-Rapport de stage«couplage de codes dans une plateforme pour applications de simulation numérique http://people.defora.org/~khorben/papers/opale/rapport_de_stage.html

- http://www.cppfrance.com

- http://c.developpez.com/bibliotheques/

- http://definition.futura-sciences.com (pour les définitions)



CODES SOURCES : combo.c et trianges.c