Re: Problem With Resize In IBM AIX 4.3.3 Fixed. I hope.
- From: "B. Souliotis" <bill beta-cae gr>
- To: gtk-app-devel-list gnome org
- Subject: Re: Problem With Resize In IBM AIX 4.3.3 Fixed. I hope.
- Date: Fri, 07 Mar 2003 15:29:03 +0200
Here is an example code trying to make a gtk_drawing_area cable for
drawing using Opengl from scratch, without GtkGlExt or Gtkgkarea Widget.
The problem exists in IBM AIX 4.3.3.
The problem was when during resize the gtk trying to change the window
background Pixmap calling gdk_window_tmp_unset_bg(GdkWindow *w) to set
Pixmap to None
end then gdk_window_tmp_reset_bg(GdkWindow *w) to set to the initial Pixmap.
The XServer crashes at :
ChangeWindowAttributes() and then
DbeChangeWindowAttributes and then
MtnChangeWindowAttributes and then crashes.
So when creating the window i set The background Pixmap to GDK_NO_BG.
I've tried this to all GtkGlExt examples and it works as well.
Also I've tried all the gtkglarea examples with gtk+-2.0 and works.
Can Anyone Tell me why gtk uses window background pixmap to
gtk_drawing_area widget.What is the reason?
#include <stdlib.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <X11/Xlib.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glx.h>
#include <gtk/gtkwindow.h>
#include <gdk/gdkdrawable.h>
#include <gdk/gdkprivate.h>
GtkWidget *window;
GLXContext gc;
Display *display;
static void realize (GtkWidget *widget, gpointer data)
{
}
static gboolean
configure_event (GtkWidget *widget,GdkEventConfigure *event,gpointer data)
{
if(!glXMakeCurrent(display, GDK_WINDOW_XID(widget->window), gc)) {
g_print("Can't make window current to context\n");
exit(-1);
}
glViewport (0, 0, widget->allocation.width, widget->allocation.height);
return TRUE;
}
static gboolean
expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
if(!glXMakeCurrent(display, GDK_WINDOW_XID(widget->window), gc)) {
g_print("Can't make window current to context\n");
exit(-1);
}
glClear (GL_COLOR_BUFFER_BIT);
glBegin (GL_TRIANGLES);
glColor3f (1.0, 0.0, 0.0);
glVertex2i (0, 1);
glColor3f (0.0, 1.0, 0.0);
glVertex2i (-1, -1);
glColor3f (0.0, 0.0, 1.0);
glVertex2i (1, -1);
glEnd ();
glXSwapBuffers(display, GDK_WINDOW_XID(widget->window));
return TRUE;
}
int rgb_attributes_dbl[] = {
GLX_RGBA,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_DOUBLEBUFFER,
None
};
GdkVisual *gdk_gl_choose_visual(int *attrlist)
{
XVisualInfo *vi;
GdkVisual *visual;
g_return_val_if_fail(attrlist != NULL, NULL);
if ((vi = glXChooseVisual(display,DefaultScreen(display), attrlist))
== NULL) return NULL;
visual = gdkx_visual_get(vi->visualid);
XFree(vi);
return visual;
}
static XVisualInfo *get_xvisualinfo(GdkVisual *visual)
{
XVisualInfo vinfo_template;
XVisualInfo *vi;
int nitems_return;
vinfo_template.visual = GDK_VISUAL_XVISUAL(visual);
vinfo_template.visualid = XVisualIDFromVisual(vinfo_template.visual);
vinfo_template.depth = visual->depth;
vinfo_template.screen = DefaultScreen(display);
vi=XGetVisualInfo(display,
VisualIDMask|VisualDepthMask|VisualScreenMask,
&vinfo_template, &nitems_return);
return vi;
}
int main (int argc, char *argv[])
{
GtkWidget *drawing_area;
GdkVisual *visual;
static XVisualInfo *vis;
GdkColormap *cmap;
GdkWindowObject *private;
gtk_init (&argc, &argv);
display = GDK_DISPLAY();
visual = gdk_gl_choose_visual(rgb_attributes_dbl);
if (visual == NULL) {
g_print("NULL visual\n");
return 0;
}
cmap = gdk_colormap_new(visual,TRUE);
gtk_widget_push_colormap(cmap);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_double_buffered (GTK_WIDGET(window), FALSE);
gtk_window_set_policy (GTK_WINDOW (window),TRUE,TRUE,FALSE);
gtk_window_set_title (GTK_WINDOW (window), "simple");
gtk_widget_set_usize (window, 900, 700);
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
gtk_container_set_reallocate_redraws(GTK_CONTAINER (window),TRUE);
gtk_container_set_resize_mode(GTK_CONTAINER(window),
GTK_RESIZE_IMMEDIATE);
drawing_area = gtk_drawing_area_new ();
gtk_widget_set_double_buffered(GTK_WIDGET(drawing_area), FALSE);
gtk_container_add (GTK_CONTAINER (window), drawing_area);
gtk_widget_set_events (drawing_area,
GDK_EXPOSURE_MASK |
GDK_BUTTON_PRESS_MASK);
gtk_widget_show(drawing_area);
gtk_widget_show(window);
/* --------------------- PROBLEM FIXED ----------------------------*/
/* WITHOUT THEESE LINES IT IS NOT WORK ON AIX WHEN TRYING TO RESIZE
THE GL_DRAIWNG AREA */
private = (GdkWindowObject*) GDK_WINDOW(drawing_area->window);
private->bg_pixmap = GDK_NO_BG;
/* -------------------- PROBLEM FIXED -----------------------------*/
vis = get_xvisualinfo(visual);
gc = glXCreateContext(display, vis, 0, GL_TRUE);
XFree(vis);
gtk_signal_connect (GTK_OBJECT (drawing_area), "realize",
GTK_SIGNAL_FUNC (realize), NULL);
gtk_signal_connect (GTK_OBJECT (drawing_area), "configure_event",
GTK_SIGNAL_FUNC (configure_event), NULL);
gtk_signal_connect (GTK_OBJECT (drawing_area), "expose_event",
GTK_SIGNAL_FUNC (expose_event), NULL);
gtk_widget_pop_colormap();
gtk_main ();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]