diff --git a/Makefile.am b/Makefile.am index fe5940bc9..c38f8c07b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -33,7 +33,6 @@ SUBDIRS = \ @media_dir@ \ @jit_dir@ \ @httpd_dir@ \ - @opengl_sge_dir@ \ @openssl_dir@ \ @openal_dir@ \ comp \ diff --git a/app/src/gambas3/.lang/.pot b/app/src/gambas3/.lang/.pot index 54011ec13..ac9a43999 100644 --- a/app/src/gambas3/.lang/.pot +++ b/app/src/gambas3/.lang/.pot @@ -558,7 +558,7 @@ msgstr "" #: FConnectionEditor.class:294 FCreateFile.form:437 FDebugInfo.form:263 #: FEditor.class:2379 FExportData.class:126 FFieldChooser.form:138 #: FFileProperty.class:140 FFontChooser.form:40 FForm.class:3141 -#: FGotoLine.form:23 FHelpBrowser.form:61 FImageEditor.class:346 +#: FGotoLine.form:23 FHelpBrowser.form:61 FImageEditor.class:347 #: FImageOffsetSelection.form:33 FImageResize.form:49 FImageRotate.form:32 #: FInfo.class:263 FList.form:121 FMain.class:212 FMakeInstall.class:350 #: FMenu.form:365 FNewConnection.form:255 FNewTable.form:86 @@ -1631,7 +1631,7 @@ msgstr "" msgid "Procedure list" msgstr "" -#: FEditor.class:2379 FImageEditor.class:346 FTextEditor.class:599 +#: FEditor.class:2379 FImageEditor.class:347 FTextEditor.class:599 msgid "" "The file has been modified.\n" "\n" diff --git a/app/src/gambas3/.src/Editor/Image/FImageEditor.class b/app/src/gambas3/.src/Editor/Image/FImageEditor.class index c4381d5b7..4c1690f87 100644 --- a/app/src/gambas3/.src/Editor/Image/FImageEditor.class +++ b/app/src/gambas3/.src/Editor/Image/FImageEditor.class @@ -89,6 +89,7 @@ Private Sub ClearSelection() $hMagnet = Null $hLastMagnet = Null $sMagnet = "" + $iChangeAction = CHANGE_NOTHING RefreshSelection End @@ -2665,6 +2666,7 @@ Private Sub ClearPaste() $hPasteSelect = Null $hPasteCurrent = Null imvImage.Refresh + $iChangeAction = CHANGE_NOTHING Endif End diff --git a/configure.ac b/configure.ac index f12d8ed3d..08baaa688 100644 --- a/configure.ac +++ b/configure.ac @@ -42,7 +42,6 @@ GB_CONFIG_SUBDIRS(ncurses, gb.ncurses) GB_CONFIG_SUBDIRS(media, gb.media) GB_CONFIG_SUBDIRS(jit, gb.jit) GB_CONFIG_SUBDIRS(httpd, gb.httpd) -GB_CONFIG_SUBDIRS(opengl_sge, gb.opengl.sge) GB_CONFIG_SUBDIRS(openssl, gb.openssl) GB_CONFIG_SUBDIRS(openal, gb.openal) diff --git a/examples/examples/OpenGL/Md2Model/.icon.png b/examples/examples/OpenGL/Md2Model/.icon.png index 8748600ba..f9972fedc 100644 Binary files a/examples/examples/OpenGL/Md2Model/.icon.png and b/examples/examples/OpenGL/Md2Model/.icon.png differ diff --git a/examples/examples/OpenGL/Md2Model/.project b/examples/examples/OpenGL/Md2Model/.project index 41225bec1..59d721658 100644 --- a/examples/examples/OpenGL/Md2Model/.project +++ b/examples/examples/OpenGL/Md2Model/.project @@ -1,17 +1,18 @@ # Gambas Project File 3.0 -# Compiled with Gambas 3.4.0 -Title=screen -Startup=MMain -Version=0.0.1 +# Compiled with Gambas 3.4.90 +Title=Md2Model example +Startup=FMain +Icon=icon.png +Version=3.4.90 +VersionFile=1 Component=gb.image +Component=gb.gui Component=gb.db Component=gb.db.mysql -Component=gb.image.io -Component=gb.sdl +Component=gb.gui.opengl Component=gb.opengl Component=gb.opengl.glu Component=gb.opengl.sge -Component=gb.sdl.sound +Environment="GB_GUI=gb.qt4" TabSize=2 -Warnings=0 Packager=1 diff --git a/examples/examples/OpenGL/Md2Model/.settings b/examples/examples/OpenGL/Md2Model/.settings index ad0cde567..cd746252e 100644 --- a/examples/examples/OpenGL/Md2Model/.settings +++ b/examples/examples/OpenGL/Md2Model/.settings @@ -96,9 +96,10 @@ SearchComment=False SearchString=True [OpenFile] -Active=1 -File[1]=".src/MMain.module:126.2" -Count=1 +File[1]=".src/FMain.form" +Active=2 +File[2]=".src/FMain.class:147.25" +Count=2 [Watches] Count=0 diff --git a/examples/examples/OpenGL/Md2Model/.src/FMain.class b/examples/examples/OpenGL/Md2Model/.src/FMain.class new file mode 100644 index 000000000..a4fe07f2d --- /dev/null +++ b/examples/examples/OpenGL/Md2Model/.src/FMain.class @@ -0,0 +1,183 @@ +' Gambas class file + +Private $aModel As Md2Model[] +Private $iFrames As Integer +Private $fTime As Single +Private $fFramerate As Float +Private $iEndWidth As Integer +Private $iEndZ As Integer + +Public Sub glaScreen_Open() + + Init() + Gl.ClearDepth(100.0) ' Enables clearing of the depth buffer + Glu.ClearColor(&H3398C3) ' This will clear the background color to blue + Gl.DepthFunc(Gl.LESS) ' The type of depth test to do + Gl.Enable(Gl.DEPTH_TEST) ' Enables depth testing + Gl.ShadeModel(Gl.SMOOTH) ' Enables smooth color shading + + $fTime = Timer + timAnim.Enabled = True + +End + +Public Sub glaScreen_Resize() + + Gl.Viewport(0, 0, glaScreen.Width, glaScreen.Height) + Gl.MatrixMode(Gl.PROJECTION) + Gl.LoadIdentity() 'Reset The Projection Matrix + Glu.Perspective(45.0, glaScreen.Width / glaScreen.Height, 0.1, 3000.0) 'Calculate The Aspect Ratio Of The Window + Glu.Lookat(0, 100, 120, 0, 0, -300, 0, 100, 0) + Gl.MatrixMode(Gl.MODELVIEW) + +End + +Public Sub Init() + + Dim X, D, Z As Float + Dim sModel As String + Dim I As Integer + Dim aModel As String[] = ["bauul", "goblin", "knight", "ogro", "rat", "rhino"] + + $aModel = New Md2Model[] + + D = 100 + + X = - D + Z = -100 + + For I = 1 To 189 + + sModel = aModel[Int(Rnd(0, aModel.Count))] + + $aModel.Add(Md2Model.Load(sModel & ".md2")) + $aModel[$aModel.Max].Texture = LoadTexture(sModel & ".jpg") + 'Print "Model #"; $aModel.Max; ": "; $aModel[$aModel.Max].Count; " frames" + $aModel[$aModel.Max].Move(X, -10, Z) + X += 50 + If X > D Then + D += 100 + X = - D + Z -= 100 + Endif + + Next + + $iEndWidth = D + $iEndZ = Z + + sldFrame.MinValue = 0 + sldFrame.MaxValue = $aModel[0].Count + +End + + +Public Sub glaScreen_Draw() + + Dim I As Integer + Dim hQuadric As GluQuadric + + Gl.Clear(Gl.COLOR_BUFFER_BIT Or Gl.DEPTH_BUFFER_BIT) ' Clear The Screen And The Depth Buffer + + Gl.PushMatrix + + Glu.Color(&HD96800&) + Gl.Begin(Gl.QUADS) + Gl.Vertex3f(-100, -34.2, -100) + Gl.Vertex3f(100, -34.2, -100) + Gl.Vertex3f($iEndWidth, -34.2, $iEndZ) + Gl.Vertex3f(- $iEndWidth, -34.2, $iEndZ) + Gl.End + + 'Drawing model is as easy as this - frame number, interpolation between frames (0-1), texture identificator) + ' + Gl.Color3f(1, 1, 1) + For I = 0 To $aModel.Max + $aModel[I].Draw + Next + + For I = 0 To $aModel.Max + Glu.Color(Color.Lighter(&HD96800&)) + hQuadric = Glu.NewQuadric() + Gl.PushMatrix() + Gl.Translatef($aModel[I].X, -34, $aModel[I].Z) + Gl.Rotatef(90, 1, 0, 0) + Glu.Disk(hQuadric, 0, 20, 20, 8) + Gl.PopMatrix() + Next + + ' You can use this code to get FPS printed in terminal + + Inc $iFrames + If Timer >= ($fTime + 1) Then + $fFrameRate = $iFrames / (Timer - $fTime) + $iFrames = 0 + Inc $fTime + Endif + + lblInfo.Text = Format($aModel[0].Pos, "0.00") & " / " & $aModel[0].Count & " ( " & CInt($fFramerate) & " FPS )" + + Gl.PopMatrix + +End + +Public Sub Form_KeyPress() + + If Key.code = Key.F1 Then + Me.FullScreen = Not Me.FullScreen + sldFrame.Visible = Not Me.FullScreen + Else If Key.Code = Key.Esc Then + Me.Close + Else If Key.code = Key.Space Then + timAnim.Enabled = Not timAnim.Enabled + Else If LCase(Key.Text) = "w" Then + Gl.PolygonMode(Gl.FRONT_AND_BACK, Gl.LINE) + Else If LCase(Key.Text) = "f" Then + Gl.PolygonMode(Gl.FRONT_AND_BACK, Gl.FILL) + Endif + +End + +Public Sub timAnim_Timer() + + ' At every timer call we increase interpolation. It makes Frame number increase every 10 calls. + ' You can control frame flow any way you want. The smaller incrementation, the smoother movement. + + Dim I As Integer + + For I = 0 To $aModel.Max + $aModel[I].Pos += 0.1 + If $aModel[I].Pos >= $aModel[I].Count Then $aModel[I].Pos = 0 + Next + + Object.Lock(sldFrame) + sldFrame.Value = CInt($aModel[0].Pos) + Object.Unlock(sldFrame) + + glaScreen.Refresh + +End + +' Just the subroutine to load textures for our models +Private Sub LoadTexture(sPath As String) As Integer + + Dim iTex As Integer + Dim hImage As Image + + iTex = Gl.GenTextures(1)[0] + hImage = Image.Load(sPath) + Gl.BindTexture(Gl.TEXTURE_2D, iTex) + Gl.TexImage2D(hImage) + Glu.Build2DMipmaps(hImage) + Gl.Texparameteri(Gl.TEXTURE_2D, Gl.TEXTURE_MIN_FILTER, Gl.LINEAR_MIPMAP_LINEAR) + Gl.Texparameteri(Gl.TEXTURE_2D, Gl.TEXTURE_MAG_FILTER, Gl.LINEAR) + Return iTex + +End + + +Public Sub sldFrame_Change() + + $aModel[0].Pos = sldFrame.Value + +End diff --git a/examples/examples/OpenGL/Md2Model/.src/FMain.form b/examples/examples/OpenGL/Md2Model/.src/FMain.form new file mode 100644 index 000000000..7e29b68b6 --- /dev/null +++ b/examples/examples/OpenGL/Md2Model/.src/FMain.form @@ -0,0 +1,28 @@ +# Gambas Form File 3.0 + +{ Form Form + MoveScaled(0,0,160,72) + Arrangement = Arrange.Vertical + { Panel1 HBox + MoveScaled(1,2,116,4) + Spacing = True + { sldFrame Slider + MoveScaled(0,0,24,4) + Expand = True + } + { Separator1 Separator + MoveScaled(54,0,0,4) + } + { lblInfo Label + MoveScaled(64,0,18,4) + } + } + { timAnim #Timer + #MoveScaled(51,13) + Delay = 20 + } + { glaScreen GLArea + MoveScaled(4,14,16,16) + Expand = True + } +} diff --git a/examples/examples/OpenGL/Md2Model/.src/MMain.module b/examples/examples/OpenGL/Md2Model/.src/MMain.module deleted file mode 100644 index 882a4d3b8..000000000 --- a/examples/examples/OpenGL/Md2Model/.src/MMain.module +++ /dev/null @@ -1,138 +0,0 @@ -' Gambas module file - -'This example shows how to use new experimental component gb.sge (Simple Game Engine) -'New class Md2Model alows to load and render quake md2 models. -' - -' Gambas module file -Private screen As New Window(True) As "Screen" -Private frames As Integer -Private CTime As Single -Private hTimer As New Timer As "Timer1" -Private ogre As Md2Model -Private gun As Md2Model -Private interp As Float -Public f_no As Integer -Private texture As New Integer[2] - - - - -Public Sub Main() -' Standard OpenGL screen init - With screen - .Width = 640 - .Height = 480 - ' .Framerate = 50 - .Show() - End With - CTime = Timer() - hTimer.Delay = 20 - hTimer.Enabled = True - -End -Public Sub Screen_Open() - - init() - Gl.ClearDepth(100.0) 'Enables Clearing Of The Depth Buffer - gl.ClearColor(0.1, 0.1, 0.6, 0.0) 'This Will Clear The Background Color To Blue - gl.DepthFunc(GL.LESS) 'The Type Of Depth Test To Do - gl.Enable(GL.DEPTH_TEST) 'Enables Depth Testing - gl.ShadeModel(GL.SMOOTH) 'Enables Smooth Color Shading - -End - -Public Sub Screen_resize() -Dim i As Integer - - Gl.Viewport(0, 0, Screen.Width, Screen.Height) - Gl.MatrixMode(GL.PROJECTION) - Gl.LoadIdentity() 'Reset The Projection Matrix - glu.Perspective(45.0, screen.Width / screen.Height, 0.1, 400.0) 'Calculate The Aspect Ratio Of The Window - Gl.MatrixMode(GL.MODELVIEW) -End - -Public Sub init() -Dim s As String - gl.Enable(gl.TEXTURE_2D) ' Enable Texture Mapping - texture = Gl.GenTextures(3) ' reserve memory for textures - load_textures(0, "igdosh.png") 'Ogre body texture - load_textures(1, "Weapon.png") 'Weapon texture - - ogre = Md2Model.Load("Ogros.md2") 'ogre model loading - it's static method use md2model.load(name) - ogre.SetPosition(0, -10, -100) 'Set position for model - gun = Md2Model.Load("Weapon.md2") - gun.SetPosition(0, -10, -100) - 'That's it - model ready to be rendered frame count and looping in timer sub - -End - - -Public Sub Screen_Draw() -Dim calc, i As Integer - - gl.Clear(GL.COLOR_BUFFER_BIT Or GL.DEPTH_BUFFER_BIT) ' Clear The Screen And The Depth Buffer - gl.LoadIdentity() - gl.Color3f(1, 1, 1) - 'Drawing model is as easy as this - frame number, interpolation between frames (0-1), texture identificator) - ogre.DrawInterFrame(f_no, interp, texture[0]) - gun.DrawInterFrame(f_no, interp, texture[1]) - - 'Now some info on the screen - it slows down rendering by more than 50%!!! Uncomment and see. - - 'gl.Translatef(-3, 3, -8) - 'gl.Rotatef(180, 1, 0, 0) - 'gl.Scalef(1 / 50, 1 / 50, 1 / 50) - 'Draw.Text(Screen.Framerate & " FPS, " & "Frame no " & f_no & " " & Trim(ogre.GetFrameName(f_no)), 0, 0) '" - 10,800 squares. SPACE - turn shader on/off", 0, 0) - - 'You can use this code to get FPS printed in terminal - - Inc (Frames) - If (Timer() > CTime + 5) Then - calc = Timer() - CTime - Print CStr(Frames) & " frames in " & Format$(calc, "#.0") & " seconds = " & Format$((Frames / calc), "######.000") & " FPS" - Frames = 0 - CTime = Timer() - Endif - -End - -Public Sub Screen_keyPress() -Dim i, j As Integer - - If (key.code = key.F1) Then screen.FullScreen = Not screen.FullScreen - If (key.Code = key.Esc) Then Screen.Close() - If (Key.code = Key.Space) Then hTimer.Enabled = Not hTimer.Enabled - If (key.Text = "w") Then gl.PolygonMode(gl.FRONT_and_back, gl.line) - If (key.Text = "f") Then gl.PolygonMode(gl.FRONT_and_back, gl.fill) - -End - -Public Sub Timer1_Timer() - - ' At every timer call we increase interpolation. It makes Frame number increase every 20 calls. - ' You can control frame flow any way you want. The smaller iterp, the smoother movement. - interp += 0.05 - If interp >= 1 Then - Inc f_no - If f_no > ogre.GetFramesNo() Then f_no = 0 'use ogre.getframesno() to get number of frames in model animation - interp = 0 - Endif - -End - -' Just the subroutine to load textures for our models -Public Sub load_textures(no As Integer, name As String) - - Dim texture_image As Image - Dim i As Integer - - texture_image = Image.Load(name) - Gl.BindTexture(gl.TEXTURE_2D, texture[no]) - Gl.TexImage2D(texture_image) - Glu.Build2DMipmaps(texture_image) - Gl.Texparameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.linear_mipmap_linear) - Gl.Texparameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR) - -End - diff --git a/examples/examples/OpenGL/Md2Model/.startup b/examples/examples/OpenGL/Md2Model/.startup index f4d66c93e..23096c7c1 100644 --- a/examples/examples/OpenGL/Md2Model/.startup +++ b/examples/examples/OpenGL/Md2Model/.startup @@ -1,16 +1,15 @@ -MMain -screen +FMain +Md2Model example 0 0 -0.0.1 +3.4.90 gb.image +gb.gui gb.db gb.db.mysql -gb.image.io -gb.sdl +gb.gui.opengl gb.opengl gb.opengl.glu gb.opengl.sge -gb.sdl.sound diff --git a/examples/examples/OpenGL/Md2Model/bauul.jpg b/examples/examples/OpenGL/Md2Model/bauul.jpg new file mode 100644 index 000000000..403d146f6 Binary files /dev/null and b/examples/examples/OpenGL/Md2Model/bauul.jpg differ diff --git a/examples/examples/OpenGL/Md2Model/bauul.md2 b/examples/examples/OpenGL/Md2Model/bauul.md2 new file mode 100644 index 000000000..573491c61 Binary files /dev/null and b/examples/examples/OpenGL/Md2Model/bauul.md2 differ diff --git a/examples/examples/OpenGL/Md2Model/goblin.jpg b/examples/examples/OpenGL/Md2Model/goblin.jpg new file mode 100644 index 000000000..0dcd98d0d Binary files /dev/null and b/examples/examples/OpenGL/Md2Model/goblin.jpg differ diff --git a/examples/examples/OpenGL/Md2Model/goblin.md2 b/examples/examples/OpenGL/Md2Model/goblin.md2 new file mode 100644 index 000000000..33266c410 Binary files /dev/null and b/examples/examples/OpenGL/Md2Model/goblin.md2 differ diff --git a/examples/examples/OpenGL/Md2Model/icon.png b/examples/examples/OpenGL/Md2Model/icon.png new file mode 100644 index 000000000..2766afa9d Binary files /dev/null and b/examples/examples/OpenGL/Md2Model/icon.png differ diff --git a/examples/examples/OpenGL/Md2Model/knight.jpg b/examples/examples/OpenGL/Md2Model/knight.jpg new file mode 100644 index 000000000..632ffc1e6 Binary files /dev/null and b/examples/examples/OpenGL/Md2Model/knight.jpg differ diff --git a/examples/examples/OpenGL/Md2Model/knight.md2 b/examples/examples/OpenGL/Md2Model/knight.md2 new file mode 100644 index 000000000..c8ab12aa9 Binary files /dev/null and b/examples/examples/OpenGL/Md2Model/knight.md2 differ diff --git a/examples/examples/OpenGL/Md2Model/ogro.jpg b/examples/examples/OpenGL/Md2Model/ogro.jpg new file mode 100644 index 000000000..3a8758a67 Binary files /dev/null and b/examples/examples/OpenGL/Md2Model/ogro.jpg differ diff --git a/examples/examples/OpenGL/Md2Model/Ogros.md2 b/examples/examples/OpenGL/Md2Model/ogro.md2 similarity index 100% rename from examples/examples/OpenGL/Md2Model/Ogros.md2 rename to examples/examples/OpenGL/Md2Model/ogro.md2 diff --git a/examples/examples/OpenGL/Md2Model/rat.jpg b/examples/examples/OpenGL/Md2Model/rat.jpg new file mode 100644 index 000000000..12e33d5c1 Binary files /dev/null and b/examples/examples/OpenGL/Md2Model/rat.jpg differ diff --git a/examples/examples/OpenGL/Md2Model/rat.md2 b/examples/examples/OpenGL/Md2Model/rat.md2 new file mode 100644 index 000000000..17658597f Binary files /dev/null and b/examples/examples/OpenGL/Md2Model/rat.md2 differ diff --git a/examples/examples/OpenGL/Md2Model/rhino.jpg b/examples/examples/OpenGL/Md2Model/rhino.jpg new file mode 100644 index 000000000..50d07fcad Binary files /dev/null and b/examples/examples/OpenGL/Md2Model/rhino.jpg differ diff --git a/examples/examples/OpenGL/Md2Model/rhino.md2 b/examples/examples/OpenGL/Md2Model/rhino.md2 new file mode 100644 index 000000000..ea10ef227 Binary files /dev/null and b/examples/examples/OpenGL/Md2Model/rhino.md2 differ diff --git a/gb.gtk/src/CTrayIcon.cpp b/gb.gtk/src/CTrayIcon.cpp index 80412d394..b0504792a 100644 --- a/gb.gtk/src/CTrayIcon.cpp +++ b/gb.gtk/src/CTrayIcon.cpp @@ -180,13 +180,20 @@ END_METHOD BEGIN_METHOD_VOID(CTRAYICON_hide) TRAYICON->hide(); + MAIN_check_quit(); END_METHOD BEGIN_PROPERTY(CTRAYICON_visible) - if (READ_PROPERTY) { GB.ReturnBoolean(TRAYICON->isVisible()); return; } - TRAYICON->setVisible(VPROP(GB_BOOLEAN)); + if (READ_PROPERTY) + GB.ReturnBoolean(TRAYICON->isVisible()); + else + { + TRAYICON->setVisible(VPROP(GB_BOOLEAN)); + if (!VPROP(GB_BOOLEAN)) + MAIN_check_quit(); + } END_PROPERTY diff --git a/gb.gtk/src/CTrayIcon.h b/gb.gtk/src/CTrayIcon.h index f75d8fab1..e16672c7d 100644 --- a/gb.gtk/src/CTrayIcon.h +++ b/gb.gtk/src/CTrayIcon.h @@ -28,13 +28,16 @@ #include "gtrayicon.h" #include "CPicture.h" - #ifndef __CTRAYICON_CPP + extern GB_DESC CTrayIconDesc[]; extern GB_DESC CTrayIconsDesc[]; + #else + #define THIS ((CTRAYICON *)_object) #define TRAYICON ((gTrayIcon *)(THIS->base.widget)) + #endif typedef diff --git a/gb.gtk/src/gtrayicon.cpp b/gb.gtk/src/gtrayicon.cpp index 8bfc68ce7..04fe3f21c 100644 --- a/gb.gtk/src/gtrayicon.cpp +++ b/gb.gtk/src/gtrayicon.cpp @@ -47,6 +47,7 @@ #define OPCODE "_NET_SYSTEM_TRAY_OPCODE" +int gTrayIcon::_visible_count = 0; /***************************************************************************** @@ -425,6 +426,8 @@ void gTrayIcon::setVisible(bool vl) updateTooltip(); refresh(); + + _visible_count++; } } @@ -433,6 +436,7 @@ void gTrayIcon::setVisible(bool vl) if (plug) { gtk_widget_destroy(plug); + _visible_count--; } } } diff --git a/gb.gtk/src/gtrayicon.h b/gb.gtk/src/gtrayicon.h index acd0e768c..2a277f1be 100644 --- a/gb.gtk/src/gtrayicon.h +++ b/gb.gtk/src/gtrayicon.h @@ -66,6 +66,7 @@ public: //"Static" static int count() { return g_list_length(trayicons); } + static int visibleCount() { return _visible_count; } static gTrayIcon *get(int index) { return (gTrayIcon *)g_list_nth_data(trayicons, index); } static void exit(); static gPicture *defaultIcon(); @@ -87,6 +88,7 @@ public: private: + static int _visible_count; GtkStyle *_style; }; diff --git a/gb.gtk/src/main.cpp b/gb.gtk/src/main.cpp index e5de989d0..232b6bbf2 100644 --- a/gb.gtk/src/main.cpp +++ b/gb.gtk/src/main.cpp @@ -475,7 +475,7 @@ static int my_loop() { if (_must_check_quit) { - if (CWINDOW_must_quit() && CWatcher::count() == 0) + if (CWINDOW_must_quit() && CWatcher::count() == 0 && gTrayIcon::visibleCount() == 0) break; _must_check_quit = false; } diff --git a/gb.opengl.sge/AUTHORS b/gb.opengl.sge/AUTHORS deleted file mode 100644 index e69de29bb..000000000 diff --git a/gb.opengl.sge/COPYING b/gb.opengl.sge/COPYING deleted file mode 120000 index 012065c85..000000000 --- a/gb.opengl.sge/COPYING +++ /dev/null @@ -1 +0,0 @@ -../COPYING \ No newline at end of file diff --git a/gb.opengl.sge/ChangeLog b/gb.opengl.sge/ChangeLog deleted file mode 100644 index e69de29bb..000000000 diff --git a/gb.opengl.sge/INSTALL b/gb.opengl.sge/INSTALL deleted file mode 120000 index 99d491b4f..000000000 --- a/gb.opengl.sge/INSTALL +++ /dev/null @@ -1 +0,0 @@ -../INSTALL \ No newline at end of file diff --git a/gb.opengl.sge/Makefile.am b/gb.opengl.sge/Makefile.am deleted file mode 100644 index f51d5299a..000000000 --- a/gb.opengl.sge/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -ACLOCAL_AMFLAGS = -I m4 --install -SUBDIRS = @OPENGL_SGE_DIR@ -EXTRA_DIST = reconf gambas.h gb*.h diff --git a/gb.opengl.sge/NEWS b/gb.opengl.sge/NEWS deleted file mode 100644 index e69de29bb..000000000 diff --git a/gb.opengl.sge/README b/gb.opengl.sge/README deleted file mode 100644 index e69de29bb..000000000 diff --git a/gb.opengl.sge/acinclude.m4 b/gb.opengl.sge/acinclude.m4 deleted file mode 120000 index d84c32a31..000000000 --- a/gb.opengl.sge/acinclude.m4 +++ /dev/null @@ -1 +0,0 @@ -../acinclude.m4 \ No newline at end of file diff --git a/gb.opengl.sge/component.am b/gb.opengl.sge/component.am deleted file mode 120000 index 2f0eee34f..000000000 --- a/gb.opengl.sge/component.am +++ /dev/null @@ -1 +0,0 @@ -../component.am \ No newline at end of file diff --git a/gb.opengl.sge/configure.ac b/gb.opengl.sge/configure.ac deleted file mode 100644 index d50a956ce..000000000 --- a/gb.opengl.sge/configure.ac +++ /dev/null @@ -1,20 +0,0 @@ -dnl ---- configure.ac for gb.opengl.sge - -AC_INIT(configure.ac) -AC_CONFIG_MACRO_DIR([m4]) -GB_INIT(gb.opengl.sge) -AC_PROG_LIBTOOL - - -GB_CHECK_XWINDOW -GB_COMPONENT( - opengl_sge, - OPENGL_SGE, - gb.opengl.sge, - [src], - [GB_FIND(gl.h glu.h glew.h, /usr/local/lib /usr/local /usr/lib /usr, opengl.sge/include include opengl.sge*/include opengl.sge)], - [GB_FIND(libGL.$SHLIBEXT libGLEW.$SHLIBEXT libGLU.$SHLIBEXT, /usr/local /usr, lib)], - [$C_LIB $THREAD_LIB -ljpeg -lpng -lGL -lGLEW -lGLU], - [$THREAD_INC -ljpeg -lpng -lGL -lGLEW -lGLU]) -AC_OUTPUT( Makefile src/Makefile ) -GB_PRINT_MESSAGES diff --git a/gb.opengl.sge/gambas.h b/gb.opengl.sge/gambas.h deleted file mode 120000 index 03677ecd0..000000000 --- a/gb.opengl.sge/gambas.h +++ /dev/null @@ -1 +0,0 @@ -../main/share/gambas.h \ No newline at end of file diff --git a/gb.opengl.sge/gb_common.h b/gb.opengl.sge/gb_common.h deleted file mode 120000 index 707d79da6..000000000 --- a/gb.opengl.sge/gb_common.h +++ /dev/null @@ -1 +0,0 @@ -../main/share/gb_common.h \ No newline at end of file diff --git a/gb.opengl.sge/m4 b/gb.opengl.sge/m4 deleted file mode 120000 index 7d49a2a4b..000000000 --- a/gb.opengl.sge/m4 +++ /dev/null @@ -1 +0,0 @@ -../m4 \ No newline at end of file diff --git a/gb.opengl.sge/missing b/gb.opengl.sge/missing deleted file mode 120000 index f3ade9ba1..000000000 --- a/gb.opengl.sge/missing +++ /dev/null @@ -1 +0,0 @@ -../missing \ No newline at end of file diff --git a/gb.opengl.sge/reconf b/gb.opengl.sge/reconf deleted file mode 120000 index 48a376da6..000000000 --- a/gb.opengl.sge/reconf +++ /dev/null @@ -1 +0,0 @@ -../reconf \ No newline at end of file diff --git a/gb.opengl.sge/src/cmd2model.c b/gb.opengl.sge/src/cmd2model.c deleted file mode 100644 index 2b808e990..000000000 --- a/gb.opengl.sge/src/cmd2model.c +++ /dev/null @@ -1,477 +0,0 @@ -/*************************************************************************** - - CMD2MODEL.c - - (c) 2012 Tomasz Kołodziejczyk "Tommyline" - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - MA 02110-1301, USA. - -***************************************************************************/ - -#define __CMD2MODEL_C - -#include "gb_common.h" -#include "cmd2model.h" -#include - -#define THIS OBJECT(MD2MODEL) - -/* Table of precalculated normals */ - GLfloat anorms_table[162][3] = { -{ -0.525731f, 0.000000f, 0.850651f }, -{ -0.442863f, 0.238856f, 0.864188f }, -{ -0.295242f, 0.000000f, 0.955423f }, -{ -0.309017f, 0.500000f, 0.809017f }, -{ -0.162460f, 0.262866f, 0.951056f }, -{ 0.000000f, 0.000000f, 1.000000f }, -{ 0.000000f, 0.850651f, 0.525731f }, -{ -0.147621f, 0.716567f, 0.681718f }, -{ 0.147621f, 0.716567f, 0.681718f }, -{ 0.000000f, 0.525731f, 0.850651f }, -{ 0.309017f, 0.500000f, 0.809017f }, -{ 0.525731f, 0.000000f, 0.850651f }, -{ 0.295242f, 0.000000f, 0.955423f }, -{ 0.442863f, 0.238856f, 0.864188f }, -{ 0.162460f, 0.262866f, 0.951056f }, -{ -0.681718f, 0.147621f, 0.716567f }, -{ -0.809017f, 0.309017f, 0.500000f }, -{ -0.587785f, 0.425325f, 0.688191f }, -{ -0.850651f, 0.525731f, 0.000000f }, -{ -0.864188f, 0.442863f, 0.238856f }, -{ -0.716567f, 0.681718f, 0.147621f }, -{ -0.688191f, 0.587785f, 0.425325f }, -{ -0.500000f, 0.809017f, 0.309017f }, -{ -0.238856f, 0.864188f, 0.442863f }, -{ -0.425325f, 0.688191f, 0.587785f }, -{ -0.716567f, 0.681718f, -0.147621f }, -{ -0.500000f, 0.809017f, -0.309017f }, -{ -0.525731f, 0.850651f, 0.000000f }, -{ 0.000000f, 0.850651f, -0.525731f }, -{ -0.238856f, 0.864188f, -0.442863f }, -{ 0.000000f, 0.955423f, -0.295242f }, -{ -0.262866f, 0.951056f, -0.162460f }, -{ 0.000000f, 1.000000f, 0.000000f }, -{ 0.000000f, 0.955423f, 0.295242f }, -{ -0.262866f, 0.951056f, 0.162460f }, -{ 0.238856f, 0.864188f, 0.442863f }, -{ 0.262866f, 0.951056f, 0.162460f }, -{ 0.500000f, 0.809017f, 0.309017f }, -{ 0.238856f, 0.864188f, -0.442863f }, -{ 0.262866f, 0.951056f, -0.162460f }, -{ 0.500000f, 0.809017f, -0.309017f }, -{ 0.850651f, 0.525731f, 0.000000f }, -{ 0.716567f, 0.681718f, 0.147621f }, -{ 0.716567f, 0.681718f, -0.147621f }, -{ 0.525731f, 0.850651f, 0.000000f }, -{ 0.425325f, 0.688191f, 0.587785f }, -{ 0.864188f, 0.442863f, 0.238856f }, -{ 0.688191f, 0.587785f, 0.425325f }, -{ 0.809017f, 0.309017f, 0.500000f }, -{ 0.681718f, 0.147621f, 0.716567f }, -{ 0.587785f, 0.425325f, 0.688191f }, -{ 0.955423f, 0.295242f, 0.000000f }, -{ 1.000000f, 0.000000f, 0.000000f }, -{ 0.951056f, 0.162460f, 0.262866f }, -{ 0.850651f, -0.525731f, 0.000000f }, -{ 0.955423f, -0.295242f, 0.000000f }, -{ 0.864188f, -0.442863f, 0.238856f }, -{ 0.951056f, -0.162460f, 0.262866f }, -{ 0.809017f, -0.309017f, 0.500000f }, -{ 0.681718f, -0.147621f, 0.716567f }, -{ 0.850651f, 0.000000f, 0.525731f }, -{ 0.864188f, 0.442863f, -0.238856f }, -{ 0.809017f, 0.309017f, -0.500000f }, -{ 0.951056f, 0.162460f, -0.262866f }, -{ 0.525731f, 0.000000f, -0.850651f }, -{ 0.681718f, 0.147621f, -0.716567f }, -{ 0.681718f, -0.147621f, -0.716567f }, -{ 0.850651f, 0.000000f, -0.525731f }, -{ 0.809017f, -0.309017f, -0.500000f }, -{ 0.864188f, -0.442863f, -0.238856f }, -{ 0.951056f, -0.162460f, -0.262866f }, -{ 0.147621f, 0.716567f, -0.681718f }, -{ 0.309017f, 0.500000f, -0.809017f }, -{ 0.425325f, 0.688191f, -0.587785f }, -{ 0.442863f, 0.238856f, -0.864188f }, -{ 0.587785f, 0.425325f, -0.688191f }, -{ 0.688191f, 0.587785f, -0.425325f }, -{ -0.147621f, 0.716567f, -0.681718f }, -{ -0.309017f, 0.500000f, -0.809017f }, -{ 0.000000f, 0.525731f, -0.850651f }, -{ -0.525731f, 0.000000f, -0.850651f }, -{ -0.442863f, 0.238856f, -0.864188f }, -{ -0.295242f, 0.000000f, -0.955423f }, -{ -0.162460f, 0.262866f, -0.951056f }, -{ 0.000000f, 0.000000f, -1.000000f }, -{ 0.295242f, 0.000000f, -0.955423f }, -{ 0.162460f, 0.262866f, -0.951056f }, -{ -0.442863f, -0.238856f, -0.864188f }, -{ -0.309017f, -0.500000f, -0.809017f }, -{ -0.162460f, -0.262866f, -0.951056f }, -{ 0.000000f, -0.850651f, -0.525731f }, -{ -0.147621f, -0.716567f, -0.681718f }, -{ 0.147621f, -0.716567f, -0.681718f }, -{ 0.000000f, -0.525731f, -0.850651f }, -{ 0.309017f, -0.500000f, -0.809017f }, -{ 0.442863f, -0.238856f, -0.864188f }, -{ 0.162460f, -0.262866f, -0.951056f }, -{ 0.238856f, -0.864188f, -0.442863f }, -{ 0.500000f, -0.809017f, -0.309017f }, -{ 0.425325f, -0.688191f, -0.587785f }, -{ 0.716567f, -0.681718f, -0.147621f }, -{ 0.688191f, -0.587785f, -0.425325f }, -{ 0.587785f, -0.425325f, -0.688191f }, -{ 0.000000f, -0.955423f, -0.295242f }, -{ 0.000000f, -1.000000f, 0.000000f }, -{ 0.262866f, -0.951056f, -0.162460f }, -{ 0.000000f, -0.850651f, 0.525731f }, -{ 0.000000f, -0.955423f, 0.295242f }, -{ 0.238856f, -0.864188f, 0.442863f }, -{ 0.262866f, -0.951056f, 0.162460f }, -{ 0.500000f, -0.809017f, 0.309017f }, -{ 0.716567f, -0.681718f, 0.147621f }, -{ 0.525731f, -0.850651f, 0.000000f }, -{ -0.238856f, -0.864188f, -0.442863f }, -{ -0.500000f, -0.809017f, -0.309017f }, -{ -0.262866f, -0.951056f, -0.162460f }, -{ -0.850651f, -0.525731f, 0.000000f }, -{ -0.716567f, -0.681718f, -0.147621f }, -{ -0.716567f, -0.681718f, 0.147621f }, -{ -0.525731f, -0.850651f, 0.000000f }, -{ -0.500000f, -0.809017f, 0.309017f }, -{ -0.238856f, -0.864188f, 0.442863f }, -{ -0.262866f, -0.951056f, 0.162460f }, -{ -0.864188f, -0.442863f, 0.238856f }, -{ -0.809017f, -0.309017f, 0.500000f }, -{ -0.688191f, -0.587785f, 0.425325f }, -{ -0.681718f, -0.147621f, 0.716567f }, -{ -0.442863f, -0.238856f, 0.864188f }, -{ -0.587785f, -0.425325f, 0.688191f }, -{ -0.309017f, -0.500000f, 0.809017f }, -{ -0.147621f, -0.716567f, 0.681718f }, -{ -0.425325f, -0.688191f, 0.587785f }, -{ -0.162460f, -0.262866f, 0.951056f }, -{ 0.442863f, -0.238856f, 0.864188f }, -{ 0.162460f, -0.262866f, 0.951056f }, -{ 0.309017f, -0.500000f, 0.809017f }, -{ 0.147621f, -0.716567f, 0.681718f }, -{ 0.000000f, -0.525731f, 0.850651f }, -{ 0.425325f, -0.688191f, 0.587785f }, -{ 0.587785f, -0.425325f, 0.688191f }, -{ 0.688191f, -0.587785f, 0.425325f }, -{ -0.955423f, 0.295242f, 0.000000f }, -{ -0.951056f, 0.162460f, 0.262866f }, -{ -1.000000f, 0.000000f, 0.000000f }, -{ -0.850651f, 0.000000f, 0.525731f }, -{ -0.955423f, -0.295242f, 0.000000f }, -{ -0.951056f, -0.162460f, 0.262866f }, -{ -0.864188f, 0.442863f, -0.238856f }, -{ -0.951056f, 0.162460f, -0.262866f }, -{ -0.809017f, 0.309017f, -0.500000f }, -{ -0.864188f, -0.442863f, -0.238856f }, -{ -0.951056f, -0.162460f, -0.262866f }, -{ -0.809017f, -0.309017f, -0.500000f }, -{ -0.681718f, 0.147621f, -0.716567f }, -{ -0.681718f, -0.147621f, -0.716567f }, -{ -0.850651f, 0.000000f, -0.525731f }, -{ -0.688191f, 0.587785f, -0.425325f }, -{ -0.587785f, 0.425325f, -0.688191f }, -{ -0.425325f, 0.688191f, -0.587785f }, -{ -0.425325f, -0.688191f, -0.587785f }, -{ -0.587785f, -0.425325f, -0.688191f }, -{ -0.688191f, -0.587785f, -0.425325f } -}; - - -MD2MODEL *Md2Model__create() -{ - return (MD2MODEL*)GB.New(GB.FindClass("Md2Model"), NULL, NULL); -}; - -/* - This method creates and loads new Md2 model. To use this in the program you should declare - it first as ie. - Public model as Md2Model - Then initiate it loading - model = Md2Model.Load(name as string) -*/ - -BEGIN_METHOD(Md2Model_Load, GB_STRING name) - - MD2MODEL *mdl = Md2Model__create(); - char *filename = GB.ToZeroString (ARG(name)); - FILE *fp; - int i,fi; - - fp = fopen (filename, "rb"); - if (!fp) - { - GB.Error ("Error: couldn't open \"%s\"!\n", filename); - return ; - } - - // Read header - fi=fread (&mdl->ident, 1, sizeof (int), fp); - fi=fread (&mdl->version, 1, sizeof (int), fp); - fi=fread (&mdl->skinwidth, 1, sizeof (int), fp); - fi=fread (&mdl->skinheight, 1, sizeof (int), fp); - fi=fread (&mdl->framesize, 1, sizeof (int), fp); - fi=fread (&mdl->num_skins, 1, sizeof (int), fp); - fi=fread (&mdl->num_vertices, 1, sizeof (int), fp); - fi=fread (&mdl->num_st, 1, sizeof (int), fp); - fi=fread (&mdl->num_tris, 1, sizeof (int), fp); - fi=fread (&mdl->num_glcmds, 1, sizeof (int), fp); - fi=fread (&mdl->num_frames, 1, sizeof (int), fp); - fi=fread (&mdl->offset_skins, 1, sizeof (int), fp); - fi=fread (&mdl->offset_st, 1, sizeof (int), fp); - fi=fread (&mdl->offset_tris, 1, sizeof (int), fp); - fi=fread (&mdl->offset_frames, 1, sizeof (int), fp); - fi=fread (&mdl->offset_glcmds, 1, sizeof (int), fp); - fi=fread (&mdl->offset_end, 1, sizeof (int), fp); - - if ((mdl->ident != 844121161) || (mdl->version != 8)) - { - // Error! - GB.Error ("Error: bad version or identifier\n"); - fclose (fp); - return; - } - - // Memory allocations - GB.Alloc ((void *) &mdl->skins, sizeof (skinmd2) * mdl->num_skins ); - GB.Alloc ((void *) &mdl->texcoords, sizeof (texCoordmd2) * mdl->num_st); - GB.Alloc ((void *) &mdl->triangles, sizeof (trianglemd2) * mdl->num_tris); - GB.Alloc ((void *) &mdl->frames, sizeof (framemd2) * mdl->num_frames); - GB.Alloc ((void *) &mdl->glcmds, sizeof (int) * mdl->num_glcmds); - // Read model data - fseek (fp, mdl->offset_skins, SEEK_SET); - fi=fread (mdl->skins, sizeof (skinmd2), mdl->num_skins, fp); - - fseek (fp, mdl->offset_st, SEEK_SET); - fi=fread (mdl->texcoords, sizeof (texCoordmd2), mdl->num_st, fp); - - fseek (fp, mdl->offset_tris, SEEK_SET); - fi=fread (mdl->triangles, sizeof (trianglemd2), mdl->num_tris, fp); - - fseek (fp, mdl->offset_glcmds, SEEK_SET); - fi=fread (mdl->glcmds, sizeof (int), mdl->num_glcmds, fp); - - // Read frames - fseek (fp, mdl->offset_frames, SEEK_SET); - for (i = 0; i < mdl->num_frames; ++i) - { - // Memory allocation for vertices of this frame - GB.Alloc ((void *) &mdl->frames[i].verts, sizeof (vertexmd2) * mdl->num_vertices); - - // Read frame data - fi=fread (mdl->frames[i].scale, sizeof (float)*3, 1, fp); - fi=fread (mdl->frames[i].translate, sizeof (float)*3, 1, fp); - fi=fread (mdl->frames[i].name, sizeof (char), 16, fp); - fi=fread (mdl->frames[i].verts, sizeof (vertexmd2), mdl->num_vertices, fp); - } - i=fi; - mdl->scale[0]=1; - mdl->scale[1]=1; - mdl->scale[2]=1; - fclose (fp); - - GB.ReturnObject(mdl); - -END_METHOD - -BEGIN_METHOD(Md2Model_SetPosition, GB_FLOAT x; GB_FLOAT y; GB_FLOAT z) - - THIS->position[0]=VARG(x); - THIS->position[1]=VARG(y); - THIS->position[2]=VARG(z); - -END_METHOD - -BEGIN_METHOD(Md2Model_DrawFrame, GB_INTEGER f_no; GB_INTEGER texture) - - int n = VARG(f_no); - int i, *pglcmds; - GLfloat v[3]; - framemd2 *pframe; - vertexmd2 *pvert; - glcmd *packet; - - // Check if n is in a valid range - if ((n < 0) || (n >= THIS->num_frames )) n=0; - glPushMatrix(); - glTranslatef(THIS->position[0], THIS->position[1], THIS->position[2]); - glRotatef(-90, 1, 0, 0); - glRotatef(-90, 0, 0, 1); - glScalef(THIS->scale[0], THIS->scale[1], THIS->scale[2]); - // Enable model's texture - glBindTexture (GL_TEXTURE_2D, VARG(texture)); - - // pglcmds points at the start of the command list - pglcmds = THIS->glcmds; - - // Draw the model - while ((i = *(pglcmds++)) != 0) - { - if (i < 0) - { - glBegin (GL_TRIANGLE_FAN); - i = -i; - } - else - { - glBegin (GL_TRIANGLE_STRIP); - } - - // Draw each vertex of this group - for (/* Nothing */ ; i > 0; --i, pglcmds += 3) - { - packet = (glcmd *)pglcmds; - pframe = &THIS->frames[n]; - pvert = &pframe->verts[packet->index]; - - // Pass texture coordinates to OpenGL - glTexCoord2f (packet->s, packet->t); - - // Normal vector - glNormal3fv (anorms_table[pvert->normalIndex]); - - // Calculate vertex real position - v[0] = (pframe->scale[0] * pvert->v[0]) + pframe->translate[0]; - v[1] = (pframe->scale[1] * pvert->v[1]) + pframe->translate[1]; - v[2] = (pframe->scale[2] * pvert->v[2]) + pframe->translate[2]; - - glVertex3fv (v); - } - - glEnd (); - } - glScalef(1/THIS->scale[0], 1/THIS->scale[1], 1/THIS->scale[2]); - glPopMatrix(); - -END_METHOD - -BEGIN_METHOD(Md2Model_DrawInterFrame, GB_INTEGER f_no; GB_FLOAT inter; GB_INTEGER texture) - - int i, j, n=VARG(f_no); - GLfloat s, t, v_curr[3], v_next[3], v[3], norm[3]; - float *n_curr, *n_next, interp = VARG(inter); - framemd2 *pframe1, *pframe2; - vertexmd2 *pvert1, *pvert2; - - if ((n < 0) || (n >= THIS->num_frames-1)) { - n=0; - interp = 0; - } - glPushMatrix(); - glTranslatef(THIS->position[0], THIS->position[1], THIS->position[2]); - glRotatef(-90, 1, 0, 0); - glRotatef(-90, 0, 0, 1); - glScalef(THIS->scale[0], THIS->scale[1], THIS->scale[2]); - glBindTexture (GL_TEXTURE_2D, VARG(texture)); - - glBegin (GL_TRIANGLES); - for (i = 0; i < THIS->num_tris; ++i) - { - for (j = 0; j < 3; ++j) - { - pframe1 = &THIS->frames[n]; - pframe2 = &THIS->frames[n + 1]; - pvert1 = &pframe1->verts[THIS->triangles[i].vertex[j]]; - pvert2 = &pframe2->verts[THIS->triangles[i].vertex[j]]; - - s = (GLfloat)THIS->texcoords[THIS->triangles[i].st[j]].s / THIS->skinwidth; - t = (GLfloat)THIS->texcoords[THIS->triangles[i].st[j]].t / THIS->skinheight; - - glTexCoord2f (s, t); - - n_curr = anorms_table[pvert1->normalIndex]; - n_next = anorms_table[pvert2->normalIndex]; - - norm[0] = n_curr[0] + interp * (n_next[0] - n_curr[0]); - norm[1] = n_curr[1] + interp * (n_next[1] - n_curr[1]); - norm[2] = n_curr[2] + interp * (n_next[2] - n_curr[2]); - - glNormal3fv (norm); - - v_curr[0] = pframe1->scale[0] * pvert1->v[0] + pframe1->translate[0]; - v_curr[1] = pframe1->scale[1] * pvert1->v[1] + pframe1->translate[1]; - v_curr[2] = pframe1->scale[2] * pvert1->v[2] + pframe1->translate[2]; - - v_next[0] = pframe2->scale[0] * pvert2->v[0] + pframe2->translate[0]; - v_next[1] = pframe2->scale[1] * pvert2->v[1] + pframe2->translate[1]; - v_next[2] = pframe2->scale[2] * pvert2->v[2] + pframe2->translate[2]; - - v[0] = v_curr[0] + interp * (v_next[0] - v_curr[0]); - v[1] = v_curr[1] + interp * (v_next[1] - v_curr[1]); - v[2] = v_curr[2] + interp * (v_next[2] - v_curr[2]); - - glVertex3fv (v); - } - } - glEnd (); - glScalef(1/THIS->scale[0], 1/THIS->scale[1], 1/THIS->scale[2]); - glPopMatrix(); - -END_METHOD - -BEGIN_METHOD_VOID(Md2Model_GetNoFrames) - - GB.ReturnInteger(THIS->num_frames); - -END_METHOD - -BEGIN_METHOD(Md2Model_GetFrameName, GB_INTEGER fn ) - - GB.ReturnNewString(THIS->frames[VARG(fn)].name, 16); - -END_METHOD - -BEGIN_METHOD(Md2Model_Scale, GB_FLOAT sx; GB_FLOAT sy; GB_FLOAT sz) - - THIS->scale[0] = VARG(sx); - THIS->scale[1] = VARG(sy); - THIS->scale[2] = VARG(sz); - -END_METHOD - - -BEGIN_METHOD_VOID(Md2Model_free) -int i; - GB.Free ((void *) &THIS->skins); - GB.Free ((void *) &THIS->texcoords); - GB.Free ((void *) &THIS->triangles); - for (i = 0; i < THIS->num_frames; ++i) GB.Free ((void *) &THIS->frames[i].verts); - GB.Free ((void *) &THIS->frames); - GB.Free ((void *) &THIS->glcmds); - -END_METHOD - -GB_DESC Md2ModelDesc[] = -{ - GB_DECLARE("Md2Model", sizeof(MD2MODEL)), - GB_NOT_CREATABLE(), - GB_STATIC_METHOD("Load", "Md2Model" , Md2Model_Load, "(Name)s"), - GB_METHOD("SetPosition", NULL, Md2Model_SetPosition, "(X)f(Y)f(Z)f" ), - GB_METHOD("DrawFrame", NULL, Md2Model_DrawFrame, "(Frame_No)i(Texture)i" ), - GB_METHOD("DrawInterFrame", NULL, Md2Model_DrawInterFrame, "(Frame_No)i(InterFrame)f(Texture)i" ), - GB_METHOD("GetFramesNo", "i", Md2Model_GetNoFrames, NULL ), - GB_METHOD("GetFrameName", "s", Md2Model_GetFrameName, "(FrameNumber)i" ), - GB_METHOD("Scale", NULL, Md2Model_Scale, "(Scale_x)f(Scale_y)f(Scale_z)f" ), - GB_METHOD("_free", NULL, Md2Model_free, NULL ), - GB_END_DECLARE -}; - - diff --git a/gb.opengl/configure.ac b/gb.opengl/configure.ac index c47e20398..0a04641cf 100644 --- a/gb.opengl/configure.ac +++ b/gb.opengl/configure.ac @@ -17,11 +17,16 @@ GB_COMPONENT_PKG_CONFIG( glu, GLU, gb.opengl.glu, [glu], [glu]) +GB_COMPONENT_PKG_CONFIG( + sge, SGE, gb.opengl.sge, [sge], + [gl glew]) + AC_OUTPUT( \ Makefile \ src/Makefile \ src/glu/Makefile \ src/glsl/Makefile \ +src/sge/Makefile ) GB_PRINT_MESSAGES diff --git a/gb.opengl/src/Makefile.am b/gb.opengl/src/Makefile.am index c2704ea00..fc741bd4a 100644 --- a/gb.opengl/src/Makefile.am +++ b/gb.opengl/src/Makefile.am @@ -1,7 +1,7 @@ COMPONENT = gb.opengl include $(top_srcdir)/component.am -SUBDIRS = . @GLSL_DIR@ @GLU_DIR@ +SUBDIRS = . @GLSL_DIR@ @GLU_DIR@ @SGE_DIR@ gblib_LTLIBRARIES = gb.opengl.la diff --git a/gb.opengl/src/glu/GLU.c b/gb.opengl/src/glu/GLU.c index 0b5324710..4e36d931c 100644 --- a/gb.opengl/src/glu/GLU.c +++ b/gb.opengl/src/glu/GLU.c @@ -23,6 +23,8 @@ #define __GLU_C +#include "gb.image.h" + #include "GLU.h" #include "GLUcoordTransf.h" @@ -31,6 +33,30 @@ #include "GLUnurb.h" #include "GLUproject.h" +//--------------------------------------------------------------------------- + +BEGIN_METHOD(Glu_Color, GB_INTEGER color) + + int r, g, b, a; + + GB_COLOR_SPLIT(VARG(color), r, g, b, a); + //fprintf(stderr, "Glu_Color: %d %d %d %d\n", r, g, b, a); + if (a == 0) + glColor3d(r / 255.0, g / 255.0, b / 255.0); + else + glColor4d(r / 255.0, g / 255.0, b / 255.0, a / 255.0); + +END_METHOD + +BEGIN_METHOD(Glu_ClearColor, GB_INTEGER color) + + int r, g, b, a; + + GB_COLOR_SPLIT(VARG(color), r, g, b, a); + glClearColor(r / 255.0, g / 255.0, b / 255.0, a / 255.0); + +END_METHOD + BEGIN_METHOD(GLUERRORSTRING, GB_INTEGER code) const GLubyte *errStr = gluErrorString(VARG(code)); @@ -38,7 +64,7 @@ BEGIN_METHOD(GLUERRORSTRING, GB_INTEGER code) END_METHOD -/**************************************************************************/ +//--------------------------------------------------------------------------- GB_DESC Cglu[] = { @@ -86,6 +112,10 @@ GB_DESC Cglu[] = GB_STATIC_METHOD("UnProject", "Float[]", GLUUNPROJECT, "(WindowX)f(WindowY)f(WindowZ)f(Modelview)Float[];(Projection)Float[];(Viewport)Integer[];"), GB_STATIC_METHOD("UnProject4", "Float[]", GLUUNPROJECT4, "(WindowX)f(WindowY)f(WindowZ)f(ClipW)f(Modelview)Float[];(Projection)Float[];(Viewport)Integer[];(NearValue)f(FarValue)f"), + /* Setting a Gambas color */ + GB_STATIC_METHOD("ClearColor", NULL, Glu_ClearColor, "(Color)i"), + GB_STATIC_METHOD("Color", NULL, Glu_Color, "(Color)i"), + /********************/ /* opengl constants */ /********************/ diff --git a/gb.opengl.sge/src/Makefile.am b/gb.opengl/src/sge/Makefile.am similarity index 52% rename from gb.opengl.sge/src/Makefile.am rename to gb.opengl/src/sge/Makefile.am index 9d2351750..3b77edbc6 100644 --- a/gb.opengl.sge/src/Makefile.am +++ b/gb.opengl/src/sge/Makefile.am @@ -3,9 +3,9 @@ include $(top_srcdir)/component.am gblib_LTLIBRARIES = gb.opengl.sge.la -gb_opengl_sge_la_LIBADD = @OPENGL_SGE_LIB@ -gb_opengl_sge_la_LDFLAGS = -module @LD_FLAGS@ @OPENGL_SGE_LDFLAGS@ -gb_opengl_sge_la_CPPFLAGS = @OPENGL_SGE_INC@ +gb_opengl_sge_la_LIBADD = @SGE_LIB@ +gb_opengl_sge_la_LDFLAGS = -module @LD_FLAGS@ @SGE_LDFLAGS@ +gb_opengl_sge_la_CPPFLAGS = @SGE_INC@ gb_opengl_sge_la_SOURCES = \ main.c main.h \ diff --git a/gb.opengl/src/sge/cmd2model.c b/gb.opengl/src/sge/cmd2model.c new file mode 100644 index 000000000..db170797f --- /dev/null +++ b/gb.opengl/src/sge/cmd2model.c @@ -0,0 +1,630 @@ +/*************************************************************************** + + cmd2model.c + + (c) 2012 Tomasz Kołodziejczyk "Tommyline" + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + +***************************************************************************/ + +#define __CMD2MODEL_C + +#include "gb_common.h" +#include "cmd2model.h" +#include + +#define THIS OBJECT(CMD2MODEL) + +/* Table of precalculated normals */ +GLfloat anorms_table[162][3] = +{ + { -0.525731f, 0.000000f, 0.850651f }, + { -0.442863f, 0.238856f, 0.864188f }, + { -0.295242f, 0.000000f, 0.955423f }, + { -0.309017f, 0.500000f, 0.809017f }, + { -0.162460f, 0.262866f, 0.951056f }, + { 0.000000f, 0.000000f, 1.000000f }, + { 0.000000f, 0.850651f, 0.525731f }, + { -0.147621f, 0.716567f, 0.681718f }, + { 0.147621f, 0.716567f, 0.681718f }, + { 0.000000f, 0.525731f, 0.850651f }, + { 0.309017f, 0.500000f, 0.809017f }, + { 0.525731f, 0.000000f, 0.850651f }, + { 0.295242f, 0.000000f, 0.955423f }, + { 0.442863f, 0.238856f, 0.864188f }, + { 0.162460f, 0.262866f, 0.951056f }, + { -0.681718f, 0.147621f, 0.716567f }, + { -0.809017f, 0.309017f, 0.500000f }, + { -0.587785f, 0.425325f, 0.688191f }, + { -0.850651f, 0.525731f, 0.000000f }, + { -0.864188f, 0.442863f, 0.238856f }, + { -0.716567f, 0.681718f, 0.147621f }, + { -0.688191f, 0.587785f, 0.425325f }, + { -0.500000f, 0.809017f, 0.309017f }, + { -0.238856f, 0.864188f, 0.442863f }, + { -0.425325f, 0.688191f, 0.587785f }, + { -0.716567f, 0.681718f, -0.147621f }, + { -0.500000f, 0.809017f, -0.309017f }, + { -0.525731f, 0.850651f, 0.000000f }, + { 0.000000f, 0.850651f, -0.525731f }, + { -0.238856f, 0.864188f, -0.442863f }, + { 0.000000f, 0.955423f, -0.295242f }, + { -0.262866f, 0.951056f, -0.162460f }, + { 0.000000f, 1.000000f, 0.000000f }, + { 0.000000f, 0.955423f, 0.295242f }, + { -0.262866f, 0.951056f, 0.162460f }, + { 0.238856f, 0.864188f, 0.442863f }, + { 0.262866f, 0.951056f, 0.162460f }, + { 0.500000f, 0.809017f, 0.309017f }, + { 0.238856f, 0.864188f, -0.442863f }, + { 0.262866f, 0.951056f, -0.162460f }, + { 0.500000f, 0.809017f, -0.309017f }, + { 0.850651f, 0.525731f, 0.000000f }, + { 0.716567f, 0.681718f, 0.147621f }, + { 0.716567f, 0.681718f, -0.147621f }, + { 0.525731f, 0.850651f, 0.000000f }, + { 0.425325f, 0.688191f, 0.587785f }, + { 0.864188f, 0.442863f, 0.238856f }, + { 0.688191f, 0.587785f, 0.425325f }, + { 0.809017f, 0.309017f, 0.500000f }, + { 0.681718f, 0.147621f, 0.716567f }, + { 0.587785f, 0.425325f, 0.688191f }, + { 0.955423f, 0.295242f, 0.000000f }, + { 1.000000f, 0.000000f, 0.000000f }, + { 0.951056f, 0.162460f, 0.262866f }, + { 0.850651f, -0.525731f, 0.000000f }, + { 0.955423f, -0.295242f, 0.000000f }, + { 0.864188f, -0.442863f, 0.238856f }, + { 0.951056f, -0.162460f, 0.262866f }, + { 0.809017f, -0.309017f, 0.500000f }, + { 0.681718f, -0.147621f, 0.716567f }, + { 0.850651f, 0.000000f, 0.525731f }, + { 0.864188f, 0.442863f, -0.238856f }, + { 0.809017f, 0.309017f, -0.500000f }, + { 0.951056f, 0.162460f, -0.262866f }, + { 0.525731f, 0.000000f, -0.850651f }, + { 0.681718f, 0.147621f, -0.716567f }, + { 0.681718f, -0.147621f, -0.716567f }, + { 0.850651f, 0.000000f, -0.525731f }, + { 0.809017f, -0.309017f, -0.500000f }, + { 0.864188f, -0.442863f, -0.238856f }, + { 0.951056f, -0.162460f, -0.262866f }, + { 0.147621f, 0.716567f, -0.681718f }, + { 0.309017f, 0.500000f, -0.809017f }, + { 0.425325f, 0.688191f, -0.587785f }, + { 0.442863f, 0.238856f, -0.864188f }, + { 0.587785f, 0.425325f, -0.688191f }, + { 0.688191f, 0.587785f, -0.425325f }, + { -0.147621f, 0.716567f, -0.681718f }, + { -0.309017f, 0.500000f, -0.809017f }, + { 0.000000f, 0.525731f, -0.850651f }, + { -0.525731f, 0.000000f, -0.850651f }, + { -0.442863f, 0.238856f, -0.864188f }, + { -0.295242f, 0.000000f, -0.955423f }, + { -0.162460f, 0.262866f, -0.951056f }, + { 0.000000f, 0.000000f, -1.000000f }, + { 0.295242f, 0.000000f, -0.955423f }, + { 0.162460f, 0.262866f, -0.951056f }, + { -0.442863f, -0.238856f, -0.864188f }, + { -0.309017f, -0.500000f, -0.809017f }, + { -0.162460f, -0.262866f, -0.951056f }, + { 0.000000f, -0.850651f, -0.525731f }, + { -0.147621f, -0.716567f, -0.681718f }, + { 0.147621f, -0.716567f, -0.681718f }, + { 0.000000f, -0.525731f, -0.850651f }, + { 0.309017f, -0.500000f, -0.809017f }, + { 0.442863f, -0.238856f, -0.864188f }, + { 0.162460f, -0.262866f, -0.951056f }, + { 0.238856f, -0.864188f, -0.442863f }, + { 0.500000f, -0.809017f, -0.309017f }, + { 0.425325f, -0.688191f, -0.587785f }, + { 0.716567f, -0.681718f, -0.147621f }, + { 0.688191f, -0.587785f, -0.425325f }, + { 0.587785f, -0.425325f, -0.688191f }, + { 0.000000f, -0.955423f, -0.295242f }, + { 0.000000f, -1.000000f, 0.000000f }, + { 0.262866f, -0.951056f, -0.162460f }, + { 0.000000f, -0.850651f, 0.525731f }, + { 0.000000f, -0.955423f, 0.295242f }, + { 0.238856f, -0.864188f, 0.442863f }, + { 0.262866f, -0.951056f, 0.162460f }, + { 0.500000f, -0.809017f, 0.309017f }, + { 0.716567f, -0.681718f, 0.147621f }, + { 0.525731f, -0.850651f, 0.000000f }, + { -0.238856f, -0.864188f, -0.442863f }, + { -0.500000f, -0.809017f, -0.309017f }, + { -0.262866f, -0.951056f, -0.162460f }, + { -0.850651f, -0.525731f, 0.000000f }, + { -0.716567f, -0.681718f, -0.147621f }, + { -0.716567f, -0.681718f, 0.147621f }, + { -0.525731f, -0.850651f, 0.000000f }, + { -0.500000f, -0.809017f, 0.309017f }, + { -0.238856f, -0.864188f, 0.442863f }, + { -0.262866f, -0.951056f, 0.162460f }, + { -0.864188f, -0.442863f, 0.238856f }, + { -0.809017f, -0.309017f, 0.500000f }, + { -0.688191f, -0.587785f, 0.425325f }, + { -0.681718f, -0.147621f, 0.716567f }, + { -0.442863f, -0.238856f, 0.864188f }, + { -0.587785f, -0.425325f, 0.688191f }, + { -0.309017f, -0.500000f, 0.809017f }, + { -0.147621f, -0.716567f, 0.681718f }, + { -0.425325f, -0.688191f, 0.587785f }, + { -0.162460f, -0.262866f, 0.951056f }, + { 0.442863f, -0.238856f, 0.864188f }, + { 0.162460f, -0.262866f, 0.951056f }, + { 0.309017f, -0.500000f, 0.809017f }, + { 0.147621f, -0.716567f, 0.681718f }, + { 0.000000f, -0.525731f, 0.850651f }, + { 0.425325f, -0.688191f, 0.587785f }, + { 0.587785f, -0.425325f, 0.688191f }, + { 0.688191f, -0.587785f, 0.425325f }, + { -0.955423f, 0.295242f, 0.000000f }, + { -0.951056f, 0.162460f, 0.262866f }, + { -1.000000f, 0.000000f, 0.000000f }, + { -0.850651f, 0.000000f, 0.525731f }, + { -0.955423f, -0.295242f, 0.000000f }, + { -0.951056f, -0.162460f, 0.262866f }, + { -0.864188f, 0.442863f, -0.238856f }, + { -0.951056f, 0.162460f, -0.262866f }, + { -0.809017f, 0.309017f, -0.500000f }, + { -0.864188f, -0.442863f, -0.238856f }, + { -0.951056f, -0.162460f, -0.262866f }, + { -0.809017f, -0.309017f, -0.500000f }, + { -0.681718f, 0.147621f, -0.716567f }, + { -0.681718f, -0.147621f, -0.716567f }, + { -0.850651f, 0.000000f, -0.525731f }, + { -0.688191f, 0.587785f, -0.425325f }, + { -0.587785f, 0.425325f, -0.688191f }, + { -0.425325f, 0.688191f, -0.587785f }, + { -0.425325f, -0.688191f, -0.587785f }, + { -0.587785f, -0.425325f, -0.688191f }, + { -0.688191f, -0.587785f, -0.425325f } +}; + + +CMD2MODEL *MD2MODEL_create(void) +{ + return (CMD2MODEL*)GB.New(GB.FindClass("Md2Model"), NULL, NULL); +}; + +static void draw_frame_inter(CMD2MODEL *_object, int n, float interp, int texture) +{ + int i, j; + GLfloat s, t, v_curr[3], v_next[3], v[3], norm[3]; + float *n_curr, *n_next; + framemd2 *pframe1, *pframe2; + vertexmd2 *pvert1, *pvert2; + bool enabled; + + int *pglcmds; + framemd2 *pframe; + vertexmd2 *pvert; + glcmd *packet; + + if (texture < 0) + return; + + if ((n < 0) || (n >= THIS->num_frames-1)) + { + n=0; + interp = 0; + } + + enabled = glIsEnabled(GL_TEXTURE_2D); + if (!enabled) + glEnable(GL_TEXTURE_2D); + + glPushMatrix(); + glTranslatef(THIS->position[0], THIS->position[1], THIS->position[2]); + glRotatef(-90, 1, 0, 0); + glRotatef(-90, 0, 0, 1); + glScalef(THIS->scale[0], THIS->scale[1], THIS->scale[2]); + glBindTexture (GL_TEXTURE_2D, texture); + + if (interp == 0) + { + // pglcmds points at the start of the command list + pglcmds = THIS->glcmds; + + // Draw the model + while ((i = *(pglcmds++)) != 0) + { + if (i < 0) + { + glBegin (GL_TRIANGLE_FAN); + i = -i; + } + else + { + glBegin (GL_TRIANGLE_STRIP); + } + + // Draw each vertex of this group + for (/* Nothing */ ; i > 0; --i, pglcmds += 3) + { + packet = (glcmd *)pglcmds; + pframe = &THIS->frames[n]; + pvert = &pframe->verts[packet->index]; + + // Pass texture coordinates to OpenGL + glTexCoord2f (packet->s, packet->t); + + // Normal vector + glNormal3fv (anorms_table[pvert->normalIndex]); + + // Calculate vertex real position + v[0] = (pframe->scale[0] * pvert->v[0]) + pframe->translate[0]; + v[1] = (pframe->scale[1] * pvert->v[1]) + pframe->translate[1]; + v[2] = (pframe->scale[2] * pvert->v[2]) + pframe->translate[2]; + + glVertex3fv (v); + } + + glEnd (); + } + } + else + { + glBegin (GL_TRIANGLES); + + for (i = 0; i < THIS->num_tris; ++i) + { + for (j = 0; j < 3; ++j) + { + pframe1 = &THIS->frames[n]; + pframe2 = &THIS->frames[n + 1]; + pvert1 = &pframe1->verts[THIS->triangles[i].vertex[j]]; + pvert2 = &pframe2->verts[THIS->triangles[i].vertex[j]]; + + s = (GLfloat)THIS->texcoords[THIS->triangles[i].st[j]].s / THIS->skinwidth; + t = (GLfloat)THIS->texcoords[THIS->triangles[i].st[j]].t / THIS->skinheight; + + glTexCoord2f (s, t); + + n_curr = anorms_table[pvert1->normalIndex]; + n_next = anorms_table[pvert2->normalIndex]; + + norm[0] = n_curr[0] + interp * (n_next[0] - n_curr[0]); + norm[1] = n_curr[1] + interp * (n_next[1] - n_curr[1]); + norm[2] = n_curr[2] + interp * (n_next[2] - n_curr[2]); + + glNormal3fv (norm); + + v_curr[0] = pframe1->scale[0] * pvert1->v[0] + pframe1->translate[0]; + v_curr[1] = pframe1->scale[1] * pvert1->v[1] + pframe1->translate[1]; + v_curr[2] = pframe1->scale[2] * pvert1->v[2] + pframe1->translate[2]; + + v_next[0] = pframe2->scale[0] * pvert2->v[0] + pframe2->translate[0]; + v_next[1] = pframe2->scale[1] * pvert2->v[1] + pframe2->translate[1]; + v_next[2] = pframe2->scale[2] * pvert2->v[2] + pframe2->translate[2]; + + v[0] = v_curr[0] + interp * (v_next[0] - v_curr[0]); + v[1] = v_curr[1] + interp * (v_next[1] - v_curr[1]); + v[2] = v_curr[2] + interp * (v_next[2] - v_curr[2]); + + glVertex3fv (v); + } + } + + glEnd(); + } + + //glScalef(1/THIS->scale[0], 1/THIS->scale[1], 1/THIS->scale[2]); + glPopMatrix(); + + if (!enabled) + glDisable(GL_TEXTURE_2D); + +} + +// // Generate one list for each frame +// +// static void make_lists(CMD2MODEL *mdl) +// { +// int i; +// +// mdl->list = glGenLists(mdl->num_frames); +// +// for (i = 0; i < mdl->num_frames; i++) +// { +// glNewList(mdl->list + i, GL_COMPILE); +// draw_frame_inter(mdl, i, 0, mdl->texture); +// glEndList(); +// } +// } + +//--------------------------------------------------------------------------- + +BEGIN_METHOD_VOID(Md2Model_new) + + THIS->texture = -1; + +END_METHOD + +BEGIN_METHOD_VOID(Md2Model_free) + + int i; + + GB.Free ((void *) &THIS->skins); + GB.Free ((void *) &THIS->texcoords); + GB.Free ((void *) &THIS->triangles); + + for (i = 0; i < THIS->num_frames; ++i) + GB.Free ((void *) &THIS->frames[i].verts); + + GB.Free ((void *) &THIS->frames); + GB.Free ((void *) &THIS->glcmds); + +END_METHOD + +/* + This method creates and loads new Md2 model. To use this in the program you should declare + it first as ie. + Public model as Md2Model + Then initiate it loading + model = Md2Model.Load(name as string) +*/ + +BEGIN_METHOD(Md2Model_Load, GB_STRING name) + + char *addr; + int len; + CMD2MODEL *mdl = NULL; + int i; + + if (GB.LoadFile(STRING(name), LENGTH(name), &addr, &len)) + return; + + mdl = MD2MODEL_create(); + + // Read header + { + int *p = (int *)addr; + + mdl->ident = *p++; + mdl->version = *p++; + mdl->skinwidth = *p++; + mdl->skinheight = *p++; + mdl->framesize = *p++; + mdl->num_skins = *p++; + mdl->num_vertices = *p++; + mdl->num_st = *p++; + mdl->num_tris = *p++; + mdl->num_glcmds = *p++; + mdl->num_frames = *p++; + mdl->offset_skins = *p++; + mdl->offset_st = *p++; + mdl->offset_tris = *p++; + mdl->offset_frames = *p++; + mdl->offset_glcmds = *p++; + mdl->offset_end = *p++; + } + + if ((mdl->ident != 844121161) || (mdl->version != 8)) + { + // Error! + GB.Error("Bad version or identifier"); + goto __ERROR; + } + + // Memory allocations + GB.Alloc ((void *) &mdl->skins, sizeof (skinmd2) * mdl->num_skins ); + GB.Alloc ((void *) &mdl->texcoords, sizeof (texCoordmd2) * mdl->num_st); + GB.Alloc ((void *) &mdl->triangles, sizeof (trianglemd2) * mdl->num_tris); + GB.Alloc ((void *) &mdl->frames, sizeof (framemd2) * mdl->num_frames); + GB.Alloc ((void *) &mdl->glcmds, sizeof (int) * mdl->num_glcmds); + + // Read model data + memcpy(mdl->skins, &addr[mdl->offset_skins], sizeof(skinmd2) * mdl->num_skins); + + //fseek (fp, mdl->offset_st, SEEK_SET); + //fi=fread (mdl->texcoords, sizeof (texCoordmd2), mdl->num_st, fp); + memcpy(mdl->texcoords, &addr[mdl->offset_st], sizeof(texCoordmd2) * mdl->num_st); + + //fseek (fp, mdl->offset_tris, SEEK_SET); + //fi=fread (mdl->triangles, sizeof (trianglemd2), mdl->num_tris, fp); + memcpy(mdl->triangles, &addr[mdl->offset_tris], sizeof(trianglemd2) * mdl->num_tris); + + //fseek (fp, mdl->offset_glcmds, SEEK_SET); + //fi=fread (mdl->glcmds, sizeof (int), mdl->num_glcmds, fp); + memcpy(mdl->glcmds, &addr[mdl->offset_glcmds], sizeof(int) * mdl->num_glcmds); + + // Read frames + //fseek (fp, mdl->offset_frames, SEEK_SET); + { + char *p = &addr[mdl->offset_frames]; + + for (i = 0; i < mdl->num_frames; ++i) + { + // Memory allocation for vertices of this frame + GB.Alloc((void *) &mdl->frames[i].verts, sizeof (vertexmd2) * mdl->num_vertices); + + // Read frame data + memcpy(mdl->frames[i].scale, p, sizeof(float) * 3); p += sizeof(float) * 3; + memcpy(mdl->frames[i].translate, p, sizeof(float) * 3); p += sizeof(float) * 3; + memcpy(mdl->frames[i].name, p, 16); p += 16; + memcpy(mdl->frames[i].verts, p, sizeof(vertexmd2) * mdl->num_vertices); p += sizeof(vertexmd2) * mdl->num_vertices; + //fi=fread (mdl->frames[i].scale, sizeof (float)*3, 1, fp); + //fi=fread (mdl->frames[i].translate, sizeof (float)*3, 1, fp); + //fi=fread (mdl->frames[i].name, sizeof (char), 16, fp); + //fi=fread (mdl->frames[i].verts, sizeof (vertexmd2), mdl->num_vertices, fp); + } + } + + mdl->scale[0] = 1; + mdl->scale[1] = 1; + mdl->scale[2] = 1; + + GB.ReleaseFile(addr, len); + GB.ReturnObject(mdl); + return; + +__ERROR: + + GB.ReleaseFile(addr, len); + GB.Unref(POINTER(&mdl)); + +END_METHOD + +BEGIN_METHOD(Md2Model_Move, GB_FLOAT x; GB_FLOAT y; GB_FLOAT z) + + THIS->position[0] = VARG(x); + THIS->position[1] = VARG(y); + THIS->position[2] = VARG(z); + +END_METHOD + +BEGIN_PROPERTY(Md2Model_X) + + if (READ_PROPERTY) + GB.ReturnFloat(THIS->position[0]); + else + THIS->position[0] = VPROP(GB_FLOAT); + +END_PROPERTY + +BEGIN_PROPERTY(Md2Model_Y) + + if (READ_PROPERTY) + GB.ReturnFloat(THIS->position[1]); + else + THIS->position[1] = VPROP(GB_FLOAT); + +END_PROPERTY + +BEGIN_PROPERTY(Md2Model_Z) + + if (READ_PROPERTY) + GB.ReturnFloat(THIS->position[2]); + else + THIS->position[2] = VPROP(GB_FLOAT); + +END_PROPERTY + +BEGIN_METHOD(Md2Model_Scale, GB_FLOAT sx; GB_FLOAT sy; GB_FLOAT sz) + + THIS->scale[0] = VARG(sx); + THIS->scale[1] = VARG(sy); + THIS->scale[2] = VARG(sz); + +END_METHOD + + +BEGIN_PROPERTY(Md2Model_Count) + + GB.ReturnInteger(THIS->num_frames); + +END_PROPERTY + +BEGIN_METHOD(Md2Model_get, GB_INTEGER frame) + + int frame = VARG(frame); + + if (frame < 0 || frame >= THIS->num_frames) + { + GB.Error(GB_ERR_BOUND); + return; + } + + THIS->frame = frame; + RETURN_SELF(); + +END_METHOD + +BEGIN_PROPERTY(Md2Model_Texture) + + if (READ_PROPERTY) + GB.ReturnInteger(THIS->texture); + else + THIS->texture = VPROP(GB_INTEGER); + +END_PROPERTY + +BEGIN_PROPERTY(Md2Model_Pos) + + if (READ_PROPERTY) + GB.ReturnFloat(THIS->pos); + else + THIS->pos = VPROP(GB_FLOAT); + +END_PROPERTY + +BEGIN_METHOD_VOID(Md2Model_Draw) + + draw_frame_inter(THIS, (int)THIS->pos, THIS->pos - (int)THIS->pos, THIS->texture); + +END_METHOD + +//--------------------------------------------------------------------------- + +BEGIN_METHOD(Md2Model_Frame_Draw, GB_INTEGER texture) + + draw_frame_inter(THIS, THIS->frame, 0, VARG(texture)); + +END_METHOD + +BEGIN_METHOD(Md2Model_Frame_DrawInter, GB_FLOAT inter; GB_INTEGER texture) + + draw_frame_inter(THIS, THIS->frame, VARG(inter), VARG(texture)); + +END_METHOD + +BEGIN_PROPERTY(Md2Model_Frame_Name) + + GB.ReturnNewZeroString(THIS->frames[THIS->frame].name); + +END_METHOD + +//--------------------------------------------------------------------------- + +GB_DESC Md2ModelFrameDesc[] = +{ + GB_DECLARE_VIRTUAL(".Md2Model.Frame"), + GB_PROPERTY_READ("Name", "s", Md2Model_Frame_Name), + GB_METHOD("Draw", NULL, Md2Model_Frame_Draw, "(Texture)i"), + GB_METHOD("DrawInter", NULL, Md2Model_Frame_DrawInter, "(InterFrame)f(Texture)i"), + GB_END_DECLARE +}; + +GB_DESC Md2ModelDesc[] = +{ + GB_DECLARE("Md2Model", sizeof(CMD2MODEL)), GB_NOT_CREATABLE(), + + GB_METHOD("_new", NULL, Md2Model_new, NULL), + GB_METHOD("_free", NULL, Md2Model_free, NULL), + + GB_STATIC_METHOD("Load", "Md2Model" , Md2Model_Load, "(Name)s"), + + GB_METHOD("Move", NULL, Md2Model_Move, "(X)f(Y)f(Z)f"), + GB_PROPERTY_READ("X", "f", Md2Model_X), + GB_PROPERTY_READ("Y", "f", Md2Model_Y), + GB_PROPERTY_READ("Z", "f", Md2Model_Z), + + GB_PROPERTY_READ("Count", "i", Md2Model_Count), + GB_METHOD("_get", ".Md2Model.Frame", Md2Model_get, "(Frame)i"), + + GB_METHOD("Scale", NULL, Md2Model_Scale, "(ScaleX)f(ScaleY)f(ScaleZ)f" ), + + GB_PROPERTY("Texture", "i", Md2Model_Texture), + GB_PROPERTY("Pos", "f", Md2Model_Pos), + GB_METHOD("Draw", NULL, Md2Model_Draw, NULL), + + GB_END_DECLARE +}; + + diff --git a/gb.opengl.sge/src/cmd2model.h b/gb.opengl/src/sge/cmd2model.h similarity index 84% rename from gb.opengl.sge/src/cmd2model.h rename to gb.opengl/src/sge/cmd2model.h index cc7c24e7d..a13cb0a2c 100644 --- a/gb.opengl.sge/src/cmd2model.h +++ b/gb.opengl/src/sge/cmd2model.h @@ -58,6 +58,10 @@ #include "gambas.h" #include "main.h" +#ifndef __CMD2MODEL_C +extern GB_DESC Md2ModelFrameDesc[]; +extern GB_DESC Md2ModelDesc[]; +#endif /* Vector */ typedef float vec3[3]; @@ -114,54 +118,54 @@ struct md2_glcmd }glcmd; -extern GB_DESC Md2ModelDesc[] ; - typedef struct { GB_BASE ob; //Header int ident; - int version; + int version; - int skinwidth; - int skinheight; + int skinwidth; + int skinheight; - int framesize; + int framesize; - int num_skins; - int num_vertices; - int num_st; - int num_tris; - int num_glcmds; - int num_frames; + int num_skins; + int num_vertices; + int num_st; + int num_tris; + int num_glcmds; + int num_frames; - int offset_skins; - int offset_st; - int offset_tris; - int offset_frames; - int offset_glcmds; - int offset_end; + int offset_skins; + int offset_st; + int offset_tris; + int offset_frames; + int offset_glcmds; + int offset_end; //End header skinmd2 *skins; - texCoordmd2 *texcoords; - trianglemd2 *triangles; - framemd2 *frames; - int *glcmds; + texCoordmd2 *texcoords; + trianglemd2 *triangles; + framemd2 *frames; + int *glcmds; - GLuint tex_id; + GLuint tex_id; //Model specific data float position[3]; float scale[3]; int f_no; float inter_frame; + int frame; // frame being accessed with the [] operator + int texture; + double pos; //End model specific data } - MD2MODEL; + CMD2MODEL; -MD2MODEL *MD2MODEL_create(); - +CMD2MODEL *MD2MODEL_create(void); #endif diff --git a/gb.opengl.sge/src/gb.opengl.sge.component b/gb.opengl/src/sge/gb.opengl.sge.component similarity index 100% rename from gb.opengl.sge/src/gb.opengl.sge.component rename to gb.opengl/src/sge/gb.opengl.sge.component diff --git a/gb.opengl.sge/src/main.c b/gb.opengl/src/sge/main.c similarity index 98% rename from gb.opengl.sge/src/main.c rename to gb.opengl/src/sge/main.c index 052e0f192..ab975c30e 100644 --- a/gb.opengl.sge/src/main.c +++ b/gb.opengl/src/sge/main.c @@ -32,6 +32,7 @@ GB_INTERFACE GB EXPORT; GB_DESC *GB_CLASSES[] EXPORT = { + Md2ModelFrameDesc, Md2ModelDesc, NULL diff --git a/gb.opengl.sge/src/main.h b/gb.opengl/src/sge/main.h similarity index 100% rename from gb.opengl.sge/src/main.h rename to gb.opengl/src/sge/main.h diff --git a/gb.qt4/src/CTrayIcon.cpp b/gb.qt4/src/CTrayIcon.cpp index 1264f039d..d46b36df0 100644 --- a/gb.qt4/src/CTrayIcon.cpp +++ b/gb.qt4/src/CTrayIcon.cpp @@ -63,6 +63,8 @@ DECLARE_EVENT(EVENT_GotFocus); DECLARE_EVENT(EVENT_LostFocus); DECLARE_EVENT(EVENT_Menu); +int TRAYICON_count = 0; + static int _state; static QList _list; static QImage _default_trayicon; @@ -115,6 +117,8 @@ static void destroy_widget(CTRAYICON *_object) { delete WIDGET; THIS->widget = NULL; + TRAYICON_count--; + MAIN_check_quit(); } } @@ -260,6 +264,7 @@ BEGIN_METHOD_VOID(CTRAYICON_show) wid->installEventFilter(&CTrayIcon::manager); THIS->widget = wid; + TRAYICON_count++; //QObject::connect(WIDGET, SIGNAL(embedded()), &CTrayIcon::manager, SLOT(embedded())); //QObject::connect(WIDGET, SIGNAL(containerClosed()), &CTrayIcon::manager, SLOT(closed())); diff --git a/gb.qt4/src/CTrayIcon.h b/gb.qt4/src/CTrayIcon.h index 856eb0b5f..234c8808b 100644 --- a/gb.qt4/src/CTrayIcon.h +++ b/gb.qt4/src/CTrayIcon.h @@ -38,6 +38,7 @@ #ifndef __CTRAYICON_CPP extern GB_DESC CTrayIconDesc[]; extern GB_DESC CTrayIconsDesc[]; +extern int TRAYICON_count; #else #define THIS ((CTRAYICON *)_object) diff --git a/gb.qt4/src/main.cpp b/gb.qt4/src/main.cpp index ee25da2c0..47eb74885 100644 --- a/gb.qt4/src/main.cpp +++ b/gb.qt4/src/main.cpp @@ -571,7 +571,7 @@ static bool must_quit(void) #if DEBUG_WINDOW qDebug("must_quit: Window = %d Watch = %d in_event_loop = %d", CWindow::count, CWatch::count, in_event_loop); #endif - return CWINDOW_must_quit() && CWatch::count == 0 && in_event_loop && MAIN_in_message_box == 0; + return CWINDOW_must_quit() && CWatch::count == 0 && in_event_loop && MAIN_in_message_box == 0 && TRAYICON_count == 0; } static void check_quit_now(intptr_t param) diff --git a/gb.qt4/src/opengl/CGLarea.cpp b/gb.qt4/src/opengl/CGLarea.cpp index 15761dc62..13ee50d7b 100644 --- a/gb.qt4/src/opengl/CGLarea.cpp +++ b/gb.qt4/src/opengl/CGLarea.cpp @@ -176,7 +176,7 @@ void GLarea::paintGL() { // clear to avoid garbage CleanupOnFirstShow = true; - qglClearColor(Qt::black); + //qglClearColor(Qt::black); glClear(GL_COLOR_BUFFER_BIT); } diff --git a/main/gbx/gb_error.c b/main/gbx/gb_error.c index 0a6011f0f..c94a5d45f 100644 --- a/main/gbx/gb_error.c +++ b/main/gbx/gb_error.c @@ -711,7 +711,7 @@ void ERROR_hook(void) if (no_rec) return; - if (PROJECT_class) + if (PROJECT_class && PROJECT_class->state) { handle_error = (CLASS_DESC_METHOD *)CLASS_get_symbol_desc_kind(PROJECT_class, "Application_Error", CD_STATIC_METHOD, 0); diff --git a/main/lib/geom/cpoint_temp.h b/main/lib/geom/cpoint_temp.h index e7676399b..04422d5c0 100644 --- a/main/lib/geom/cpoint_temp.h +++ b/main/lib/geom/cpoint_temp.h @@ -134,7 +134,7 @@ static bool _convert_##__name(void *a, GB_TYPE type, GB_VALUE *conv) { \ if (a) \ { \ - double norm = _abs_##__name(a); \ + double norm = _fabs_##__name(a); \ \ switch (type) \ { \ diff --git a/main/lib/image/gb.image.h b/main/lib/image/gb.image.h index 3f43f5226..ac623a4cd 100644 --- a/main/lib/image/gb.image.h +++ b/main/lib/image/gb.image.h @@ -111,12 +111,13 @@ typedef // Split a color into its component. Uninvert the alpha component #define GB_COLOR_SPLIT(_color, _r, _g, _b, _a) \ -{ \ - _b = (_color) & 0xFF; \ - _g = ((_color) >> 8) & 0xFF; \ - _r = ((_color) >> 16) & 0xFF; \ - _a = ((_color) >> 24) ^ 0xFF; \ -} +({ \ + uint _c = (uint)(_color); \ + _b = _c & 0xFF; \ + _g = (_c >> 8) & 0xFF; \ + _r = (_c >> 16) & 0xFF; \ + _a = (_c >> 24) ^ 0xFF; \ +}) // Create a GB_COLOR from rgba components