00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "framework/gui/_motifglx.h"
00023 #include "framework/gui/_motifcb.h"
00024 #include "jed_gl.h"
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027
00028 #ifdef MOTIF_ENABLED
00029
00030
00031
00032
00033
00034 #ifdef GL_ENABLED
00035
00039 static int CONFIGURACION_glx_buffer_doble[] = {
00040 GLX_DOUBLEBUFFER, GLX_RGBA, GLX_DEPTH_SIZE, 16,
00041 GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1,
00042 None
00043 };
00044 static int *CONFIGURACION_glx_buffer_simple=&CONFIGURACION_glx_buffer_doble[1];
00045 #endif
00046
00050 #ifdef GL_ENABLED
00051 GLXContext glx_context;
00052 #endif
00053
00054 #ifdef GLX_ALTERNATIVO_NONONO
00055 GLint alloc_color(Widget w, Colormap cmap, int red, int green, int blue);
00056 void translate_pixels(Widget to, Widget from, ...);
00057 #endif
00058
00059 #ifdef GLX_ALTERNATIVO_NONONO
00060 static GLint Black, Red, Green, Blue;
00061 #endif
00062
00063
00064
00065
00066
00067 #ifdef GLX_ALTERNATIVO_NONONO
00068 GLint
00069 alloc_color(Widget w, Colormap cmap, int red, int green, int blue)
00072 {
00073 XColor xcolor;
00074
00075 xcolor.red = red;
00076 xcolor.green = green;
00077 xcolor.blue = blue;
00078 xcolor.flags = DoRed | DoGreen | DoBlue;
00079 if ( !XAllocColor(XtDisplay (w), cmap, &xcolor) ) {
00080 printf ("Couldn't allocate color!\n");
00081 exit (1);
00082 }
00083 return xcolor.pixel;
00084 }
00085
00086 void
00087 translate_pixels (Widget to, Widget from, ...)
00092 {
00093 va_list ap;
00094 char *name;
00095 Colormap from_cmap, to_cmap;
00096 XColor xcolor;
00097
00098 XtVaGetValues (from, XtNcolormap, &from_cmap, NULL);
00099 XtVaGetValues (to, XtNcolormap, &to_cmap, NULL);
00100
00101 va_start (ap, from);
00102 for (name = va_arg (ap, char *); name != NULL; name = va_arg (ap, char *))
00103 {
00104 XtVaGetValues (from, name, &xcolor.pixel, NULL);
00105 XQueryColor (XtDisplay (from), from_cmap, &xcolor);
00106 if (!XAllocColor (XtDisplay (to), to_cmap, &xcolor))
00107 XtAppWarning (XtWidgetToApplicationContext (to),
00108 "Couldn't allocate color!\n");
00109 else
00110 XtVaSetValues (from, name, xcolor.pixel, NULL);
00111 }
00112 va_end (ap);
00113 }
00114 #endif
00115
00116
00117
00118
00119
00120 void
00121 arranque_GLX(Widget padre)
00132 {
00133 #ifdef GL_ENABLED
00134 Boolean rgba, doublebuffer, cmap_installed;
00135 XVisualInfo *vi;
00136 Display *Display_x;
00137
00138 XtVaGetValues(padre,
00139 GLwNrgba, &rgba,
00140 GLwNinstallColormap, &cmap_installed,
00141 GLwNdoublebuffer, &doublebuffer,
00142 GLwNvisualInfo, &vi, NULL);
00143
00144
00145 Display_x = XtDisplay(padre);
00146
00147 vi = glXChooseVisual(Display_x,
00148 DefaultScreen(Display_x), CONFIGURACION_glx_buffer_doble);
00149 if ( !vi ) {
00150 vi = glXChooseVisual(Display_x,
00151 DefaultScreen(Display_x), CONFIGURACION_glx_buffer_simple);
00152 if ( !vi ) {
00153 fprintf(stderr,
00154 "ERROR: el servidor X no soporta el modo de video solicitado!.");
00155 fflush(stderr);
00156 exit(1);
00157 }
00158 }
00159
00160
00161 glx_context = glXCreateContext(Display_x, vi, None, GL_TRUE);
00162
00163 if ( !glx_context ) {
00164 fprintf(stderr,
00165 "<MOTIF> - ERROR: "
00166 "No se puede crear un contexto de visualizacion OpenGL.");
00167 fflush(stderr);
00168 exit(0);
00169 }
00170
00171 GLwDrawingAreaMakeCurrent(padre, glx_context);
00172
00173
00174 XWarpPointer(XtDisplay(padre), None, XtWindow (padre),0, 0, 0, 0, 0, 0);
00175
00176 #ifdef GLX_ALTERNATIVO_NONONO
00177 if ( rgba ) {
00178 Black = Red = Green = Blue = 0;
00179
00180 if ( cmap_installed ) {
00181
00182
00183
00184
00185 translate_pixels (padre, form, XtNbackground, XtNborder, NULL);
00186 translate_pixels (padre, menubar,
00187 XmNbackground, XmNforeground, XmNborderColor,
00188 XmNarmColor, XmNbottomShadowColor,
00189 XmNtopShadowColor, NULL);
00190
00191
00192
00193 XWarpPointer (XtDisplay (padre), None, XtWindow (padre),
00194 0, 0, 0, 0, 0, 0);
00195 }
00196 }
00197 else {
00198
00199 Colormap cmap;
00200 cmap = DefaultColormap(
00201 XtDisplay(toplevel), DefaultScreen (XtDisplay (toplevel)));
00202 Black = alloc_color (toplevel, cmap, 0x0000, 0x0000, 0x0000);
00203 Red = alloc_color (toplevel, cmap, 0xffff, 0x0000, 0x0000);
00204 Green = alloc_color (toplevel, cmap, 0x0000, 0xffff, 0x0000);
00205 Blue = alloc_color (toplevel, cmap, 0x0000, 0x0000, 0xffff);
00206 }
00207 #endif
00208
00209 static BOOLEAN ya = FALSE;
00210 if ( !ya ) {
00211 motif_starttimer_callback(padre); ya = TRUE;
00212 }
00213 #endif
00214 }
00215
00216 #endif // MOTIF_ENABLED
00217
00218
00219
00220
00221