]> git.tdb.fi Git - netvis.git/blobdiff - source/netvis.cpp
Get rid of any direct gl* calls in favor of the mspgl wrappers
[netvis.git] / source / netvis.cpp
index e9c6d50a3719da9628e935911a2c3f75b94b63df..7f0ac9e6b5de33f0d9fec3ca86bd5721ebeab22f 100644 (file)
@@ -5,7 +5,6 @@ Copyright @ 2008 Mikko Rasa, Mikkosoft Productions
 Distributed unter the GPL
 */
 
-#include <iostream>
 #include <limits>
 #include <cstdlib>
 #include <cmath>
@@ -16,6 +15,8 @@ Distributed unter the GPL
 #include <linux/if_ether.h>
 #include <msp/core/except.h>
 #include <msp/debug/profilingscope.h>
+#include <msp/gl/blend.h>
+#include <msp/gl/framebuffer.h>
 #include <msp/gl/immediate.h>
 #include <msp/gl/matrix.h>
 #include <msp/gl/misc.h>
@@ -34,6 +35,10 @@ using namespace std;
 using namespace Msp;
 
 NetVis::NetVis(int argc, char **argv):
+       pcap(0),
+       resolver(0),
+       wnd(0),
+       font(0),
        max_hosts(1000),
        max_visible_hosts(30),
        draw_labels(true),
@@ -43,10 +48,7 @@ NetVis::NetVis(int argc, char **argv):
        if(argc<2)
                throw UsageError("No interface given");
        iface = argv[1];
-}
 
-int NetVis::main()
-{
        char err[1024];
        pcap = pcap_open_live(iface.c_str(), 128, true, 0, err);
        if(!pcap)
@@ -59,39 +61,29 @@ int NetVis::main()
        localnet = ntohl(localnet);
        localnet_mask = ntohl(localnet_mask);
 
-       dpy = new Graphics::Display;
-       wnd = new Graphics::Window(*dpy, 1024, 768);
-       glc = new Graphics::GLContext(*wnd);
+       resolver = new Resolver;
+
+       wnd = new Graphics::SimpleGLWindow(1024, 768);
        wnd->set_title("NetVis");
        wnd->signal_close.connect(sigc::bind(sigc::mem_fun(this, &NetVis::exit), 0));
        wnd->signal_key_press.connect(sigc::mem_fun(this, &NetVis::key_press));
        wnd->show();
 
-       GL::enable(GL_BLEND);
-       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+       GL::enable(GL::BLEND);
+       GL::blend_func(GL::SRC_ALPHA, GL::ONE_MINUS_SRC_ALPHA);
 
        font = new GL::Font;
        DataFile::load(*font, "dejavu-10.font");
 
        catch_signal(SIGINT);
+}
 
-       resolver = new Resolver;
-
-       //set_loop_mode(TICK_BUSY);
-
-       Application::main();
-
+NetVis::~NetVis()
+{
        delete resolver;
 
        delete font;
-       delete glc;
        delete wnd;
-       delete dpy;
-
-       cout<<hosts.size()+disabled_hosts.size()<<" different hosts seen\n";
-       cout<<"capture: "<<profiler.scope("capture").total_time<<'\n';
-       cout<<"tick:    "<<profiler.scope("tick").total_time<<'\n';
-       cout<<"render:  "<<profiler.scope("render").total_time<<'\n';
 
        pcap_close(pcap);
        for(map<unsigned, Host *>::iterator i=hosts.begin(); i!=hosts.end(); ++i)
@@ -100,8 +92,6 @@ int NetVis::main()
                delete i->second;
        for(list<Packet *>::iterator i=packets.begin(); i!=packets.end(); ++i)
                delete *i;
-
-       return exit_code;
 }
 
 void NetVis::tick()
@@ -119,7 +109,7 @@ void NetVis::tick()
                frames = 0;
        }
 
-       dpy->tick();
+       wnd->get_display().tick();
 
        {
                Debug::ProfilingScope s(profiler, "capture");
@@ -196,7 +186,7 @@ void NetVis::tick()
 
        {
                Debug::ProfilingScope s(profiler, "render");
-               glClear(GL_COLOR_BUFFER_BIT);
+               GL::clear(GL::COLOR_BUFFER_BIT);
 
                GL::matrix_mode(GL::PROJECTION);
                GL::load_identity();
@@ -208,7 +198,6 @@ void NetVis::tick()
                        i->second->render();
                if(draw_labels)
                {
-                       glColor4f(1.0, 1.0, 1.0, 1.0);
                        for(map<unsigned, Host *>::iterator i=hosts.begin(); i!=hosts.end(); ++i)
                                i->second->render_label();
                        GL::Texture::unbind();
@@ -247,11 +236,12 @@ void NetVis::tick()
                        GL::push_matrix();
                        GL::translate(-484, 361, 0);
                        GL::scale_uniform(10);
-                       glColor4f(1.0, 1.0, 1.0, 1.0);
                        n = 0;
                        for(map<unsigned, GL::Color>::iterator i=port_colors.begin(); (i!=port_colors.end() && n<20); ++i, ++n)
                        {
-                               font->draw_string(format("%d", i->first));
+                               GL::Immediate imm2((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
+                               imm.color(1.0f, 1.0f, 1.0f);
+                               font->draw_string(format("%d", i->first), imm2);
 
                                GL::translate(0, -1.2, 0);
                        }
@@ -269,7 +259,7 @@ void NetVis::tick()
                GL::pop_matrix();
                GL::Texture::unbind();
 
-               glc->swap_buffers();
+               wnd->swap_buffers();
        }
 
        ++frames;