![]() |
Kukatz 3D
0.1
Török Attila szakdolgozata
|
00001 /* 00002 * guiimage.cpp - Kukatz 3D 00003 * Copyright (c) 2012 - TÖRÖK Attila (torokati44@gmail.com) 00004 * 00005 * This software is provided 'as-is', without any express or implied 00006 * warranty. In no event will the authors be held liable for any damages 00007 * arising from the use of this software. 00008 * 00009 * Permission is granted to anyone to use this software for any purpose, 00010 * including commercial applications, and to alter it and redistribute it 00011 * freely, subject to the following restrictions: 00012 * 00013 * 1. The origin of this software must not be misrepresented; you must not 00014 * claim that you wrote the original software. If you use this software 00015 * in a product, an acknowledgment in the product documentation would be 00016 * appreciated but is not required. 00017 * 00018 * 2. Altered source versions must be plainly marked as such, and must not be 00019 * misrepresented as being the original software. 00020 * 00021 * 3. This notice may not be removed or altered from any source 00022 * distribution. 00023 */ 00024 00025 #include "guiimage.hpp" 00026 00027 #include <iostream> 00028 #include "resourcemanager.hpp" 00029 00030 GUIImage::GUIImage(const std::string& tex): 00031 texture_id(tex), texture_ptr(ResourceManager::instance().textures[tex]), 00032 mode(STRETCH), image_scale(1.0f), color(sf::Color::White) 00033 { 00034 aspect_ratio = (float)texture_ptr->get_width() / (float)texture_ptr->get_height(); 00035 00036 display_list = glGenLists(1); 00037 make_list(); 00038 } 00039 00040 GUIImage::GUIImage(const std::string& tex, float s): 00041 texture_id(tex), texture_ptr(ResourceManager::instance().textures[tex]), 00042 mode(TILE), image_scale(s), color(sf::Color::White) 00043 { 00044 aspect_ratio = (float)texture_ptr->get_width() / (float)texture_ptr->get_height(); 00045 00046 display_list = glGenLists(1); 00047 make_list(); 00048 } 00049 00050 GUIImage::GUIImage(const std::string& tex, const sf::FloatRect& rect): 00051 texture_id(tex), texture_ptr(ResourceManager::instance().textures[tex]), 00052 mode(RECTANGLE), rectangle(rect), image_scale(1.0f), color(sf::Color::White) 00053 { 00054 aspect_ratio = (float)texture_ptr->get_width() / (float)texture_ptr->get_height(); 00055 00056 display_list = glGenLists(1); 00057 make_list(); 00058 } 00059 00060 void GUIImage::make_list() 00061 { 00062 glNewList(display_list, GL_COMPILE); 00063 glBegin(GL_QUADS); 00064 00065 glTexCoord2i(0, 0); 00066 glVertex2i(0, 0); 00067 glTexCoord2i(1, 0); 00068 glVertex2i(1, 0); 00069 glTexCoord2i(1, 1); 00070 glVertex2i(1, 1); 00071 glTexCoord2i(0, 1); 00072 glVertex2i(0, 1); 00073 00074 glEnd(); 00075 glEndList(); 00076 } 00077 00078 void GUIImage::set_mode(const ImageMode& m) 00079 { 00080 if (m != mode) 00081 { 00082 mode = m; 00083 make_list(); 00084 } 00085 } 00086 00087 GUIImage::ImageMode GUIImage::get_mode() 00088 { 00089 return mode; 00090 } 00091 00092 void GUIImage::render() 00093 { 00094 if (visible) 00095 { 00096 ResourceManager::instance().use_program(0); 00097 glDisable(GL_DEPTH_TEST); 00098 texture_ptr->bind(); 00099 00100 glPushMatrix(); 00101 glScalef(size.x, size.y, 1.0f); 00102 00103 glMatrixMode(GL_TEXTURE); 00104 glPushMatrix(); 00105 glLoadIdentity(); 00106 glScalef(1.0f / image_scale, 1.0f / image_scale, 1.0f); 00107 00108 glColor4ub(color.r, color.g, color.b, color.a); 00109 glCallList(display_list); 00110 glColor4ub(255, 255, 255, 255); 00111 00112 glPopMatrix(); 00113 00114 glMatrixMode(GL_MODELVIEW); 00115 glPopMatrix(); 00116 00117 glEnable(GL_DEPTH_TEST); 00118 } 00119 } 00120 00121 GUIImage::~GUIImage() 00122 { 00123 glDeleteLists(display_list, 1); 00124 }