comp.lang.ada
 help / color / mirror / Atom feed
* Ada newbie needs help!
@ 2001-04-15 18:27 Michael Andersson
  0 siblings, 0 replies; only message in thread
From: Michael Andersson @ 2001-04-15 18:27 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 243 bytes --]

Hi!
I'm currently working on a little opengl application coded in Ada. The
problem is that the application window just falshes the dies. There
seems to be a problem with my callbacks but I can't find it.
Please help me!!!

/Michael  Andersson

[-- Attachment #2: GUI.adb --]
[-- Type: text/plain, Size: 1917 bytes --]

with Gtk;              use Gtk;
with GL_H;             use GL_H;
with Gtk.Glarea;       use Gtk.Glarea;
with Gtk.Main, Gtk.Widget;
with Gtk.Window;       use Gtk.Window;
with Gdk.GL;           use Gdk.Gl;
with Gtk.Container;    use Gtk.Container;
with Gtk.Widget;       use Gtk.Widget;
with Gtk.Enums;        use Gtk.Enums;
with Gdk.Event;        use Gdk.Event;
with Gtk.Handlers;     use Gtk.Handlers;
with Gdk.Types;        use Gdk.Types;
with OpenGL;           use OpenGL;
with Gtk.Marshallers;   use Gtk.Marshallers;
with Gtk.Signal;        use Gtk.Signal;
with Ada.Text_IO;       use Ada.Text_IO;

procedure GUI is
   package EventRCB is new  Gtk.Handlers.Return_Callback(Gtk_GLArea_Record, Boolean);
   package EventCB is  new Gtk.Handlers.Callback(Gtk_GLArea_Record);
   type GtkGLAreaPtr is access all Gtk_GLArea_Record;
   Window : Gtk_Window;
   Area : GtkGlAreaPtr;
begin
   Gtk.Main.Init;
   Gtk_New(Window, Window_Dialog);
   Gtk.Window.Set_Title(Window,"Simple");
   Gtk.Window.Set_Border_Width(Window,10);
   Gtk.Window.Set_Default_Size(Window,500,500);
   Show(Window);
   Area := new Gtk_GLArea_Record;
   Initialize (Area,(GDK_GL_RGBA,
                     GDK_GL_RED_SIZE, Gl_Configs (1),
                     GDK_GL_GREEN_SIZE, Gl_Configs (1),
                     GDK_GL_BLUE_SIZE, Gl_Configs (1),
                     GDK_GL_DOUBLEBUFFER,
                     GDK_GL_DEPTH_SIZE, Gl_Configs (1)));
   if Area = null then
      Put_Line("Can't recate Gtk_GLArea");
      return;
   end if;
   Set_Events(Area, Exposure_Mask);
   --EventRCB.Connect(Area, "exposure_event", EventRCB.To_Marshaller(Display'Access));
   --EventRCB.Connect(Area, "configure_event", EventRCB.To_Marshaller(Reshape'Access));
   EventRCB.Connect(Area, "realize", EventRCB.To_Marshaller(InitGL'Access));
   --Gtk.Signal.Signal_Connect(Area, "realize", InitGL'Access, null);
   Add(Window, Area);
   Gtk.Main.Main;
end GUI;

[-- Attachment #3: opengl.adb --]
[-- Type: text/plain, Size: 1539 bytes --]

with Gtk.Main;
with Gtk.Window;       use Gtk.Window;
with Glu_H;            use Glu_H;
with GL_H;             use GL_H;
with Gtk.Glarea;       use Gtk.Glarea;
with Gdk.GL;           use Gdk.Gl;
with Ada.Text_IO;      use Ada.Text_IO;
with Gdk.Event;        use Gdk.Event;
with Gtk.Handlers;     use Gtk.Handlers;



package body OpenGL is

function InitGL(Area : access Gtk_GLArea_Record'Class) return Boolean is
begin
   if Make_Current(Area) then
      Glclearcolor(0.0,0.0,0.0,0.0);
      Glenable(GL_DEPTH_TEST);
      Glshademodel(GL_SMOOTH);
      end if;
   return True;
end InitGL;

function Reshape(Area : access Gtk_GLArea_Record'Class; Event : Gdk_Event) return Boolean is
begin
   if Get_Count(Event) > 0 then
      return True;
   end if;

   if Make_Current(Area) then
      Glviewport(0,0,500,500);
      Glmatrixmode(GL_PROJECTION);
      Glloadidentity;
      Gluperspective(Long_Float (45.0), Long_Float(1.3), 1.0,100.0);
      Glmatrixmode(GL_MODELVIEW);
      Glloadidentity;
   end if;
   return True;
end Reshape;

function Display(Area: access Gtk_GLArea_Record'Class; Event : Gdk_Event) return Boolean is
begin
   if Make_Current(Area) then
      Glclear(GL_COLOR_BUFFER_BIT);
      Glclear(GL_DEPTH_BUFFER_BIT);
      Glloadidentity;
      Gltranslatef(0.0,0.0,-5.0);
      Glbegin(GL_QUADS);
      Glvertex3f(-2.0,0.0,0.0);
      Glvertex3f(-2.0,2.0,0.0);
      Glvertex3f(2.0,2.0,0.0);
      Glvertex3f(2.0,0.0,0.0);
      Glend;
      Swap_Buffers(Area);
   end if;
     return True;
end Display;

end OpenGL;

[-- Attachment #4: opengl.ads --]
[-- Type: text/plain, Size: 894 bytes --]

with Gtk;              use Gtk;
with GL_H;             use GL_H;
with Gtk.Glarea;       use Gtk.Glarea;
with Gtk.Main, Gtk.Widget;
with Gtk.Window;       use Gtk.Window;
with Gdk.GL;           use Gdk.Gl;
with Gtk.Container;    use Gtk.Container;
with Gtk.Widget;       use Gtk.Widget;
with Gtk.Enums;        use Gtk.Enums;
with Gdk.Event;        use Gdk.Event;
with Gtk.Handlers;     use Gtk.Handlers;
with Gdk.Types;        use Gdk.Types;
with Gtk.Marshallers;   use Gtk.Marshallers;
with Gtk.Signal;        use Gtk.Signal;
with Ada.Text_IO;       use Ada.Text_IO;
with Glib;              use Glib;

package OpenGL is
   function InitGL(Area : access Gtk_GLArea_Record'Class) return Boolean;
   function Display(Area : access Gtk_GLArea_Record'Class; Event : Gdk_Event) return Boolean;
   function Reshape(Area : access Gtk_GLArea_Record'Class; Event : Gdk_Event) return Boolean;
end OpenGL;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2001-04-15 18:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-15 18:27 Ada newbie needs help! Michael Andersson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox