Mercurial > fife-parpg
annotate engine/core/video/opengl/glimage.cpp @ 631:f3457443c95f
* Added drawRectangle() and fillRectangle() functions to the renderers
* Modified FIFE::FloatingTextRenderer to use the new functions
* Updated some data types in FIFE::FloatingTextRenderer to use integer types defined in fife_stdint.h
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 05 Oct 2010 15:44:16 +0000 |
parents | 79257869a6e9 |
children | 5d6b1820b953 |
rev | line source |
---|---|
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 /*************************************************************************** |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 * Copyright (C) 2005-2008 by the FIFE team * |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 * http://www.fifengine.de * |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 * This file is part of FIFE. * |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 * * |
46
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
6 * FIFE is free software; you can redistribute it and/or * |
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
7 * modify it under the terms of the GNU Lesser General Public * |
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
8 * License as published by the Free Software Foundation; either * |
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
9 * version 2.1 of the License, or (at your option) any later version. * |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 * * |
46
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
11 * This library is distributed in the hope that it will be useful, * |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
46
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
14 * Lesser General Public License for more details. * |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
15 * * |
46
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
16 * You should have received a copy of the GNU Lesser General Public * |
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
17 * License along with this library; if not, write to the * |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 * Free Software Foundation, Inc., * |
46
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
20 ***************************************************************************/ |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 // Standard C++ library includes |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 #include <cassert> |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
24 #include <iostream> |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 // 3rd party library includes |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 // FIFE includes |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 // These includes are split up in two parts, separated by one empty line |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 // First block: files included from the FIFE root src directory |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 // Second block: files included from the same folder |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 #include "util/structures/rect.h" |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
32 #include "video/sdl/sdlimage.h" |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 #include "video/renderbackend.h" |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 #include "glimage.h" |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
36 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
37 namespace FIFE { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
38 GLImage::GLImage(SDL_Surface* surface): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
39 Image(surface) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
40 m_sdlimage = new SDLImage(surface); |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
41 |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
42 m_textureids = NULL; |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
43 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 resetGlimage(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
45 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 GLImage::GLImage(const uint8_t* data, unsigned int width, unsigned int height): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
48 Image(data, width, height) { |
627
79257869a6e9
* GLImage now uses the optimal next power of 2 size for both width and height.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
625
diff
changeset
|
49 assert(m_surface); |
79257869a6e9
* GLImage now uses the optimal next power of 2 size for both width and height.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
625
diff
changeset
|
50 m_sdlimage = new SDLImage(m_surface); |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
51 |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
52 m_textureids = NULL; |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
53 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 resetGlimage(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
57 GLImage::~GLImage() { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
58 // remove surface so that deletion happens correctly (by base class destructor) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
59 m_sdlimage->detachSurface(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 delete m_sdlimage; |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
61 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
62 cleanup(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
63 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
64 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
65 void GLImage::resetGlimage() { |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
66 cleanup(); |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
67 |
627
79257869a6e9
* GLImage now uses the optimal next power of 2 size for both width and height.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
625
diff
changeset
|
68 m_chunk_size_w = 0; |
79257869a6e9
* GLImage now uses the optimal next power of 2 size for both width and height.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
625
diff
changeset
|
69 m_chunk_size_h = 0; |
79257869a6e9
* GLImage now uses the optimal next power of 2 size for both width and height.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
625
diff
changeset
|
70 |
425
ad7969d9460b
A client can now specify a global color key to be used with all images. The default color key is (255,0,255) in RGB format. Also the client can enable/disable the color key feature by using the setColorKeyEnabled function in the EngineSettings class. By default the color key feature is disabled. fixes[t:451]
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
263
diff
changeset
|
71 m_colorkey = RenderBackend::instance()->getColorKey(); |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
72 } |
430
ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
425
diff
changeset
|
73 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
74 void GLImage::cleanup() { |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
75 if (m_textureids) { |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
76 glDeleteTextures(1, &m_textureids[0]); |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
77 |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
78 delete[] m_textureids; |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
79 m_textureids = NULL; |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
80 } |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
81 |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
82 m_col_tex_coord = 0; |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
83 m_row_tex_coord = 0; |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
84 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
85 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
86 void GLImage::render(const Rect& rect, SDL_Surface* screen, unsigned char alpha) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
87 if (!m_textureids) { |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
88 generateGLTexture(); |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
89 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
90 |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
91 //not on the screen. dont render |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
92 if (rect.right() < 0 || rect.x > static_cast<int>(screen->w) || rect.bottom() < 0 || rect.y > static_cast<int>(screen->h)) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
93 return; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
94 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
95 |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
96 //completely transparent so dont bother rendering |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
97 if (0 == alpha) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
98 return; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
99 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
100 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
101 // the amount of "zooming" for the image |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
102 float scale_x = static_cast<float>(rect.w) / static_cast<float>(m_surface->w); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
103 float scale_y = static_cast<float>(rect.h) / static_cast<float>(m_surface->h); |
430
ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
425
diff
changeset
|
104 |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
105 // apply the scale to the width and height of the image |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
106 uint16_t w = static_cast<int>(round(scale_x*m_surface->w)); |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
107 uint16_t h = static_cast<int>(round(scale_y*m_surface->h)); |
430
ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
425
diff
changeset
|
108 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
109 /// setting transparency for the whole primitive: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
110 glColor4ub( 255, 255, 255, alpha ); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
111 |
625
92290efadab7
* This fixes a small bug that causes some primitives to not be rendered by the OpenGL renderbackend
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
620
diff
changeset
|
112 glEnable(GL_TEXTURE_2D); |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
113 glBindTexture(GL_TEXTURE_2D, m_textureids[0]); |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
114 |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
115 glBegin(GL_QUADS); |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
116 glTexCoord2f(0.0f, 0.0f); |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
117 glVertex2i(rect.x, rect.y); |
430
ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
425
diff
changeset
|
118 |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
119 glTexCoord2f(0.0f, m_row_tex_coord); |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
120 glVertex2i(rect.x, rect.y + h); |
430
ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
425
diff
changeset
|
121 |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
122 glTexCoord2f(m_col_tex_coord, m_row_tex_coord); |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
123 glVertex2i(rect.x + w, rect.y + h); |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
124 |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
125 glTexCoord2f(m_col_tex_coord, 0.0f); |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
126 glVertex2i(rect.x + w, rect.y); |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
127 glEnd(); |
625
92290efadab7
* This fixes a small bug that causes some primitives to not be rendered by the OpenGL renderbackend
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
620
diff
changeset
|
128 glDisable(GL_TEXTURE_2D); |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
129 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
130 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
131 |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
132 void GLImage::generateGLTexture() { |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
133 const unsigned int width = m_surface->w; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
134 const unsigned int height = m_surface->h; |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
135 |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
136 //calculate the nearest larger power of 2 |
627
79257869a6e9
* GLImage now uses the optimal next power of 2 size for both width and height.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
625
diff
changeset
|
137 m_chunk_size_w = nextPow2(width); |
79257869a6e9
* GLImage now uses the optimal next power of 2 size for both width and height.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
625
diff
changeset
|
138 m_chunk_size_h = nextPow2(height); |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
139 |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
140 // used to calculate the fill ratio for given chunk |
627
79257869a6e9
* GLImage now uses the optimal next power of 2 size for both width and height.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
625
diff
changeset
|
141 m_col_tex_coord = static_cast<float>(m_surface->w%m_chunk_size_w) / static_cast<float>(m_chunk_size_w); |
79257869a6e9
* GLImage now uses the optimal next power of 2 size for both width and height.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
625
diff
changeset
|
142 m_row_tex_coord = static_cast<float>(m_surface->h%m_chunk_size_h) / static_cast<float>(m_chunk_size_h); |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
143 |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
144 if (m_col_tex_coord == 0.0f){ |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
145 m_col_tex_coord = 1.0f; |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
146 } |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
147 |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
148 if (m_row_tex_coord == 0.0f){ |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
149 m_row_tex_coord = 1.0f; |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
150 } |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
151 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
152 uint8_t* data = static_cast<uint8_t*>(m_surface->pixels); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
153 int pitch = m_surface->pitch; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
154 |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
155 |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
156 assert(!m_textureids); |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
157 |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
158 m_textureids = new GLuint[1]; |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
159 memset(m_textureids, 0x00, 1*sizeof(GLuint)); |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
160 |
263
10e0687a4cec
Fixed a bug in the OpenGl renderer where the last chunk of images would not be displayed when image_height % chunk_size was 0.
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
46
diff
changeset
|
161 |
627
79257869a6e9
* GLImage now uses the optimal next power of 2 size for both width and height.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
625
diff
changeset
|
162 uint32_t* oglbuffer = new uint32_t[m_chunk_size_w * m_chunk_size_h]; |
79257869a6e9
* GLImage now uses the optimal next power of 2 size for both width and height.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
625
diff
changeset
|
163 memset(oglbuffer, 0x00, m_chunk_size_w*m_chunk_size_h*sizeof(uint32_t)); |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
164 |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
165 for (unsigned int y = 0; y < height; ++y) { |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
166 for (unsigned int x = 0; x < width; ++x) { |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
167 unsigned int pos = (y * pitch) + (x * 4); |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
168 |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
169 uint8_t r = data[pos + 3]; |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
170 uint8_t g = data[pos + 2]; |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
171 uint8_t b = data[pos + 1]; |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
172 uint8_t a = data[pos + 0]; |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
173 |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
174 if (RenderBackend::instance()->isColorKeyEnabled()) { |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
175 // only set alpha to zero if colorkey feature is enabled |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
176 if (r == m_colorkey.r && g == m_colorkey.g && b == m_colorkey.b) { |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
177 a = 0; |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
178 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
179 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
180 |
627
79257869a6e9
* GLImage now uses the optimal next power of 2 size for both width and height.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
625
diff
changeset
|
181 oglbuffer[(y*m_chunk_size_w) + x] = r | (g << 8) | (b << 16) | (a<<24); |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
182 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
183 } |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
184 |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
185 // get texture id from opengl |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
186 glGenTextures(1, &m_textureids[0]); |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
187 // set focus on that texture |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
188 glBindTexture(GL_TEXTURE_2D, m_textureids[0]); |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
189 // set filters for texture |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
190 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
191 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
192 // transfer data from sdl buffer |
627
79257869a6e9
* GLImage now uses the optimal next power of 2 size for both width and height.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
625
diff
changeset
|
193 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_chunk_size_w, m_chunk_size_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, static_cast<GLvoid*>(oglbuffer)); |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
194 |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
195 delete[] oglbuffer; |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
196 } |
430
ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
425
diff
changeset
|
197 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
198 void GLImage::saveImage(const std::string& filename) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
199 const unsigned int swidth = getWidth(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
200 const unsigned int sheight = getHeight(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
201 SDL_Surface *surface = NULL; |
430
ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
425
diff
changeset
|
202 uint8_t *pixels; |
ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
425
diff
changeset
|
203 |
ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
425
diff
changeset
|
204 surface = SDL_CreateRGBSurface(SDL_SWSURFACE, swidth, |
ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
425
diff
changeset
|
205 sheight, 24, |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
206 RMASK,GMASK,BMASK, NULLMASK); |
430
ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
425
diff
changeset
|
207 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
208 if(surface == NULL) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
209 return; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
210 } |
430
ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
425
diff
changeset
|
211 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
212 SDL_LockSurface(surface); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
213 pixels = new uint8_t[swidth * sheight * 3]; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
214 glReadPixels(0, 0, swidth, sheight, GL_RGB, GL_UNSIGNED_BYTE, reinterpret_cast<GLvoid*>(pixels)); |
430
ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
425
diff
changeset
|
215 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
216 uint8_t *imagepixels = reinterpret_cast<uint8_t*>(surface->pixels); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
217 // Copy the "reversed_image" memory to the "image" memory |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
218 for (int y = (sheight - 1); y >= 0; --y) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
219 uint8_t *rowbegin = pixels + y * swidth * 3; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
220 uint8_t *rowend = rowbegin + swidth * 3; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
221 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
222 std::copy(rowbegin, rowend, imagepixels); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
223 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
224 // Advance a row in the output surface. |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
225 imagepixels += surface->pitch; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
226 } |
430
ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
425
diff
changeset
|
227 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
228 SDL_UnlockSurface(surface); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
229 saveAsPng(filename, *surface); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
230 SDL_FreeSurface(surface); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
231 delete [] pixels; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
232 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
233 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
234 void GLImage::setClipArea(const Rect& cliparea, bool clear) { |
620
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
235 glScissor(cliparea.x, getHeight() - cliparea.y - cliparea.h, cliparea.w, cliparea.h); |
853d25234671
* Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
603
diff
changeset
|
236 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
237 if (clear) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
238 glClear(GL_COLOR_BUFFER_BIT); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
239 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
240 } |
430
ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
425
diff
changeset
|
241 |
583
47b49b9b0c0a
* Improved the floatingtextrenderer. Now you can set an alpha value for font, background quad and border. Splited quad and border into own commands.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
430
diff
changeset
|
242 bool GLImage::putPixel(int x, int y, int r, int g, int b, int a) { |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
243 cleanup(); |
583
47b49b9b0c0a
* Improved the floatingtextrenderer. Now you can set an alpha value for font, background quad and border. Splited quad and border into own commands.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
430
diff
changeset
|
244 return m_sdlimage->putPixel(x, y, r, g, b, a); |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
245 } |
430
ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
425
diff
changeset
|
246 |
583
47b49b9b0c0a
* Improved the floatingtextrenderer. Now you can set an alpha value for font, background quad and border. Splited quad and border into own commands.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
430
diff
changeset
|
247 void GLImage::drawLine(const Point& p1, const Point& p2, int r, int g, int b, int a) { |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
248 cleanup(); |
583
47b49b9b0c0a
* Improved the floatingtextrenderer. Now you can set an alpha value for font, background quad and border. Splited quad and border into own commands.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
430
diff
changeset
|
249 m_sdlimage->drawLine(p1, p2, r, g, b, a); |
430
ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
425
diff
changeset
|
250 } |
ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
425
diff
changeset
|
251 |
583
47b49b9b0c0a
* Improved the floatingtextrenderer. Now you can set an alpha value for font, background quad and border. Splited quad and border into own commands.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
430
diff
changeset
|
252 void GLImage::drawTriangle(const Point& p1, const Point& p2, const Point& p3, int r, int g, int b, int a) { |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
253 cleanup(); |
583
47b49b9b0c0a
* Improved the floatingtextrenderer. Now you can set an alpha value for font, background quad and border. Splited quad and border into own commands.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
430
diff
changeset
|
254 m_sdlimage->drawTriangle(p1, p2, p3, r, g, b, a); |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
255 } |
430
ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
425
diff
changeset
|
256 |
631
f3457443c95f
* Added drawRectangle() and fillRectangle() functions to the renderers
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
627
diff
changeset
|
257 void GLImage::drawRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { |
f3457443c95f
* Added drawRectangle() and fillRectangle() functions to the renderers
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
627
diff
changeset
|
258 cleanup(); |
f3457443c95f
* Added drawRectangle() and fillRectangle() functions to the renderers
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
627
diff
changeset
|
259 m_sdlimage->drawRectangle(p, w, h, r, g, b, a); |
f3457443c95f
* Added drawRectangle() and fillRectangle() functions to the renderers
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
627
diff
changeset
|
260 } |
f3457443c95f
* Added drawRectangle() and fillRectangle() functions to the renderers
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
627
diff
changeset
|
261 |
f3457443c95f
* Added drawRectangle() and fillRectangle() functions to the renderers
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
627
diff
changeset
|
262 void GLImage::fillRectangle(const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { |
f3457443c95f
* Added drawRectangle() and fillRectangle() functions to the renderers
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
627
diff
changeset
|
263 cleanup(); |
f3457443c95f
* Added drawRectangle() and fillRectangle() functions to the renderers
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
627
diff
changeset
|
264 m_sdlimage->fillRectangle(p, w, h, r, g, b, a); |
f3457443c95f
* Added drawRectangle() and fillRectangle() functions to the renderers
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
627
diff
changeset
|
265 } |
f3457443c95f
* Added drawRectangle() and fillRectangle() functions to the renderers
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
627
diff
changeset
|
266 |
583
47b49b9b0c0a
* Improved the floatingtextrenderer. Now you can set an alpha value for font, background quad and border. Splited quad and border into own commands.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
430
diff
changeset
|
267 void GLImage::drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b, int a) { |
430
ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
425
diff
changeset
|
268 cleanup(); |
583
47b49b9b0c0a
* Improved the floatingtextrenderer. Now you can set an alpha value for font, background quad and border. Splited quad and border into own commands.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
430
diff
changeset
|
269 m_sdlimage->drawQuad(p1, p2, p3, p4, r, g, b, a); |
47b49b9b0c0a
* Improved the floatingtextrenderer. Now you can set an alpha value for font, background quad and border. Splited quad and border into own commands.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
430
diff
changeset
|
270 } |
47b49b9b0c0a
* Improved the floatingtextrenderer. Now you can set an alpha value for font, background quad and border. Splited quad and border into own commands.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
430
diff
changeset
|
271 |
47b49b9b0c0a
* Improved the floatingtextrenderer. Now you can set an alpha value for font, background quad and border. Splited quad and border into own commands.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
430
diff
changeset
|
272 void GLImage::drawVertex(const Point& p, const uint8_t size, int r, int g, int b, int a) { |
47b49b9b0c0a
* Improved the floatingtextrenderer. Now you can set an alpha value for font, background quad and border. Splited quad and border into own commands.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
430
diff
changeset
|
273 cleanup(); |
47b49b9b0c0a
* Improved the floatingtextrenderer. Now you can set an alpha value for font, background quad and border. Splited quad and border into own commands.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
430
diff
changeset
|
274 m_sdlimage->drawVertex(p, size, r, g, b, a); |
430
ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
425
diff
changeset
|
275 } |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
276 } |