From 761c681764d4dae3b9776a57e4c3e5561e37f733 Mon Sep 17 00:00:00 2001 From: neoraider Date: Mon, 7 Apr 2008 01:45:04 +0000 Subject: zoomedit: Added RenderArea with OpenGL support. --- src/Gui/Makefile.am | 2 +- src/Gui/Makefile.in | 33 +++++++++++++++++++------------ src/Gui/RenderArea.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/Gui/RenderArea.h | 25 ++++++++++++++++++++++++ src/Gui/Window.cpp | 4 ++++ src/Gui/Window.h | 4 ++++ 6 files changed, 108 insertions(+), 13 deletions(-) create mode 100644 src/Gui/RenderArea.cpp create mode 100644 src/Gui/RenderArea.h (limited to 'src/Gui') diff --git a/src/Gui/Makefile.am b/src/Gui/Makefile.am index c3d6837..fad988d 100644 --- a/src/Gui/Makefile.am +++ b/src/Gui/Makefile.am @@ -1,4 +1,4 @@ noinst_LTLIBRARIES = libgui.la -libgui_la_SOURCES = Window.cpp +libgui_la_SOURCES = Window.cpp RenderArea.cpp libgui_la_CPPFLAGS = $(glademm_CFLAGS) $(GTKGLEXT_CFLAGS) \ No newline at end of file diff --git a/src/Gui/Makefile.in b/src/Gui/Makefile.in index 117fcae..61b6676 100644 --- a/src/Gui/Makefile.in +++ b/src/Gui/Makefile.in @@ -1,8 +1,8 @@ -# Makefile.in generated by automake 1.10 from Makefile.am. +# Makefile.in generated by automake 1.10.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -43,9 +43,9 @@ CONFIG_HEADER = $(top_builddir)/src/config.h CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) libgui_la_LIBADD = -am_libgui_la_OBJECTS = libgui_la-Window.lo +am_libgui_la_OBJECTS = libgui_la-Window.lo libgui_la-RenderArea.lo libgui_la_OBJECTS = $(am_libgui_la_OBJECTS) -DEFAULT_INCLUDES = -I. -I$(top_builddir)/src@am__isrc@ +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ @@ -81,6 +81,7 @@ CXXFLAGS = @CXXFLAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ ECHO = @ECHO@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ @@ -106,6 +107,7 @@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MKDIR_P = @MKDIR_P@ +NMEDIT = @NMEDIT@ OBJEXT = @OBJEXT@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ @@ -175,7 +177,7 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_LTLIBRARIES = libgui.la -libgui_la_SOURCES = Window.cpp +libgui_la_SOURCES = Window.cpp RenderArea.cpp libgui_la_CPPFLAGS = $(glademm_CFLAGS) $(GTKGLEXT_CFLAGS) all: all-am @@ -228,6 +230,7 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgui_la-RenderArea.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgui_la-Window.Plo@am__quote@ .cpp.o: @@ -258,6 +261,13 @@ libgui_la-Window.lo: Window.cpp @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libgui_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libgui_la-Window.lo `test -f 'Window.cpp' || echo '$(srcdir)/'`Window.cpp +libgui_la-RenderArea.lo: RenderArea.cpp +@am__fastdepCXX_TRUE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libgui_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libgui_la-RenderArea.lo -MD -MP -MF $(DEPDIR)/libgui_la-RenderArea.Tpo -c -o libgui_la-RenderArea.lo `test -f 'RenderArea.cpp' || echo '$(srcdir)/'`RenderArea.cpp +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/libgui_la-RenderArea.Tpo $(DEPDIR)/libgui_la-RenderArea.Plo +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='RenderArea.cpp' object='libgui_la-RenderArea.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libgui_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libgui_la-RenderArea.lo `test -f 'RenderArea.cpp' || echo '$(srcdir)/'`RenderArea.cpp + mostlyclean-libtool: -rm -f *.lo @@ -269,8 +279,8 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ + $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ mkid -fID $$unique tags: TAGS @@ -282,8 +292,8 @@ TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ @@ -293,13 +303,12 @@ ctags: CTAGS CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) tags=; \ - here=`pwd`; \ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ test -z "$(CTAGS_ARGS)$$tags$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$tags $$unique diff --git a/src/Gui/RenderArea.cpp b/src/Gui/RenderArea.cpp new file mode 100644 index 0000000..c19c0a5 --- /dev/null +++ b/src/Gui/RenderArea.cpp @@ -0,0 +1,53 @@ +#include "RenderArea.h" +#include +#include +#include + +namespace ZoomEdit { +namespace Gui { + +GdkGLConfig *RenderArea::glconfig = NULL; + +RenderArea::RenderArea(BaseObjectType *cobject, const Glib::RefPtr &xml) +: Gtk::DrawingArea(cobject) { + if(!glconfig) { + glconfig = gdk_gl_config_new_by_mode((GdkGLConfigMode)(GDK_GL_MODE_RGB | GDK_GL_MODE_DOUBLE)); + if(!glconfig) glconfig = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB); // Hmm, can't find double buffered config + if(!glconfig) { + std::cerr << "*** No appropriate OpenGL-capable visual found." << std::endl; + std::exit(1); + } + } + + signal_realize().connect(sigc::mem_fun(this, &RenderArea::onRealize)); + + gtk_widget_set_gl_capability(GTK_WIDGET(cobject), glconfig, NULL, TRUE, GDK_GL_RGBA_TYPE); +} + +RenderArea::~RenderArea() { +} + +void RenderArea::onRealize() { + GtkWidget *widget = GTK_WIDGET(gobj()); + GdkGLContext *context = gtk_widget_get_gl_context(widget); + GdkGLDrawable *drawable = gtk_widget_get_gl_drawable(widget); + + if(!gdk_gl_drawable_gl_begin(drawable, context)) + return; + + glClearColor(0, 0, 0, 0); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + + glEnable(GL_LINE_SMOOTH); + glEnable(GL_POINT_SMOOTH); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + gdk_gl_drawable_gl_end(drawable); +} + +} +} diff --git a/src/Gui/RenderArea.h b/src/Gui/RenderArea.h new file mode 100644 index 0000000..6695e09 --- /dev/null +++ b/src/Gui/RenderArea.h @@ -0,0 +1,25 @@ +#ifndef ZOOMEDIT_GUI_RENDERAREA_H_ +#define ZOOMEDIT_GUI_RENDERAREA_H_ + +#include +#include +#include + +namespace ZoomEdit { +namespace Gui { + +class RenderArea : public Gtk::DrawingArea { + public: + RenderArea(BaseObjectType *cobject, const Glib::RefPtr &xml); + virtual ~RenderArea(); + + private: + static GdkGLConfig *glconfig; + + void onRealize(); +}; + +} +} + +#endif /*ZOOMEDIT_GUI_RENDERAREA_H_*/ diff --git a/src/Gui/Window.cpp b/src/Gui/Window.cpp index a90a460..0ec933d 100644 --- a/src/Gui/Window.cpp +++ b/src/Gui/Window.cpp @@ -6,9 +6,13 @@ namespace Gui { Window::Window(BaseObjectType *cobject, const Glib::RefPtr &xml) : Gtk::Window(cobject) { xml->connect_clicked("MenuItemQuit", sigc::mem_fun(this, &Window::hide)); + + xml->get_widget_derived("RenderArea", renderArea); } Window::~Window() { + if(renderArea) + delete renderArea; } } diff --git a/src/Gui/Window.h b/src/Gui/Window.h index f940c1d..89e9f49 100644 --- a/src/Gui/Window.h +++ b/src/Gui/Window.h @@ -3,11 +3,15 @@ #include #include +#include "RenderArea.h" namespace ZoomEdit { namespace Gui { class Window : public Gtk::Window { + private: + RenderArea *renderArea; + public: Window(BaseObjectType *cobject, const Glib::RefPtr &xml); virtual ~Window(); -- cgit v1.2.3