Bien le bonjour ! j'ai une erreur de linkage assez bizarre
voici mon glGtk.ml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 make make[1]: Entering directory `/home/kulssaka/EHK/Yama_no_Me' ocamldep -native -I glGtk/ -I glcaml/ glGtk/glGtk.mli > ._ncdi/glGtk/glGtk.di ocamldep -native -I glGtk/ -I glcaml/ glcaml/glcaml.mli > ._ncdi/glcaml/glcaml.di ocamldep -I glGtk/ -I glcaml/ source2.ml > ._d/source2.d ocamldep -I glGtk/ -I glcaml/ glGtk/glGtk.ml > ._d/glGtk/glGtk.d ocamldep -I glGtk/ -I glcaml/ glcaml/glcaml.ml > ._d/glcaml/glcaml.d make[1]: Leaving directory `/home/kulssaka/EHK/Yama_no_Me' make[1]: Entering directory `/home/kulssaka/EHK/Yama_no_Me' ocamlc -c -I glGtk/ -I glcaml/ -I +sdl -I +lablgtk2 -I +lablgl glcaml/glcaml.mli ocamlopt -c -I glGtk/ -I glcaml/ -I +sdl -I +lablgtk2 -I +lablgl glcaml/glcaml.ml ocamlc -c -I glGtk/ -I glcaml/ -I +sdl -I +lablgtk2 -I +lablgl glGtk/glGtk.mli ocamlopt -c -I glGtk/ -I glcaml/ -I +sdl -I +lablgtk2 -I +lablgl glGtk/glGtk.ml ocamlopt -c -I glGtk/ -I glcaml/ -I +sdl -I +lablgtk2 -I +lablgl source2.ml File "source2.ml", line 49, characters 5-9: Warning Y: unused variable area. File "source2.ml", line 34, characters 6-54: Warning S: this expression should have type unit. File "source2.ml", line 39, characters 4-117: Warning S: this expression should have type unit. File "source2.ml", line 43, characters 4-112: Warning S: this expression should have type unit. ocamlc -c -cc "cc" -ccopt " \ -DNATIVE_CODE \ -IglGtk/ -Iglcaml/ -I+sdl -I+lablgtk2 -I+lablgl -o glcaml/glcaml_stub.o " glcaml/glcaml_stub.c ocamlopt \ \ -I glGtk/ -I glcaml/ -I +sdl -I +lablgtk2 -I +lablgl bigarray.cmxa sdl.cmxa lablgtk.cmxa lablglade.cmxa lablgl.cmxa gtkInit.cmx -ccopt -LglGtk/ -ccopt -Lglcaml/ glcaml/glcaml_stub.o -o source2 \ glcaml/glcaml.cmx glGtk/glGtk.cmx source2.cmx glGtk/glGtk.o: In function `camlGlGtk__fun_302': (.text+0x11): undefined reference to `ml_gtk_gl_area_make_current' glGtk/glGtk.o: In function `camlGlGtk__fun_294': (.text+0x65): undefined reference to `ml_gtk_gl_area_make_current' glGtk/glGtk.o: In function `camlGlGtk__fun_286': (.text+0xf7): undefined reference to `ml_gtk_gl_area_make_current' glGtk/glGtk.o: In function `camlGlGtk__method_make_current_257': (.text+0x378): undefined reference to `ml_gtk_gl_area_make_current' glGtk/glGtk.o: In function `camlGlGtk__method_swap_buffers_260': (.text+0x3e8): undefined reference to `ml_gtk_gl_area_swap_buffers' glGtk/glGtk.o: In function `camlGlGtk__area_201': (.text+0x84c): undefined reference to `ml_gtk_gl_area_new' glGtk/glGtk.o: In function `camlGlGtk__19': (.data+0x2ac): undefined reference to `ml_gtk_gl_area_make_current' glGtk/glGtk.o: In function `camlGlGtk__19': (.data+0x2b0): undefined reference to `ml_gtk_gl_area_swap_buffers' glGtk/glGtk.o: In function `camlGlGtk__19': (.data+0x2b4): undefined reference to `ml_gtk_gl_area_new' collect2: ld returned 1 exit status File "caml_startup", line 1, characters 0-1: Error: Error during linking make[1]: *** [source2] Error 2 make[1]: Leaving directory `/home/kulssaka/EHK/Yama_no_Me' make: *** [native-code] Error 2
Et voila mon makefile :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 (**************************************************************************) (* Lablgtk *) (* *) (* This program is free software; you can redistribute it *) (* and/or modify it under the terms of the GNU Library General *) (* Public License as published by the Free Software Foundation *) (* version 2, with the exception described in file COPYING which *) (* comes with the library. *) (* *) (* This program is distributed in the hope that it will be useful, *) (* but WITHOUT ANY WARRANTY; without even the implied warranty of *) (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *) (* GNU Library General Public License for more details. *) (* *) (* You should have received a copy of the GNU Library General *) (* Public License along with this program; if not, write to the *) (* Free Software Foundation, Inc., 59 Temple Place, Suite 330, *) (* Boston, MA 02111-1307 USA *) (* *) (* *) (**************************************************************************) (* $Id: glGtk.ml 1347 2007-06-20 07:40:34Z guesdon $ *) open Gaux open Gtk type visual_options = [ | `USE_GL | `BUFFER_SIZE of int | `LEVEL of int | `RGBA | `DOUBLEBUFFER | `STEREO | `AUX_BUFFERS of int | `RED_SIZE of int | `GREEN_SIZE of int | `BLUE_SIZE of int | `ALPHA_SIZE of int | `DEPTH_SIZE of int | `STENCIL_SIZE of int | `ACCUM_GREEN_SIZE of int | `ACCUM_ALPHA_SIZE of int ] type gl_area = [Gtk.drawing_area|`glarea] module GtkRaw = struct external create : visual_options list -> share:[>`glarea] optobj -> gl_area obj = "ml_gtk_gl_area_new" external swap_buffers : [>`glarea] obj -> unit = "ml_gtk_gl_area_swap_buffers" external make_current : [>`glarea] obj -> bool = "ml_gtk_gl_area_make_current" end class area_signals obj = object (connect) inherit GObj.widget_signals_impl (obj : [> gl_area] obj) method display ~callback = (new GObj.event_signals obj)#after#expose ~callback: begin fun ev -> if GdkEvent.Expose.count ev = 0 then if GtkRaw.make_current obj then callback () else prerr_endline "GlGtk-WARNING **: could not make current"; true end method reshape ~callback = (new GObj.event_signals obj)#after#configure ~callback: begin fun ev -> if GtkRaw.make_current obj then begin callback ~width:(GdkEvent.Configure.width ev) ~height:(GdkEvent.Configure.height ev) end else prerr_endline "GlGtk-WARNING **: could not make current"; true end method realize ~callback = (new GObj.misc_signals (obj :> Gtk.widget obj))#after#realize ~callback: begin fun ev -> if GtkRaw.make_current obj then callback () else prerr_endline "GlGtk-WARNING **: could not make current" end end class area obj = object (self) inherit GObj.widget (obj : gl_area obj) method as_area = obj method event = new GObj.event_ops obj method connect = new area_signals obj method set_size = GtkMisc.DrawingArea.size obj method swap_buffers () = GtkRaw.swap_buffers obj method make_current () = if not (GtkRaw.make_current obj) then raise (Gl.GLerror "make_current") end let area options ?share ?(width=0) ?(height=0) ?packing ?show () = let share = match share with Some (x : area) -> Some x#as_area | None -> None in let w = GtkRaw.create options ~share:(Gpointer.optboxed share) in if width <> 0 || height <> 0 then GtkMisc.DrawingArea.size w ~width ~height; GtkBase.Widget.add_events w [`EXPOSURE]; GObj.pack_return (new area w) ~packing ~show let region_of_raw raw = Gpointer.unsafe_create_region ~path:[|1|] ~get_length:Raw.byte_size raw
Pour le projet les sources sont :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 all: native-code GLCAML = glcaml/glcaml_stub.c glcaml/glcaml.mli glcaml/glcaml.ml GLGTK = glGtk/glGtk.ml glGtk/glGtk.mli SOURCES = $(GLCAML) $(GLGTK) gladeconverter.ml RESULT = gladeconverter INCDIRS = +sdl +lablgtk2 +lablgl CMXA = bigarray.cmxa sdl.cmxa lablgtk.cmxa lablglade.cmxa lablgl.cmxa lablgtkgl.cmxa OCAMLNLDFLAGS = $(CMXA) gtkInit.cmx -include OCamlMakefile
le fichier glade en xml de test :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234 (*gladeconverter.ml*) (*OpenGl part*) let rtri = ref 0.0 let rquad = ref 0.0 let resizeGLScene ~width ~height = let ok_height = if height = 0 then 1 else height in GlDraw.viewport 0 0 width ok_height; GlMat.mode `projection; GlMat.load_identity (); GluMat.perspective ~fovy:45.0 ~aspect:((float_of_int width)/.(float_of_int ok_height)) ~z:(0.1, 100.0); GlMat.mode `modelview; GlMat.load_identity () let initGL () = GlDraw.shade_model `smooth; GlClear.color ~alpha:0.0 (0.0, 0.0, 0.0); GlClear.depth 1.0; Gl.enable `depth_test; GlFunc.depth_func `lequal; GlMisc.hint `perspective_correction `nicest let draw area () = GlClear.clear [`color; `depth]; GlMat.load_identity (); GlMat.translate ~x:(-1.5) ~y:0.0 ~z:(-6.0) (); GlMat.rotate ~angle:!rtri ~x:0.0 ~y:1.0 ~z:0.0 (); GlDraw.begins `triangles; GlDraw.color (1.0, 0.0, 0.0); GlDraw.vertex3 (0.0, 1.0, 0.0); GlDraw.color (0.0, 1.0, 0.0); GlDraw.vertex3 (-1.0, -1.0, 0.0); GlDraw.color (0.0, 0.0, 1.0); GlDraw.vertex3 (1.0, -1.0, 0.0); GlDraw.ends (); GlMat.load_identity (); GlMat.translate ~x:1.5 ~y:0.0 ~z:(-6.0) (); GlMat.rotate ~angle:!rquad ~x:1.0 ~y:0.0 ~z:0.0 (); GlDraw.color (0.5, 0.5, 1.0); GlDraw.begins `quads; GlDraw.vertex3 (-1.0, 1.0, 0.0); GlDraw.vertex3 (1.0, 1.0, 0.0); GlDraw.vertex3 (1.0, -1.0, 0.0); GlDraw.vertex3 (-1.0, -1.0, 0.0); GlDraw.ends (); rtri := !rtri +. 0.2; rquad := !rquad -. 0.15; area#swap_buffers () let xml = Glade.create ~file:"gl.glade" () let load_xml () = (*Creating the window*) let widget = Glade.get_widget xml "window1" in let window = new GWindow.window (GtkWindow.Window.cast widget) in ignore( window#connect#destroy ~callback:GMain.Main.quit); (*Creating the useless quit test button*) let widget = Glade.get_widget xml "Quit" in let button = new GButton.button (GtkButton.Button.cast widget) in ignore( button#connect#clicked ~callback:(fun () -> print_endline "Bye"; window#destroy (); GMain.quit ())); (*Creating the Quit menu*) let widget = Glade.get_widget xml "EXIT" in let item = new GMenu.menu_item (GtkMenu.MenuItem.cast widget) in ignore( item#connect#activate ~callback:(fun () -> print_endline "Bye"; window#destroy (); GMain.quit ())); (*Creating the GLarea*) let widget = Glade.get_widget xml "Area" in let frame = new GBin.aspect_frame (GtkBin.AspectFrame.cast widget) in let area = GlGtk.area [ `RGBA; `DOUBLEBUFFER;`DEPTH_SIZE 16; `USE_GL] ~packing:frame#add () in ignore(area#connect#realize ~callback: (fun () -> initGL (); resizeGLScene 800 800 )); ignore(GMain.Timeout.add ~ms:20 ~callback: (fun () -> draw area ();true)); ignore(area#connect#display ~callback: (fun () -> draw area () )); (*End of xml*) window#show (); GMain.main () let main () = load_xml () let _ = main () kulssaka@ubuntu:~/EHK/Yama_no_Me$ cat gladeconverter.ml (*gladeconverter.ml*) (*OpenGl part*) let rtri = ref 0.0 let rquad = ref 0.0 let resizeGLScene ~width ~height = let ok_height = if height = 0 then 1 else height in GlDraw.viewport 0 0 width ok_height; GlMat.mode `projection; GlMat.load_identity (); GluMat.perspective ~fovy:45.0 ~aspect:((float_of_int width)/.(float_of_int ok_height)) ~z:(0.1, 100.0); GlMat.mode `modelview; GlMat.load_identity () let initGL () = GlDraw.shade_model `smooth; GlClear.color ~alpha:0.0 (0.0, 0.0, 0.0); GlClear.depth 1.0; Gl.enable `depth_test; GlFunc.depth_func `lequal; GlMisc.hint `perspective_correction `nicest let draw area () = GlClear.clear [`color; `depth]; GlMat.load_identity (); GlMat.translate ~x:(-1.5) ~y:0.0 ~z:(-6.0) (); GlMat.rotate ~angle:!rtri ~x:0.0 ~y:1.0 ~z:0.0 (); GlDraw.begins `triangles; GlDraw.color (1.0, 0.0, 0.0); GlDraw.vertex3 (0.0, 1.0, 0.0); GlDraw.color (0.0, 1.0, 0.0); GlDraw.vertex3 (-1.0, -1.0, 0.0); GlDraw.color (0.0, 0.0, 1.0); GlDraw.vertex3 (1.0, -1.0, 0.0); GlDraw.ends (); GlMat.load_identity (); GlMat.translate ~x:1.5 ~y:0.0 ~z:(-6.0) (); GlMat.rotate ~angle:!rquad ~x:1.0 ~y:0.0 ~z:0.0 (); GlDraw.color (0.5, 0.5, 1.0); GlDraw.begins `quads; GlDraw.vertex3 (-1.0, 1.0, 0.0); GlDraw.vertex3 (1.0, 1.0, 0.0); GlDraw.vertex3 (1.0, -1.0, 0.0); GlDraw.vertex3 (-1.0, -1.0, 0.0); GlDraw.ends (); rtri := !rtri +. 0.2; rquad := !rquad -. 0.15; area#swap_buffers () let xml = Glade.create ~file:"gl.glade" () let load_xml () = (*Creating the window*) let widget = Glade.get_widget xml "window1" in let window = new GWindow.window (GtkWindow.Window.cast widget) in ignore( window#connect#destroy ~callback:GMain.Main.quit); (*Creating the useless quit test button*) let widget = Glade.get_widget xml "Quit" in let button = new GButton.button (GtkButton.Button.cast widget) in ignore( button#connect#clicked ~callback:(fun () -> print_endline "Bye"; window#destroy (); GMain.quit ())); (*Creating the Quit menu*) let widget = Glade.get_widget xml "EXIT" in let item = new GMenu.menu_item (GtkMenu.MenuItem.cast widget) in ignore( item#connect#activate ~callback:(fun () -> print_endline "Bye"; window#destroy (); GMain.quit ())); (*Creating the GLarea*) let widget = Glade.get_widget xml "Area" in let frame = new GBin.aspect_frame (GtkBin.AspectFrame.cast widget) in let area = GlGtk.area [ `RGBA; `DOUBLEBUFFER;`DEPTH_SIZE 16; `USE_GL] ~packing:frame#add () in ignore(area#connect#realize ~callback: (fun () -> initGL (); resizeGLScene 800 800 )); ignore(GMain.Timeout.add ~ms:20 ~callback: (fun () -> draw area ();true)); ignore(area#connect#display ~callback: (fun () -> draw area () )); (*End of xml*) window#show (); GMain.main () let main () = load_xml () let _ = main ()
Le but etant de creer une fenetre affichant de l'OpenGl dans la frame nommee GlArea
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?xml version="1.0"?> <glade-interface> <!-- interface-requires gtk+ 2.16 --> <!-- interface-naming-policy project-wide --> <widget class="GtkWindow" id="window1"> <property name="title" translatable="yes">Yama no Me</property> <child> <widget class="GtkFixed" id="fixed1"> <property name="visible">True</property> <child> <widget class="GtkMenuBar" id="menubar1"> <property name="width_request">944</property> <property name="height_request">26</property> <property name="visible">True</property> <child> <widget class="GtkMenuItem" id="menuitem1"> <property name="visible">True</property> <property name="label" translatable="yes">_File</property> <property name="use_underline">True</property> <child> <widget class="GtkMenu" id="menu1"> <property name="visible">True</property> <child> <widget class="GtkImageMenuItem" id="Load"> <property name="label">_Load Map</property> <property name="visible">True</property> <property name="use_underline">True</property> <property name="use_stock">False</property> <child internal-child="image"> <widget class="GtkImage" id="image1"> <property name="visible">True</property> <property name="stock">gtk-select-color</property> </widget> </child> </widget> </child> <child> <widget class="GtkSeparatorMenuItem" id="separatormenuitem1"> <property name="visible">True</property> </widget> </child> <child> <widget class="GtkImageMenuItem" id="EXIT"> <property name="label">gtk-quit</property> <property name="visible">True</property> <property name="use_underline">True</property> <property name="use_stock">True</property> </widget> </child> </widget> </child> </widget> </child> </widget> </child> <child> <widget class="GtkButton" id="Quit"> <property name="label">gtk-quit</property> <property name="width_request">144</property> <property name="height_request">799</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> <property name="use_stock">True</property> </widget> <packing> <property name="x">800</property> <property name="y">27</property> </packing> </child> <child> <widget class="GtkAspectFrame" id="Area"> <property name="width_request">800</property> <property name="height_request">800</property> <property name="visible">True</property> <property name="label_xalign">0</property> <property name="shadow_type">none</property> <property name="obey_child">False</property> <child> <placeholder/> </child> </widget> <packing> <property name="y">26</property> </packing> </child> </widget> </child> </widget> </glade-interface>
Partager