File: HOWTO.txt

package info (click to toggle)
gtkgl2 1.99.0-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,104 kB
  • ctags: 330
  • sloc: sh: 6,744; ansic: 3,173; makefile: 125
file content (111 lines) | stat: -rw-r--r-- 3,104 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111


1. Help, ./configure does not find Mesa, I do have Mesa libaries installed.

	- Mesa may need additional libraries to link with, depending on what
	  options were used while compiling Mesa libraries. Currently configure tries
	  to link Mesa with whatever libraries GTK needs and if this fails it tries
	  Mesa+needed by GTK+pthreads libraries. Try passing extra libraries to
	  ./configure in LIBS envinronment variable.

	- configure scripts are still a bit flaky, patches are gratefully accepted.




2. How do I make any widget opengl widget?

	Your widget needs OpenGL capable visual and you also
	need to set colormap for it. Widget must also have
	X window (not all widgets have it).

	/* get visual using gdk_gl_choose_visual */
	visual = gdk_gl_choose_visual(visual_attributes);

	/* set visual and colormap */
	gtk_widget_push__colormap(gdk_colormap_new(visual, TRUE));
	gtk_widget_push_visual(visual);

	/* create your widget */
	widget = gtk_foobar_new();

	/* disable backing store (only in GTK-1.4) */
	gtk_widget_set_double_buffered(widget, FALSE);

	/* restore old values */
	gtk_widget_pop_visual();
	gtk_widget_pop_colormap();




3. How do I render to such widget?

	Create gl context and connect it to widgets GdkDrawable.

	context = gdk_gl_context(visual);
 
	/* connect to gdk window of widget */
	if (gdk_gl_make_current(widget->window, context)) {
		do opengl stuff...

	}




4. How do I render to off screen pixmap?

	See examples/glpixmap.c, remember that pixmaps can not be rendered to with
	direct context.



5. Can I use gdk_gl functions and GtkGLArea widget in the same program?

	Yes, just remember that gtk_gl_area_make_current makes internal context of
	GtkGLArea widget current context (and leaves it so).



6. How do I capture keypress events for GtkGLArea widget?

	This is not a GtkGLArea specific question, but here is the answer anyway,

	- You forgot to set event mask:
		 gtk_widget_set_events(glarea, GDK_KEY_PRESS_MASK);

	- You forgot to grab focus:
		GTK_WIDGET_SET_FLAGS(glarea, GTK_CAN_FOCUS);
		gtk_widget_grab_focus(GTK_WIDGET(glarea));

	-  keypresses/releases have default handlers, you may need to prevent
	   them from running:
		/* do this in your signal keypress handler and return TRUE from handler */
		gtk_signal_emit_stop_by_name(GTK_OBJECT(glarea),"key_press_event");
		



7. I noticed that gtk_gl_area_begingl(), gtk_gl_area_endgl(), and gtk_gl_area_swapbuffers()
   are deprecated?

	- they are still there, but you should use gtk_gl_area_make_current() instead
	  then you can avoid calling matching gtk_gl_area_endgl().

	- just formalizing what has been true for a long time, gtk_gl_area_endgl is
	  no longer necessary and gtk_gl_area_begingl() just makes widgets context
	  current.

	- gtk_gl_area_swapbuffers() just fixes minor spelling error.

	- old versions wont go away.

	- to convert your code you can replace them with following functions.

	   gtk_gl_area_begingl()     =>  gtk_gl_area_make_current()
	   gtk_gl_area_endgl()       =>  glFlush() or nothing
	   gtk_gl_area_swapbuffers() =>  gtk_gl_area_swap_buffers()