It is currently Wed Jun 19, 2013 4:57 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 28 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Gtk GL Extension
PostPosted: Tue Jan 10, 2012 3:04 am 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 2506
Location: New Zealand
Got it!

Code:
Macro fillv(V,a,b,c,d)
  v(0) = a
  v(1) = b
  v(2) = c
  v(3) = d
EndMacro

Declare glarea_draw (*widget.GtkWidget,*event.GdkEventExpose)
Procedure glarea_init (*widget.GtkWidget)
 
   If gtk_gl_area_make_current(*widget)
  Global Dim light0_pos.f(4)
  fillv(light0_pos,-50.0, 50.0, 0.0, 0.0);
  Global Dim light0_color.f(4)
  fillv(light0_color, 0.6, 0.6, 0.6, 1.0); /* white light */
  Global Dim light1_pos.f(4)
  fillv(light1_pos,50.0, 50.0, 0.0, 0.0);
  Global Dim light1_color.f(4)
  fillv(light1_color,0.4, 0.4, 1.0, 1.0);  /* cold blue light */

  glEnable(#GL_DEPTH_TEST);
  glEnable(#GL_CULL_FACE)
  ;/* speedups */
  glEnable(#GL_DITHER);
  glShadeModel(#GL_SMOOTH);
  glHint(#GL_PERSPECTIVE_CORRECTION_HINT, #GL_FASTEST);
  glHint(#GL_POLYGON_SMOOTH_HINT, #GL_FASTEST);

  ;/* light */
  glLightfv(#GL_LIGHT0, #GL_POSITION, @light0_pos);
  glLightfv(#GL_LIGHT0, #GL_DIFFUSE,  @light0_color);
  glLightfv(#GL_LIGHT1, #GL_POSITION, @light1_pos);
  glLightfv(#GL_LIGHT1, #GL_DIFFUSE,  @light1_color);
  glEnable(#GL_LIGHT0);
  glEnable(#GL_LIGHT1);
  glEnable(#GL_LIGHTING);

  glColorMaterial(#GL_FRONT_AND_BACK,#GL_AMBIENT_AND_DIFFUSE);
  glEnable(#GL_COLOR_MATERIAL);
 
 
 
  ginit = 1
 
EndIf
 
  ProcedureReturn 1

EndProcedure

Procedure glarea_reshape(*widget.GtkWidget,*event.GdkEventConfigure)
 
  w =*widget\parent\allocation\width;
  h = *widget\parent\allocation\height;
  If gtk_gl_area_make_current(*widget)
    glMatrixMode(#GL_PROJECTION)
    glLoadIdentity()
    gluPerspective(45.0, w/h, 0.1, 1000.0)
    glMatrixMode(#GL_MODELVIEW)
    glViewport(0,0, w,h);
     
  Else
    Debug "fail"
  EndIf
  ProcedureReturn 1;

EndProcedure

Procedure glarea_draw (*widget.GtkWidget,*event.GdkEventExpose)
  Static rot.f
   Static shp
  If gtk_gl_area_make_current(*widget)
   
   rot+0.1 
  glClear(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
  glClearColor(0,0,0,1);
  glLoadIdentity();                   // Reset The View
  glTranslatef(0,0,-5);             
  glRotatef(rot,0.0,1.0,1.0);             // Rotate The Pyramid On It's Y Axis
   
  glbegin(#GL_TRIANGLES)
  glColor3f(255,0.0,0.0);          // Red
  glVertex3f( 0.0,1.0,0.0);          // Top Of Triangle (Front)
  glColor3f(0.0,255,0.0);          // Green
  glVertex3f(-1.0,-1.0, 1.0);          // Left Of Triangle (Front)
  glColor3f(0.0,0.0,255);          // Blue
  glVertex3f( 1.0,-1.0, 1.0);          // Right Of Triangle (Front)
   
  glColor3f(255,0.0,0.0);          // Red
  glVertex3f( 0.0, 1.0, 0.0);          // Top Of Triangle (Right)
  glColor3f(0.0,0.0,255);          // Blue
  glVertex3f( 1.0,-1.0, 1.0);          // Left Of Triangle (Right)
  glColor3f(0.0,255,0.0);          // Green
  glVertex3f( 1.0,-1.0, -1.0);         // Right Of Triangle (Right)
 
  glColor3f(255,0.0,0.0);          // Red
  glVertex3f( 0.0, 1.0,0.0);          // Top Of Triangle (Back)
  glColor3f(0.0,255,0.0);          // Green
  glVertex3f( 1.0,-1.0, -1.0);         // Left Of Triangle (Back)
  glColor3f(0.0,0.0,255);          // Blue
  glVertex3f(-1.0,-1.0, -1.0);         // Right Of Triangle (Back)

  glColor3f(255,0.0,0.0);          // Red
  glVertex3f( 0.0, 1.0, 0.0);          // Top Of Triangle (Left)
  glColor3f(0.0,0.0,255);          // Blue
  glVertex3f(-1.0,-1.0,-1.0);          // Left Of Triangle (Left)
  glColor3f(0.0,255,0.0);          // Green
  glVertex3f(-1.0,-1.0, 1.0);          // Right Of Triangle (Left)
  glEnd();                        // Done Drawing The Pyramid
 
  gtk_gl_area_swap_buffers(*widget);
 
  ;Debug "draw"
Else
  Debug "fail"
EndIf

 ProcedureReturn 1

EndProcedure

Global glarea ,ctg,win

Procedure Ireshape(*widget.GtkWidget,*allocation.GtkAllocation,*vData)
   gtk_widget_set_size_request_(*vdata,*allocation\width,*allocation\height)
EndProcedure 

Procedure glarea_Create(x,y,w,h)
  Protected tglarea,ctg
  Dim ats(4) : ats(0)=#GDK_GL_RGBA : ats(1)=#GDK_GL_DOUBLEBUFFER : ats(2) = #GDK_GL_DEPTH_SIZE
  ats(3) = 1 : ats(4) = #GDK_NONE
  ctg = ContainerGadget(#PB_Any,x,y,w,h)
  tglarea = gtk_gl_area_new(@ats(0))
  SetGadgetData(ctg,tglarea)
  g_signal_connect_(GadgetID(ctg), "size-allocate",@Ireshape(),tglarea)
  gtk_widget_set_events_(tglarea,#GDK_EXPOSURE_MASK|#GDK_BUTTON_PRESS_MASK|#GDK_BUTTON_RELEASE_MASK|#GDK_POINTER_MOTION_MASK|#GDK_POINTER_MOTION_HINT_MASK);
  g_signal_connect_(tglarea,"realize",@glarea_init(),0);
  g_signal_connect_(tglarea,"expose_event",@glarea_draw(),0);
  g_signal_connect_(tglarea, "configure_event",@glarea_reshape(),0)
  gtk_widget_set_usize_(tglarea,w,h);
  gtk_container_add_(GadgetID(ctg), tglarea);  ;need to attach it to something
  CloseGadgetList()
  gtk_widget_show_(tglarea);
  ProcedureReturn ctg 
EndProcedure   

If  OpenWindow(#PB_Any, 0, 0, 800, 600, "ContainerGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
SetWindowCallback(@WinManCallBack(),0)
   
  glarea1 = glarea_Create(0,0,0,0)
  glarea2 = glarea_Create(0,0,0,0)
  glarea3=  glarea_Create(0,0,0,0)
  glarea4 = glarea_Create(0,0,0,0)
 
 
  #Separateur1 = 4
  #Separateur2 = 5
  #Separateur3 = 6
 
  SplitterGadget(#Separateur1, 0, 0, 0, 0, glarea1, glarea2, #PB_Splitter_Separator)
  SplitterGadget(#Separateur2, 0, 0, 0, 0, glarea3, glarea4, #PB_Splitter_Separator)
  SplitterGadget(#Separateur3, 5, 5, 790, 590, #Separateur1, #Separateur2, #PB_Splitter_Separator|#PB_Splitter_Vertical)
 
   
  Repeat
   
    glarea_draw(GetGadgetData(glarea1),0) 
    glarea_draw(GetGadgetData(glarea2),0)
    glarea_draw(GetGadgetData(glarea3),0) 
    glarea_draw(GetGadgetData(glarea4),0)
   
   
    EventID = WaitWindowEvent(10)
   
    Select EventID
       
      Case #PB_Event_Menu
       
        Select EventMenu()
           
        EndSelect
       
      Case #PB_Event_Gadget
       
        Select EventGadget()

        EndSelect
       
       
    EndSelect
   
  Until EventID = #PB_Event_CloseWindow
 


Top
 Profile  
 
 Post subject: Re: Gtk GL Extension
PostPosted: Tue Jan 10, 2012 3:11 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Oct 22, 2003 2:51 am
Posts: 734
Location: Canada
Now I need to combine Your advancement with WindowResize() and everything will be fine.

Edit : To have the Window Resize feature, a simple ResizeGadget(#Separateur3, #PB_Ignore, #PB_Ignore, WindowWidth(0)-10, WindowHeight(0) - 10) do the job.
A gentle reminder, it's impossible to compile in Unicode mode.

Best regards.
Guimauve


Top
 Profile  
 
 Post subject: Re: Gtk GL Extension
PostPosted: Tue Jan 10, 2012 4:00 am 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 2506
Location: New Zealand
something still needs to be done to update the window, when you restore it.
I added
Code:
Case #PB_Event_SizeWindow 
      ResizeGadget(#Separateur3, 5, 5, WindowWidth(0)-10,WindowHeight(0)-10)
    Case #PB_Event_RestoreWindow
      ResizeGadget(#Separateur3, 5, 5, WindowWidth(0)-10,WindowHeight(0)-10)


but there's an issue with the restore.

I was just looking into the unicode issue
You'd think it'd be fine with Unicode, perhaps it's a bug with the macro definition?
and being a macro I guess that rules out using a prototype to cast the string to Ascii


Image


Top
 Profile  
 
 Post subject: Re: Gtk GL Extension
PostPosted: Tue Jan 10, 2012 4:22 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Oct 22, 2003 2:51 am
Posts: 734
Location: Canada
Hello,

The much simpler way to handle Size and Restore Window :
Code:
Case #PB_Event_SizeWindow, #PB_Event_RestoreWindow
   ResizeGadget(#Separateur3, #PB_Ignore, #PB_Ignore, WindowWidth(0)-10,WindowHeight(0)-10)

Thanks for your work !

Best regards.
Guimauve


Top
 Profile  
 
 Post subject: Re: Gtk GL Extension
PostPosted: Tue Jan 10, 2012 5:21 am 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 2506
Location: New Zealand
Guimauve wrote:
Hello,

The much simpler way to handle Size and Restore Window :
Code:
Case #PB_Event_SizeWindow, #PB_Event_RestoreWindow
   ResizeGadget(#Separateur3, #PB_Ignore, #PB_Ignore, WindowWidth(0)-10,WindowHeight(0)-10)

Thanks for your work !

Best regards.
Guimauve


yes it is! though I still can't work out how to get the splitter to redraw after maximize and restore.
Beer time here anyway!

Your welcome!


Top
 Profile  
 
 Post subject: Re: Gtk GL Extension
PostPosted: Tue Jan 10, 2012 5:30 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Oct 22, 2003 2:51 am
Posts: 734
Location: Canada
It's very strange because here with Linux Mint 12 x64 everything work fine.

Question : Do you use the proprietary video driver ?

Best regards
Guimauve


Top
 Profile  
 
 Post subject: Re: Gtk GL Extension
PostPosted: Tue Jan 10, 2012 5:36 am 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 2506
Location: New Zealand
yes ATI's one, doesn't work well without it, though.
I'm on ubuntu 11.04 with unity disabled

Image


Top
 Profile  
 
 Post subject: Re: Gtk GL Extension
PostPosted: Tue Jan 10, 2012 8:20 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Oct 22, 2003 2:51 am
Posts: 734
Location: Canada
Hello everyone,

A little update, now The GLAreaGadget can be defined by User Constant or #PB_Any

Code:
Procedure GLAreaGadget(GadgetID, x, y, w, h)
 
  Protected tglarea, ctg
 
  Dim ats(4) : ats(0)=#GDK_GL_RGBA : ats(1)=#GDK_GL_DOUBLEBUFFER : ats(2) = #GDK_GL_DEPTH_SIZE
  ats(3) = 1 : ats(4) = #GDK_NONE
 
  ctg = ContainerGadget(GadgetID,x,y,w,h)
   
    tglarea = gtk_gl_area_new(@ats(0))
   
    gtk_widget_set_events_(tglarea,#GDK_EXPOSURE_MASK|#GDK_BUTTON_PRESS_MASK|#GDK_BUTTON_RELEASE_MASK|#GDK_POINTER_MOTION_MASK|#GDK_POINTER_MOTION_HINT_MASK)
    g_signal_connect_(tglarea,"realize",@glarea_init(),0)
    g_signal_connect_(tglarea,"expose_event",@glarea_draw(),0)
    g_signal_connect_(tglarea, "configure_event",@glarea_reshape(),0)
   
    If GadgetID = #PB_Any
      SetGadgetData(ctg, tglarea)
      g_signal_connect_(GadgetID(ctg), "size-allocate", @Ireshape(), tglarea)
      gtk_container_add_(GadgetID(ctg), tglarea)
    Else
      SetGadgetData(GadgetID, tglarea)
      g_signal_connect_(GadgetID(GadgetID), "size-allocate", @Ireshape(), tglarea)
      gtk_container_add_(GadgetID(GadgetID), tglarea)
    EndIf

  CloseGadgetList()
 
  gtk_widget_set_usize_(tglarea, w, h)
  gtk_widget_show_(tglarea)
 
  ProcedureReturn ctg 
EndProcedure   

Enumeration
 
  #GLArea1
  #GLArea2
  #Separateur1
  #Separateur2
  #Separateur3
 
EndEnumeration

If OpenWindow(0, 0, 0, 800, 600, "GLAreaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget) 
 
  GLAreaGadget(#GLArea1, 0, 0, 0, 0)
  GLAreaGadget(#GLArea2, 0, 0, 0, 0)
  GLArea3 = GLAreaGadget(#PB_Any, 0, 0, 0, 0)
  GLArea4 = GLAreaGadget(#PB_Any, 0, 0, 0, 0)
 
  SplitterGadget(#Separateur1, 0, 0, 0, 0, #GLArea1, #GLArea2, #PB_Splitter_Separator)
  SplitterGadget(#Separateur2, 0, 0, 0, 0, GLArea3, GLArea4, #PB_Splitter_Separator)
  SplitterGadget(#Separateur3, 5, 5, 790, 590, #Separateur1, #Separateur2, #PB_Splitter_Separator|#PB_Splitter_Vertical)

  Repeat
   
    glarea_draw(GetGadgetData(#GLArea1), 0) 
    glarea_draw(GetGadgetData(#GLArea2), 0)
    glarea_draw(GetGadgetData(GLArea3), 0) 
    glarea_draw(GetGadgetData(GLArea4), 0)
   
    EventID = WaitWindowEvent(5)
   
    Select EventID
       
      Case #PB_Event_Menu
       
        Select EventMenu()
           
        EndSelect
       
      Case #PB_Event_Gadget
       
        Select EventGadget()
           
        EndSelect
       
      Case #PB_Event_SizeWindow
        ResizeGadget(#Separateur3, #PB_Ignore, #PB_Ignore, WindowWidth(0) - 10, WindowHeight(0) - 10)
       
    EndSelect
   
  Until EventID = #PB_Event_CloseWindow
 
EndIf


Best regards.
Guimauve


Top
 Profile  
 
 Post subject: Re: Gtk GL Extension
PostPosted: Tue Jan 10, 2012 8:39 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 2506
Location: New Zealand
If you change the draw routine to the below you can remove the GetGadgetData from the main loop

I'll see if I can figure out what the redraw issue is on my system today.

Code:

Procedure glarea_draw (*widget.GtkWidget,*event.GdkEventExpose=0)
  Static rot.f
  Static shp
 
  If Not *event
     *widget = GetGadgetData(*widget)
  EndIf
 
  If gtk_gl_area_make_current(*widget)



Top
 Profile  
 
 Post subject: Re: Gtk GL Extension
PostPosted: Wed Jan 11, 2012 8:14 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Oct 22, 2003 2:51 am
Posts: 734
Location: Canada
Hello,

Now the question is : how to add event like :

Code:
#PB_EventType_MouseEnter        ; The mouse cursor entered the gadget
#PB_EventType_MouseLeave        ; The mouse cursor left the gadget
#PB_EventType_MouseMove         ; The mouse cursor moved
#PB_EventType_MouseWheel        ; The mouse wheel was moved
#PB_EventType_LeftButtonDown    ; The left mouse button was pressed
#PB_EventType_LeftButtonUp      ; The left mouse button was released
#PB_EventType_LeftClick         ; A click With the left mouse button
#PB_EventType_LeftDoubleClick   ; A double-click With the left mouse button
#PB_EventType_RightButtonDown   ; The right mouse button was pressed
#PB_EventType_RightButtonUp     ; The right mouse button was released
#PB_EventType_RightClick        ; A click With the right mouse button
#PB_EventType_RightDoubleClick  ; A double-click With the right mouse button
#PB_EventType_MiddleButtonDown  ; The middle mouse button was pressed
#PB_EventType_MiddleButtonUp    ; The middle mouse button was released
#PB_EventType_Focus             ; The gadget gained keyboard focus
#PB_EventType_LostFocus         ; The gadget lost keyboard focus

to the GLAreaGadget() ?

Using the ContainerGadget() to attach the GtkGLArea widget is a working solution for the rendering process but Event processing it's a different story. I have begin to study the GObject Reference Manuel to figure out if it's possible to add event signal and finally add some custom event processing system. I'm not sure if sending events to the PB event system is possible. With SDL we can add custom event to the event processing system but for this project I would like to stay way from this library.

Best regards.
Guimauve


Top
 Profile  
 
 Post subject: Re: Gtk GL Extension
PostPosted: Wed Jan 11, 2012 10:11 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 2506
Location: New Zealand
I don't know how to post messages into the PB event queue like you would in windows

I'd abstact it to something like this

Code:
ImportC "-gtk"
EndImport

Declare GadgetEvent(gadget,EventType,Value)

ProcedureC onScroll(*widget.GtkWidget,*event.GdkEventScroll,pbID)
  GadgetEvent(pbId,#PB_EventType_MouseWheel ,*event\direction)
  ProcedureReturn 1
EndProcedure 

Procedure GadgetEvent(gadget,EventType,Value)
   
  Select EventType 
    Case #PB_EventType_MouseWheel
      Debug "gadget " + Str(Gadget)
      Debug "Direction " + Str(value)
  EndSelect
 
 EndProcedure

OpenWindow(1,0,0,200,100,"g_signalConnect")
ButtonGadget(2,5,5,60,20,"OK")

g_signal_connect_(GadgetID(2),"scroll-event",@onScroll(),2)

Repeat
  Ev = WaitWindowEvent()
  evg = EventGadget()
  If Ev
    If  evg = 2 
      Debug EventType()
    EndIf
  EndIf
Until Ev = #PB_Event_CloseWindow




Top
 Profile  
 
 Post subject: Re: Gtk GL Extension
PostPosted: Wed Jan 11, 2012 10:31 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Oct 22, 2003 2:51 am
Posts: 734
Location: Canada
How it work it's not very important. Hacking to the system to work are more important.

By the way, where I can found the g_signal_connect_() signal definition list ? (For example the "scroll-event" and all of it's brothers)

Best regards
Guimauve


Top
 Profile  
 
 Post subject: Re: Gtk GL Extension
PostPosted: Thu Jan 12, 2012 6:49 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 2506
Location: New Zealand
each widget can have these and then look up the specific widget to see the additional signals

http://developer.gnome.org/gtk/2.24/Gtk ... et.signals


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 28 posts ]  Go to page Previous  1, 2

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye