From 1d595f048c9e59bbff14217e2fe3821ee3e1aaa1 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Sun, 9 May 2010 19:17:52 +0200 Subject: changed from SDL rendering to OpenGL draw, repaint methods do not have the SDL_Surface* parameter anymore --- src/menu/application.cpp | 52 ++++++++++++++++++------ src/menu/application.hpp | 4 +- src/menu/container.cpp | 6 +-- src/menu/container.hpp | 3 +- src/menu/drawable.cpp | 4 +- src/menu/drawable.hpp | 6 +-- src/menu/frame.cpp | 6 ++- src/menu/frame.hpp | 2 +- src/menu/frame_background.hpp | 7 ---- src/menu/frame_background_color.cpp | 13 +++++- src/menu/frame_background_color.hpp | 5 +-- src/menu/reflection.cpp | 2 +- src/menu/reflection.hpp | 2 +- src/menu/software_mouse_pointer.cpp | 79 +++++++++++++++++++++++++++++++++---- src/menu/software_mouse_pointer.hpp | 15 +++++-- 15 files changed, 154 insertions(+), 52 deletions(-) (limited to 'src/menu') diff --git a/src/menu/application.cpp b/src/menu/application.cpp index 48f1291c..e8cbde1a 100644 --- a/src/menu/application.cpp +++ b/src/menu/application.cpp @@ -28,7 +28,7 @@ #include "event_manager.hpp" #include #include "software_mouse_pointer.hpp" - +#include namespace usdx { @@ -74,21 +74,21 @@ namespace usdx return instance; } - void Application::draw(SDL_Surface* display) const + void Application::draw(void) { if (frame) { - frame->repaint(display); + frame->repaint(); } } - void Application::repaint(SDL_Surface* display) const { - DrawableControl::repaint(display); + void Application::repaint(void) { + DrawableControl::repaint(); for (std::list::const_iterator it = overlays.begin(); it != overlays.end(); it++) { - (*it)->repaint(display); + (*it)->repaint(); } } @@ -112,8 +112,8 @@ namespace usdx running = true; while (running) { // repaint everything - repaint(display); - SDL_Flip(display); + repaint(); + SDL_GL_SwapBuffers(); LOG4CXX_TRACE(log, L"repaint"); @@ -123,7 +123,6 @@ namespace usdx case SDL_QUIT: running = false; event_thread.interrupt(); - break; default: event_manager.add_event(event); @@ -143,11 +142,42 @@ namespace usdx void Application::run(void) { if (! display) { + // opengl settings + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + + // center screen + char test[] = "SDL_VIDEO_CENTERED=center"; + SDL_putenv(test); + + // create screen display = SDL_SetVideoMode(display_width, display_height, 24, - SDL_SWSURFACE | - SDL_DOUBLEBUF); + SDL_OPENGL); + + glEnable( GL_TEXTURE_2D ); + + glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); + + glViewport( 0, 0, display_width, display_height ); + + glClear( GL_COLOR_BUFFER_BIT ); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_COLOR_MATERIAL); + + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + + glOrtho(0.0f, display_width, display_height, 0.0f, -1.0f, 1.0f); + + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); } if (! display) { diff --git a/src/menu/application.hpp b/src/menu/application.hpp index cc9ba0c2..914eda71 100644 --- a/src/menu/application.hpp +++ b/src/menu/application.hpp @@ -66,7 +66,7 @@ namespace usdx protected: Application(Control* parent); - void draw(SDL_Surface* display) const; + void draw(void); public: virtual ~Application(); @@ -84,7 +84,7 @@ namespace usdx const int get_frames_per_second(void) const; void set_frames_per_second(int fps); - void repaint(SDL_Surface* display) const; + void repaint(void); }; }; diff --git a/src/menu/container.cpp b/src/menu/container.cpp index edcd5e10..3bed894e 100644 --- a/src/menu/container.cpp +++ b/src/menu/container.cpp @@ -43,16 +43,16 @@ namespace usdx controls.clear(); } - void Container::repaint(SDL_Surface* display) const + void Container::repaint(void) { if (get_visible()) { - draw(display); + draw(); for (std::list::const_iterator it = controls.begin(); it != controls.end(); it++) { - (*it)->repaint(display); + (*it)->repaint(); } } } diff --git a/src/menu/container.hpp b/src/menu/container.hpp index 8ba9466c..6ee6bde2 100644 --- a/src/menu/container.hpp +++ b/src/menu/container.hpp @@ -27,7 +27,6 @@ #ifndef CONTAINER_HPP #define CONTAINER_HPP -#include #include #include "drawable_control.hpp" @@ -46,7 +45,7 @@ namespace usdx /** * Method for redraw all contained objects. */ - void repaint(SDL_Surface* display) const; + void repaint(void); }; }; diff --git a/src/menu/drawable.cpp b/src/menu/drawable.cpp index 0c68affc..37c42b25 100644 --- a/src/menu/drawable.cpp +++ b/src/menu/drawable.cpp @@ -32,10 +32,10 @@ namespace usdx { } - void Drawable::repaint(SDL_Surface* display) const + void Drawable::repaint(void) { if (visible) { - draw(display); + draw(); } }; diff --git a/src/menu/drawable.hpp b/src/menu/drawable.hpp index 28cbd223..bca0ac03 100644 --- a/src/menu/drawable.hpp +++ b/src/menu/drawable.hpp @@ -27,8 +27,6 @@ #ifndef DRAWABLE_HPP #define DRAWABLE_HPP -#include - namespace usdx { /** @@ -43,7 +41,7 @@ namespace usdx /** * Pure virtual method, that descendant classes have to implement. */ - virtual void draw(SDL_Surface* display) const = 0; + virtual void draw(void) = 0; public: Drawable(void); @@ -52,7 +50,7 @@ namespace usdx /** * Method for redraw this Object. If visible issues draw. */ - void repaint(SDL_Surface* display) const; + void repaint(void); /** * Setter for visible. diff --git a/src/menu/frame.cpp b/src/menu/frame.cpp index 228df767..08cc833a 100644 --- a/src/menu/frame.cpp +++ b/src/menu/frame.cpp @@ -56,8 +56,10 @@ namespace usdx return background; } - void Frame::draw(SDL_Surface* display) const + void Frame::draw(void) { - background->repaint(display); + if (background) { + background->repaint(); + } } }; diff --git a/src/menu/frame.hpp b/src/menu/frame.hpp index b337275c..55e0a4db 100644 --- a/src/menu/frame.hpp +++ b/src/menu/frame.hpp @@ -40,7 +40,7 @@ namespace usdx FrameBackground* background; protected: - virtual void draw(SDL_Surface* display) const; + virtual void draw(void); public: Frame(Control* parent); diff --git a/src/menu/frame_background.hpp b/src/menu/frame_background.hpp index a8e7daea..9cb7c504 100644 --- a/src/menu/frame_background.hpp +++ b/src/menu/frame_background.hpp @@ -39,19 +39,12 @@ namespace usdx { public: FrameBackground(); - - // optional methods virtual ~FrameBackground(); - virtual void on_show(void) {} - virtual void on_finish(void) {} - protected: // no copy and no assignment FrameBackground(const FrameBackground&); FrameBackground& operator=(const FrameBackground&); - - virtual void draw(SDL_Surface* display) = 0; }; }; diff --git a/src/menu/frame_background_color.cpp b/src/menu/frame_background_color.cpp index 18483e54..43b1c748 100644 --- a/src/menu/frame_background_color.cpp +++ b/src/menu/frame_background_color.cpp @@ -25,14 +25,23 @@ */ #include "frame_background_color.hpp" +#include namespace usdx { - FrameBackgroundColor::FrameBackgroundColor(RgbColor &color) : color(color) + FrameBackgroundColor::FrameBackgroundColor(RgbColor &color) : + color(color) { } - void FrameBackgroundColor::draw(SDL_Surface* display) const + FrameBackgroundColor::FrameBackgroundColor(void) : + color(0, 0, 0) { } + + void FrameBackgroundColor::draw() + { + glClearColor(color.get_red(), color.get_green(), color.get_blue(), 1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } }; diff --git a/src/menu/frame_background_color.hpp b/src/menu/frame_background_color.hpp index a52e1f13..2e850d2c 100644 --- a/src/menu/frame_background_color.hpp +++ b/src/menu/frame_background_color.hpp @@ -27,8 +27,6 @@ #ifndef FRAME_BACKGROUND_COLOR_HPP #define FRAME_BACKGROUND_COLOR_HPP -#include - #include "frame_background.hpp" #include "utils/rgb_color.hpp" @@ -40,9 +38,10 @@ namespace usdx RgbColor color; protected: - virtual void draw(SDL_Surface* display) const; + void draw(void); public: + FrameBackgroundColor(void); FrameBackgroundColor(RgbColor &color); }; diff --git a/src/menu/reflection.cpp b/src/menu/reflection.cpp index 92ab01e1..1b453f5e 100644 --- a/src/menu/reflection.cpp +++ b/src/menu/reflection.cpp @@ -36,7 +36,7 @@ namespace usdx { } - void Reflection::draw(SDL_Surface* display) const + void Reflection::draw(void) { } diff --git a/src/menu/reflection.hpp b/src/menu/reflection.hpp index aa43491a..af0d70db 100644 --- a/src/menu/reflection.hpp +++ b/src/menu/reflection.hpp @@ -37,7 +37,7 @@ namespace usdx float spacing; protected: - virtual void draw(SDL_Surface* display) const; + virtual void draw(void); public: Reflection(float spacing); diff --git a/src/menu/software_mouse_pointer.cpp b/src/menu/software_mouse_pointer.cpp index 47e00047..1723ce9b 100644 --- a/src/menu/software_mouse_pointer.cpp +++ b/src/menu/software_mouse_pointer.cpp @@ -25,14 +25,55 @@ */ #include "software_mouse_pointer.hpp" -#include +#include +#include namespace usdx { SoftwareMousePointer::SoftwareMousePointer(Control* parent, EventManager* event_manager) : DrawableControl(parent), x(-1), y(-1) { - texture = new Image(L"game/themes/Deluxe/interface/cursor.png"); + this->vertices[0] = 0.0f; + this->vertices[1] = 40.0f; + this->vertices[2] = 0.0f; + this->vertices[3] = 40.0f; + this->vertices[4] = 40.0f; + this->vertices[5] = 0.0f; + this->vertices[6] = 40.0f; + this->vertices[7] = 0.0f; + this->vertices[8] = 0.0f; + this->vertices[9] = 0.0f; + this->vertices[10] = 0.0f; + this->vertices[11] = 0.0f; + + this->color[0] = 255; + this->color[1] = 255; + this->color[2] = 255; + this->color[3] = 100; + this->color[4] = 255; + this->color[5] = 255; + this->color[6] = 255; + this->color[7] = 100; + this->color[8] = 255; + this->color[9] = 255; + this->color[10] = 255; + this->color[11] = 100; + this->color[12] = 255; + this->color[13] = 255; + this->color[14] = 255; + this->color[15] = 100; + + this->texture[0] = 0.0f; + this->texture[1] = 1.0f; + this->texture[2] = 1.0f; + this->texture[3] = 1.0f; + this->texture[4] = 1.0f; + this->texture[5] = 0.0f; + this->texture[6] = 0.0f; + this->texture[7] = 0.0f; + + texture_normal = new Texture(L"game/themes/Deluxe/interface/cursor.png"); + texture_pressed = new Texture(L"game/themes/Deluxe/interface/cursor_pressed.png"); mouse_move_connection = event_manager->mouse_move.connect( boost::bind(&SoftwareMousePointer::on_mouse_move, this, _1, _2)); @@ -42,22 +83,44 @@ namespace usdx { mouse_move_connection.disconnect(); - if (texture != NULL) { - delete texture; - texture = NULL; + if (texture_normal != NULL) { + delete texture_normal; + texture_normal = NULL; } } - void SoftwareMousePointer::draw(SDL_Surface* display) const + void SoftwareMousePointer::draw(void) { + glLoadIdentity(); + + boost::mutex::scoped_lock lock(mutex); + if (x >= 0 && y >= 0) { - SDL_Rect rcDest = { x, y, 0, 0 }; - SDL_BlitSurface((SDL_Surface*)texture->get_surface(), NULL, display, &rcDest); + glTranslatef(x, y, 0.0f); + lock.unlock(); + + glBindTexture(GL_TEXTURE_2D, texture_normal->get_texture()); + + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + + glVertexPointer(3, GL_FLOAT, 0, vertices); + glColorPointer(4, GL_UNSIGNED_BYTE, 0, color); + glTexCoordPointer(2, GL_FLOAT, 0, texture); + + glDrawArrays(GL_QUADS, 0, 4); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); } } void SoftwareMousePointer::on_mouse_move(int x, int y) { + boost::mutex::scoped_lock lock(mutex); + this->x = x; this->y = y; } diff --git a/src/menu/software_mouse_pointer.hpp b/src/menu/software_mouse_pointer.hpp index dad27543..3b29e50e 100644 --- a/src/menu/software_mouse_pointer.hpp +++ b/src/menu/software_mouse_pointer.hpp @@ -30,9 +30,11 @@ #include "drawable_control.hpp" #include "control.hpp" #include "event_manager.hpp" -#include "image.hpp" +#include "texture.hpp" #include +#include +#include namespace usdx { @@ -42,12 +44,19 @@ namespace usdx int x; int y; - Image* texture; + GLfloat vertices[12]; + GLubyte color[16]; + GLfloat texture[8]; + + Texture* texture_normal; + Texture* texture_pressed; boost::signals2::connection mouse_move_connection; + boost::mutex mutex; + protected: - void draw(SDL_Surface* display) const; + void draw(void); public: SoftwareMousePointer(Control* parent, EventManager* event_manager); -- cgit v1.2.3