Esta es la aplicacion:
El cubo rota, y se puede detener con los botones...
Este es el archivo .h
#ifndef FD_demonstracion_h_
#define FD_demonstracion_h_
/* Header file generated with fdesign. */
/**** Callback routines ****/
void Salir(FL_OBJECT *ob,long data);
void Rotar(FL_OBJECT *ob,long data);
/**** Forms and Objects ****/
typedef struct {
FL_FORM *demonstracion;
FL_OBJECT *canvas;
FL_OBJECT *boton_rotar;
FL_OBJECT *boton_detener;
FL_OBJECT *boton_ok;
void *vdata;
long ldata;
} FD_demonstracion;
extern FD_demonstracion * create_form_demonstracion(void);
#endif /* FD_demonstracion_h_ */
Este es el archivo .c
/* Form definition file generated with fdesign. */
#define v3f glVertex3f
#include "forms.h"
#include "prueba.h"
#include "GL/gl.h"
#include "GL/glx.h"
FD_demonstracion *display;
char rotar=1;
int idle_cb(XEvent *ev,void *data);
void Detener(FL_OBJECT *ob,long data);
int InitOGL(FL_OBJECT *ob, Window win,int w,int h, XEvent *xev,void *ud);
void Figura(void);
FD_demonstracion *create_form_demonstracion(void)
{
FL_OBJECT *obj;
FD_demonstracion *fdui = (FD_demonstracion *) fl_calloc(1, sizeof(FD_demonstracion));
fdui->demonstracion = fl_bgn_form(FL_NO_BOX, 460, 520);
obj = fl_add_box(FL_UP_BOX,0,0,460,520,"");
fdui->canvas= obj = fl_add_glcanvas(FL_NORMAL_CANVAS,80,200,300,290,""); /* ojo, gl aqui! */
fdui->boton_ok= obj = fl_add_button(FL_NORMAL_BUTTON,360,20,80,50,"OK");
fl_set_object_lsize(obj,FL_HUGE_SIZE);
fl_set_object_lstyle(obj,FL_BOLD_STYLE+FL_ENGRAVED_STYLE);
fdui->boton_rotar= obj = fl_add_button(FL_NORMAL_BUTTON,30,120,260,60,"ROTAR");
fl_set_object_lsize(obj,FL_HUGE_SIZE);
fl_set_object_lstyle(obj,FL_NORMAL_STYLE+FL_ENGRAVED_STYLE);
fl_set_object_callback(obj,Rotar,0);
fdui->boton_detener= obj = fl_add_button(FL_NORMAL_BUTTON,30,50,260,60,"DETENER");
fl_set_object_lsize(obj,FL_HUGE_SIZE);
fl_set_object_lstyle(obj,FL_NORMAL_STYLE+FL_ENGRAVED_STYLE);
fl_set_object_callback(obj,Detener,0);
fl_end_form();
return fdui;
}
/*---------------------------------------*/
void main(int argc,char *argv[])
{
FL_OBJECT *controla;
fl_initialize(argv[0],"GlDemo",0,0,&argc,argv);
display=create_form_demonstracion();
fl_add_canvas_handler(display->canvas,Expose,InitOGL,0);
fl_set_idle_callback(idle_cb,0);
fl_show_form(display->demonstracion,FL_PLACE_CENTER|FL_FREE_SIZE,
FL_FULLBORDER,"Open GL demo");
while((controla = fl_do_forms()) != display->boton_ok);
}
int InitOGL(FL_OBJECT *ob, Window win,int w,int h, XEvent *xev, void *ud)
{
/* La primera parte de esta funcion inicializa OpenGL con los parametros
que diran como se visualiza. */
glViewport(0,0,(GLint)w,(GLint)h);
glDrawBuffer(GL_FRONT);
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-5.0,5.0,-5.0,5.0,1.0,100.0);
glTranslatef(0,0,-5);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glScalef(2.0,2.0,2.0);
glShadeModel(GL_SMOOTH);
return 0;
}
int idle_cb(XEvent *ev,void *data)
{
if(rotar)
{
glDrawBuffer(GL_BACK);
glClearColor(0.5,0.5,0.5,0.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glRotatef(1.0,1.0,2.0,-3.0);
Figura();
glXSwapBuffers(fl_display, fl_get_canvas_id(display->canvas));
}
}
void Figura( void )
{
glColor3f( 1.0, 0.0, 0.0 );
glBegin(GL_POLYGON);
v3f( 1.0, 1.0, 1.0 ); v3f( 1.0, -1.0, 1.0 );
v3f( 1.0, -1.0, -1.0 ); v3f( 1.0, 1.0, -1.0 );
glEnd();
glColor3f( 0.5, 0.0, 0.0 );
glBegin(GL_POLYGON);
v3f( -1.0, 1.0, 1.0 ); v3f( -1.0, 1.0, -1.0 );
v3f( -1.0, -1.0, -1.0 ); v3f( -1.0, -1.0, 1.0 );
glEnd();
glColor3f( 0.0, 1.0, 0.0 );
glBegin(GL_POLYGON);
v3f( 1.0, 1.0, 1.0 ); v3f( 1.0, 1.0, -1.0 );
v3f( -1.0, 1.0, -1.0 ); v3f( -1.0, 1.0, 1.0 );
glEnd();
glColor3f( 0.0, 0.5, 0.0 );
glBegin(GL_POLYGON);
v3f( 1.0, -1.0, 1.0 ); v3f( -1.0, -1.0, 1.0 );
v3f( -1.0, -1.0, -1.0 ); v3f( 1.0, -1.0, -1.0 );
glEnd();
glColor3f( 0.0, 0.0, 1.0 );
glBegin(GL_POLYGON);
v3f( 1.0, 1.0, 1.0 ); v3f( -1.0, 1.0, 1.0 );
v3f( -1.0, -1.0, 1.0 ); v3f( 1.0, -1.0, 1.0 );
glEnd();
glColor3f( 0.0, 0.0, 0.5 );
glBegin(GL_POLYGON);
v3f( 1.0, 1.0, -1.0 ); v3f( 1.0,-1.0, -1.0 );
v3f( -1.0,-1.0, -1.0 ); v3f( -1.0, 1.0, -1.0 );
glEnd();
}
void Rotar(FL_OBJECT *ob,long data)
{
rotar=1;
}
void Detener(FL_OBJECT *ob,long data)
{
rotar=0;
}