Mercurial > love-experiments
annotate src/modules/graphics/opengl/Graphics.cpp @ 1448:108ee2e81f65 default tip
Fix a case typo, imageData.h -> ImageData.h
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Sat, 18 Jan 2014 13:57:44 +0100 |
| parents | d732e302eae6 |
| children | 923a594c28d1 |
| rev | line source |
|---|---|
| 1096 | 1 /** |
|
1282
b7f097053d74
Updated copyright text for the new year
Alex Szpakowski <slime73@gmail.com>
parents:
1250
diff
changeset
|
2 * Copyright (c) 2006-2013 LOVE Development Team |
| 1096 | 3 * |
| 4 * This software is provided 'as-is', without any express or implied | |
| 5 * warranty. In no event will the authors be held liable for any damages | |
| 6 * arising from the use of this software. | |
| 7 * | |
| 8 * Permission is granted to anyone to use this software for any purpose, | |
| 9 * including commercial applications, and to alter it and redistribute it | |
| 10 * freely, subject to the following restrictions: | |
| 11 * | |
| 12 * 1. The origin of this software must not be misrepresented; you must not | |
| 13 * claim that you wrote the original software. If you use this software | |
| 14 * in a product, an acknowledgment in the product documentation would be | |
| 15 * appreciated but is not required. | |
| 16 * 2. Altered source versions must be plainly marked as such, and must not be | |
| 17 * misrepresented as being the original software. | |
| 18 * 3. This notice may not be removed or altered from any source distribution. | |
| 19 **/ | |
| 20 | |
| 21 #include "common/config.h" | |
| 22 #include "common/math.h" | |
| 23 #include "common/Vector.h" | |
| 24 | |
| 25 #include "Graphics.h" | |
| 26 #include "window/sdl/Window.h" | |
| 27 | |
| 28 #include <vector> | |
| 29 #include <sstream> | |
| 30 #include <algorithm> | |
| 31 #include <iterator> | |
| 32 | |
|
1111
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1107
diff
changeset
|
33 using love::window::WindowFlags; |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1107
diff
changeset
|
34 |
| 1096 | 35 namespace love |
| 36 { | |
| 37 namespace graphics | |
| 38 { | |
| 39 namespace opengl | |
| 40 { | |
| 41 | |
| 42 Graphics::Graphics() | |
| 43 : currentFont(0) | |
| 44 , lineStyle(LINE_SMOOTH) | |
| 45 , lineWidth(1) | |
| 46 , matrixLimit(0) | |
| 47 , userMatrices(0) | |
| 48 { | |
| 49 currentWindow = love::window::sdl::Window::getSingleton(); | |
| 50 } | |
| 51 | |
| 52 Graphics::~Graphics() | |
| 53 { | |
| 54 if (currentFont != 0) | |
| 55 currentFont->release(); | |
| 56 | |
| 57 currentWindow->release(); | |
| 58 } | |
| 59 | |
| 60 const char *Graphics::getName() const | |
| 61 { | |
| 62 return "love.graphics.opengl"; | |
| 63 } | |
| 64 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1307
diff
changeset
|
65 bool Graphics::checkMode(int width, int height, bool fullscreen) const |
| 1096 | 66 { |
| 67 return currentWindow->checkWindowSize(width, height, fullscreen); | |
| 68 } | |
| 69 | |
| 70 DisplayState Graphics::saveState() | |
| 71 { | |
| 72 DisplayState s; | |
| 73 | |
| 74 s.color = getColor(); | |
| 75 s.backgroundColor = getBackgroundColor(); | |
| 76 | |
| 77 s.blendMode = getBlendMode(); | |
| 78 //get line style | |
| 79 s.lineStyle = lineStyle; | |
| 80 //get the point size | |
| 81 glGetFloatv(GL_POINT_SIZE, &s.pointSize); | |
| 82 //get point style | |
| 83 s.pointStyle = (glIsEnabled(GL_POINT_SMOOTH) == GL_TRUE) ? Graphics::POINT_SMOOTH : Graphics::POINT_ROUGH; | |
|
1438
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
84 // get alpha test status |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
85 s.alphaTest = isAlphaTestEnabled(); |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
86 if (s.alphaTest) |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
87 { |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
88 // if alpha testing is enabled, store mode and reference alpha |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
89 s.alphaTestMode = getAlphaTestMode(); |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
90 s.alphaTestRef = getAlphaTestRef(); |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
91 } |
| 1096 | 92 //get scissor status |
| 93 s.scissor = (glIsEnabled(GL_SCISSOR_TEST) == GL_TRUE); | |
| 94 //do we have scissor, if so, store the box | |
| 95 if (s.scissor) | |
| 96 glGetIntegerv(GL_SCISSOR_BOX, s.scissorBox); | |
| 97 | |
|
1328
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
98 for (int i = 0; i < 4; i++) |
|
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
99 s.colorMask[i] = colorMask[i]; |
|
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
100 |
| 1096 | 101 return s; |
| 102 } | |
| 103 | |
| 104 void Graphics::restoreState(const DisplayState &s) | |
| 105 { | |
| 106 setColor(s.color); | |
| 107 setBackgroundColor(s.backgroundColor); | |
| 108 setBlendMode(s.blendMode); | |
| 109 setLine(lineWidth, s.lineStyle); | |
| 110 setPoint(s.pointSize, s.pointStyle); | |
|
1438
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
111 if (s.alphaTest) |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
112 setAlphaTest(s.alphaTestMode, s.alphaTestRef); |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
113 else |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
114 setAlphaTest(); |
| 1096 | 115 if (s.scissor) |
| 116 setScissor(s.scissorBox[0], s.scissorBox[1], s.scissorBox[2], s.scissorBox[3]); | |
| 117 else | |
| 118 setScissor(); | |
|
1328
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
119 setColorMask(s.colorMask[0], s.colorMask[1], s.colorMask[2], s.colorMask[3]); |
| 1096 | 120 } |
| 121 | |
|
1111
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1107
diff
changeset
|
122 bool Graphics::setMode(int width, int height, WindowFlags *flags) |
| 1096 | 123 { |
| 124 // This operation destroys the OpenGL context, so | |
| 125 // we must save the state. | |
| 126 DisplayState tempState; | |
| 127 if (isCreated()) | |
| 128 tempState = saveState(); | |
| 129 | |
|
1106
7428fd56552d
Fix some typos in comments.
Marc Lepage <mlepage@antimeta.com>
parents:
1105
diff
changeset
|
130 // Unload all volatile objects. These must be reloaded after |
| 1096 | 131 // the display mode change. |
| 132 Volatile::unloadAll(); | |
|
1329
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
133 |
|
1203
a7567c5e400f
improved GL texture binding api to take texture units into consideration
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1200
diff
changeset
|
134 uninitializeContext(); |
| 1096 | 135 |
|
1111
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1107
diff
changeset
|
136 bool success = currentWindow->setWindow(width, height, flags); |
|
1333
730ed5f01ab0
Merge in default, update changelog
Bart van Strien <bart.bes+projects@gmail.com>
diff
changeset
|
137 |
| 1096 | 138 // Regardless of failure, we'll have to set up OpenGL once again. |
| 139 width = currentWindow->getWidth(); | |
| 140 height = currentWindow->getHeight(); | |
| 141 | |
| 142 // Okay, setup OpenGL. | |
|
1203
a7567c5e400f
improved GL texture binding api to take texture units into consideration
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1200
diff
changeset
|
143 initializeContext(); |
| 1096 | 144 |
|
1250
8c3108ab0e95
Removed direct OpenGL calls in the SDL Window module
Alex Szpakowski <slime73@gmail.com>
parents:
1239
diff
changeset
|
145 // Make sure antialiasing works when set elsewhere |
|
1433
86757de71c7c
Fixed an OpenGL error when MSAA isn't supported
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
146 if (GLEE_VERSION_1_3 || GLEE_ARB_multisample) |
|
86757de71c7c
Fixed an OpenGL error when MSAA isn't supported
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
147 glEnable(GL_MULTISAMPLE); |
|
1250
8c3108ab0e95
Removed direct OpenGL calls in the SDL Window module
Alex Szpakowski <slime73@gmail.com>
parents:
1239
diff
changeset
|
148 |
| 1096 | 149 // Enable blending |
| 150 glEnable(GL_BLEND); | |
| 151 | |
| 152 // "Normal" blending | |
| 153 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
| 154 | |
|
1328
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
155 // Enable all color component writes. |
|
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
156 setColorMask(true, true, true, true); |
|
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
157 |
| 1096 | 158 // Enable line/point smoothing. |
| 159 setLineStyle(LINE_SMOOTH); | |
| 160 glEnable(GL_POINT_SMOOTH); | |
| 161 glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); | |
| 162 | |
|
1250
8c3108ab0e95
Removed direct OpenGL calls in the SDL Window module
Alex Szpakowski <slime73@gmail.com>
parents:
1239
diff
changeset
|
163 // Auto-generated mipmaps should be the best quality possible |
|
8c3108ab0e95
Removed direct OpenGL calls in the SDL Window module
Alex Szpakowski <slime73@gmail.com>
parents:
1239
diff
changeset
|
164 if (GLEE_VERSION_1_4 || GLEE_SGIS_generate_mipmap) |
|
8c3108ab0e95
Removed direct OpenGL calls in the SDL Window module
Alex Szpakowski <slime73@gmail.com>
parents:
1239
diff
changeset
|
165 glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); |
|
8c3108ab0e95
Removed direct OpenGL calls in the SDL Window module
Alex Szpakowski <slime73@gmail.com>
parents:
1239
diff
changeset
|
166 |
|
1438
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
167 // Set default alpha test mode and value |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
168 glAlphaFunc(GL_GREATER, 0.0f); |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
169 setAlphaTest(); |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
170 |
| 1096 | 171 // Enable textures |
| 172 glEnable(GL_TEXTURE_2D); | |
|
1232
f4a855e7b65d
Improved clarity of some comments, variable names, and functions
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1230
diff
changeset
|
173 setActiveTextureUnit(0); |
| 1096 | 174 |
| 175 // Set the viewport to top-left corner | |
| 176 glViewport(0, 0, width, height); | |
| 177 | |
| 178 // Reset the projection matrix | |
| 179 glMatrixMode(GL_PROJECTION); | |
| 180 glLoadIdentity(); | |
| 181 | |
| 182 // Set up orthographic view (no depth) | |
| 183 glOrtho(0.0, width, height, 0.0, -1.0, 1.0); | |
| 184 | |
| 185 // Reset modelview matrix | |
| 186 glMatrixMode(GL_MODELVIEW); | |
| 187 glLoadIdentity(); | |
| 188 | |
| 189 // Set pixel row alignment | |
| 190 glPixelStorei(GL_UNPACK_ALIGNMENT, 2); | |
| 191 | |
| 192 // Reload all volatile objects. | |
| 193 if (!Volatile::loadAll()) | |
| 194 std::cerr << "Could not reload all volatile objects." << std::endl; | |
| 195 | |
| 196 // Restore the display state. | |
| 197 restoreState(tempState); | |
| 198 | |
| 199 // Get the maximum number of matrices | |
| 200 // subtract a few to give the engine some room. | |
| 201 glGetIntegerv(GL_MAX_MODELVIEW_STACK_DEPTH, &matrixLimit); | |
| 202 matrixLimit -= 5; | |
| 203 | |
| 204 return success; | |
| 205 } | |
| 206 | |
|
1333
730ed5f01ab0
Merge in default, update changelog
Bart van Strien <bart.bes+projects@gmail.com>
diff
changeset
|
207 void Graphics::getMode(int &width, int &height, WindowFlags &flags) const |
| 1096 | 208 { |
|
1111
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1107
diff
changeset
|
209 currentWindow->getWindow(width, height, flags); |
| 1096 | 210 } |
| 211 | |
| 212 bool Graphics::toggleFullscreen() | |
| 213 { | |
|
1111
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1107
diff
changeset
|
214 int width, height; |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1107
diff
changeset
|
215 WindowFlags flags; |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1107
diff
changeset
|
216 currentWindow->getWindow(width, height, flags); |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1107
diff
changeset
|
217 flags.fullscreen = !flags.fullscreen; |
|
9a6a533ac832
Use a flags table for setMode now, implement resizable and borderless windows, and add resize event
Bart van Strien <bart.bes+projects@gmail.com>
parents:
1107
diff
changeset
|
218 return setMode(width, height, &flags); |
| 1096 | 219 } |
| 220 | |
| 221 | |
| 222 void Graphics::reset() | |
| 223 { | |
| 224 DisplayState s; | |
| 225 discardStencil(); | |
| 226 Canvas::bindDefaultCanvas(); | |
|
1233
1cb8b929f662
Renamed all instances of 'ShaderEffect' (previously 'PixelEffect') to 'Shader'.
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1232
diff
changeset
|
227 Shader::detach(); |
| 1096 | 228 restoreState(s); |
| 229 } | |
| 230 | |
| 231 void Graphics::clear() | |
| 232 { | |
| 233 glClear(GL_COLOR_BUFFER_BIT); | |
| 234 } | |
| 235 | |
| 236 void Graphics::present() | |
| 237 { | |
| 238 currentWindow->swapBuffers(); | |
| 239 } | |
| 240 | |
| 241 void Graphics::setIcon(Image *image) | |
| 242 { | |
|
1425
4d66b8cbe5a9
Removed an unused graphics Image method
Alex Szpakowski <slime73@gmail.com>
parents:
1421
diff
changeset
|
243 if (image->isCompressed()) |
| 1421 | 244 throw love::Exception("Cannot use compressed image data to set an icon."); |
|
1425
4d66b8cbe5a9
Removed an unused graphics Image method
Alex Szpakowski <slime73@gmail.com>
parents:
1421
diff
changeset
|
245 |
| 1096 | 246 currentWindow->setIcon(image->getData()); |
| 247 } | |
| 248 | |
| 249 void Graphics::setCaption(const char *caption) | |
| 250 { | |
| 251 std::string title(caption); | |
| 252 currentWindow->setWindowTitle(title); | |
| 253 } | |
| 254 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1307
diff
changeset
|
255 int Graphics::getCaption(lua_State *L) const |
| 1096 | 256 { |
| 257 std::string title = currentWindow->getWindowTitle(); | |
| 258 lua_pushstring(L, title.c_str()); | |
| 259 return 1; | |
| 260 } | |
| 261 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1307
diff
changeset
|
262 int Graphics::getWidth() const |
| 1096 | 263 { |
| 264 return currentWindow->getWidth(); | |
| 265 } | |
| 266 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1307
diff
changeset
|
267 int Graphics::getHeight() const |
| 1096 | 268 { |
| 269 return currentWindow->getHeight(); | |
| 270 } | |
| 271 | |
|
1365
ed450b9c8bb4
love.graphics.newScreenshot now uses the size of the current canvas (if applicable), instead of adding transparency or clipping to match the screen size
Alex Szpakowski <slime73@gmail.com>
parents:
1364
diff
changeset
|
272 int Graphics::getRenderWidth() const |
|
ed450b9c8bb4
love.graphics.newScreenshot now uses the size of the current canvas (if applicable), instead of adding transparency or clipping to match the screen size
Alex Szpakowski <slime73@gmail.com>
parents:
1364
diff
changeset
|
273 { |
|
ed450b9c8bb4
love.graphics.newScreenshot now uses the size of the current canvas (if applicable), instead of adding transparency or clipping to match the screen size
Alex Szpakowski <slime73@gmail.com>
parents:
1364
diff
changeset
|
274 if (Canvas::current) |
|
ed450b9c8bb4
love.graphics.newScreenshot now uses the size of the current canvas (if applicable), instead of adding transparency or clipping to match the screen size
Alex Szpakowski <slime73@gmail.com>
parents:
1364
diff
changeset
|
275 return Canvas::current->getWidth(); |
|
ed450b9c8bb4
love.graphics.newScreenshot now uses the size of the current canvas (if applicable), instead of adding transparency or clipping to match the screen size
Alex Szpakowski <slime73@gmail.com>
parents:
1364
diff
changeset
|
276 return getWidth(); |
|
ed450b9c8bb4
love.graphics.newScreenshot now uses the size of the current canvas (if applicable), instead of adding transparency or clipping to match the screen size
Alex Szpakowski <slime73@gmail.com>
parents:
1364
diff
changeset
|
277 } |
|
ed450b9c8bb4
love.graphics.newScreenshot now uses the size of the current canvas (if applicable), instead of adding transparency or clipping to match the screen size
Alex Szpakowski <slime73@gmail.com>
parents:
1364
diff
changeset
|
278 |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1307
diff
changeset
|
279 int Graphics::getRenderHeight() const |
| 1096 | 280 { |
| 281 if (Canvas::current) | |
| 282 return Canvas::current->getHeight(); | |
| 283 return getHeight(); | |
| 284 } | |
| 285 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1307
diff
changeset
|
286 bool Graphics::isCreated() const |
| 1096 | 287 { |
| 288 return currentWindow->isCreated(); | |
| 289 } | |
| 290 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1307
diff
changeset
|
291 int Graphics::getModes(lua_State *L) const |
| 1096 | 292 { |
| 293 int n; | |
|
1418
357697c2e2a8
More internal code cleanup
Alex Szpakowski <slime73@gmail.com>
parents:
1410
diff
changeset
|
294 love::window::Window::WindowSize *modes = currentWindow->getFullscreenSizes(n); |
| 1096 | 295 |
| 296 if (modes == 0) | |
| 297 return 0; | |
| 298 | |
|
1418
357697c2e2a8
More internal code cleanup
Alex Szpakowski <slime73@gmail.com>
parents:
1410
diff
changeset
|
299 lua_createtable(L, n, 0); |
| 1096 | 300 |
| 301 for (int i = 0; i < n ; i++) | |
| 302 { | |
| 303 lua_pushinteger(L, i+1); | |
|
1418
357697c2e2a8
More internal code cleanup
Alex Szpakowski <slime73@gmail.com>
parents:
1410
diff
changeset
|
304 lua_createtable(L, 0, 2); |
| 1096 | 305 |
| 306 // Inner table attribs. | |
| 307 | |
|
1418
357697c2e2a8
More internal code cleanup
Alex Szpakowski <slime73@gmail.com>
parents:
1410
diff
changeset
|
308 lua_pushinteger(L, modes[i].width); |
|
357697c2e2a8
More internal code cleanup
Alex Szpakowski <slime73@gmail.com>
parents:
1410
diff
changeset
|
309 lua_setfield(L, -2, "width"); |
| 1096 | 310 |
|
1418
357697c2e2a8
More internal code cleanup
Alex Szpakowski <slime73@gmail.com>
parents:
1410
diff
changeset
|
311 lua_pushinteger(L, modes[i].height); |
|
357697c2e2a8
More internal code cleanup
Alex Szpakowski <slime73@gmail.com>
parents:
1410
diff
changeset
|
312 lua_setfield(L, -2, "height"); |
| 1096 | 313 |
| 314 // Inner table attribs end. | |
| 315 | |
| 316 lua_settable(L, -3); | |
| 317 } | |
| 318 | |
| 319 delete[] modes; | |
| 320 return 1; | |
| 321 } | |
| 322 | |
| 323 void Graphics::setScissor(int x, int y, int width, int height) | |
| 324 { | |
| 325 glEnable(GL_SCISSOR_TEST); | |
| 326 glScissor(x, getRenderHeight() - (y + height), width, height); // Compensates for the fact that our y-coordinate is reverse of OpenGLs. | |
| 327 } | |
| 328 | |
| 329 void Graphics::setScissor() | |
| 330 { | |
| 331 glDisable(GL_SCISSOR_TEST); | |
| 332 } | |
| 333 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1307
diff
changeset
|
334 int Graphics::getScissor(lua_State *L) const |
| 1096 | 335 { |
| 336 if (glIsEnabled(GL_SCISSOR_TEST) == GL_FALSE) | |
| 337 return 0; | |
| 338 | |
| 339 GLint scissor[4]; | |
| 340 glGetIntegerv(GL_SCISSOR_BOX, scissor); | |
| 341 | |
| 342 lua_pushnumber(L, scissor[0]); | |
| 343 lua_pushnumber(L, getRenderHeight() - (scissor[1] + scissor[3])); // Compensates for the fact that our y-coordinate is reverse of OpenGLs. | |
| 344 lua_pushnumber(L, scissor[2]); | |
| 345 lua_pushnumber(L, scissor[3]); | |
| 346 | |
| 347 return 4; | |
| 348 } | |
| 349 | |
| 350 void Graphics::defineStencil() | |
| 351 { | |
|
1425
4d66b8cbe5a9
Removed an unused graphics Image method
Alex Szpakowski <slime73@gmail.com>
parents:
1421
diff
changeset
|
352 // Disable color writes but don't save the mask values. |
| 1096 | 353 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); |
|
1425
4d66b8cbe5a9
Removed an unused graphics Image method
Alex Szpakowski <slime73@gmail.com>
parents:
1421
diff
changeset
|
354 |
|
4d66b8cbe5a9
Removed an unused graphics Image method
Alex Szpakowski <slime73@gmail.com>
parents:
1421
diff
changeset
|
355 glClear(GL_STENCIL_BUFFER_BIT); |
| 1096 | 356 glEnable(GL_STENCIL_TEST); |
| 357 glStencilFunc(GL_ALWAYS, 1, 1); | |
| 358 glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); | |
| 359 } | |
| 360 | |
| 361 void Graphics::useStencil(bool invert) | |
| 362 { | |
| 363 glStencilFunc(GL_EQUAL, (int)(!invert), 1); // invert ? 0 : 1 | |
| 364 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); | |
|
1328
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
365 setColorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]); |
| 1096 | 366 } |
| 367 | |
| 368 void Graphics::discardStencil() | |
| 369 { | |
|
1328
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
370 setColorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]); |
| 1096 | 371 glDisable(GL_STENCIL_TEST); |
| 372 } | |
| 373 | |
|
1438
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
374 void Graphics::setAlphaTest(Graphics::AlphaTestMode mode, unsigned char refalpha) |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
375 { |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
376 GLclampf ref = refalpha / 255.0f; |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
377 |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
378 glEnable(GL_ALPHA_TEST); |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
379 |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
380 switch (mode) |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
381 { |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
382 case ALPHATEST_LESS: |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
383 glAlphaFunc(GL_LESS, ref); |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
384 break; |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
385 case ALPHATEST_LEQUAL: |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
386 glAlphaFunc(GL_LEQUAL, ref); |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
387 break; |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
388 case ALPHATEST_EQUAL: |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
389 glAlphaFunc(GL_EQUAL, ref); |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
390 break; |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
391 case ALPHATEST_NOTEQUAL: |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
392 glAlphaFunc(GL_NOTEQUAL, ref); |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
393 break; |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
394 case ALPHATEST_GEQUAL: |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
395 glAlphaFunc(GL_GEQUAL, ref); |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
396 break; |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
397 case ALPHATEST_GREATER: |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
398 glAlphaFunc(GL_GREATER, ref); |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
399 break; |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
400 default: |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
401 glDisable(GL_ALPHA_TEST); |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
402 break; |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
403 } |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
404 } |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
405 |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
406 void Graphics::setAlphaTest() |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
407 { |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
408 glDisable(GL_ALPHA_TEST); |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
409 } |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
410 |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
411 bool Graphics::isAlphaTestEnabled() |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
412 { |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
413 return glIsEnabled(GL_ALPHA_TEST) == GL_TRUE; |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
414 } |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
415 |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
416 Graphics::AlphaTestMode Graphics::getAlphaTestMode() |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
417 { |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
418 GLint func; |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
419 glGetIntegerv(GL_ALPHA_TEST_FUNC, &func); |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
420 |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
421 switch (func) |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
422 { |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
423 case GL_LESS: |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
424 return ALPHATEST_LESS; |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
425 case GL_LEQUAL: |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
426 return ALPHATEST_LEQUAL; |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
427 case GL_EQUAL: |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
428 return ALPHATEST_EQUAL; |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
429 case GL_NOTEQUAL: |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
430 return ALPHATEST_NOTEQUAL; |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
431 case GL_GEQUAL: |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
432 return ALPHATEST_GEQUAL; |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
433 case GL_GREATER: |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
434 return ALPHATEST_GREATER; |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
435 default: |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
436 return ALPHATEST_MAX_ENUM; |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
437 } |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
438 } |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
439 |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
440 unsigned char Graphics::getAlphaTestRef() |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
441 { |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
442 GLfloat ref; |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
443 glGetFloatv(GL_ALPHA_TEST_REF, &ref); |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
444 |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
445 return ref * 255; |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
446 } |
|
6f9dbdeae2c6
Added love.graphics.setAlphaTest (issue #534)
Alex Szpakowski <slime73@gmail.com>
parents:
1436
diff
changeset
|
447 |
| 1096 | 448 Image *Graphics::newImage(love::image::ImageData *data) |
| 449 { | |
| 450 // Create the image. | |
| 451 Image *image = new Image(data); | |
| 452 bool success; | |
| 453 try | |
| 454 { | |
| 455 success = image->load(); | |
| 456 } | |
|
1182
639924c0fe39
Removed names of unused parameters to quiet noisy compilers
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1179
diff
changeset
|
457 catch(love::Exception &) |
| 1096 | 458 { |
| 459 image->release(); | |
| 1179 | 460 throw; |
| 1096 | 461 } |
| 462 if (!success) | |
| 463 { | |
| 464 image->release(); | |
| 465 return 0; | |
| 466 } | |
| 467 | |
| 468 return image; | |
| 469 } | |
| 470 | |
|
1420
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
471 Image *Graphics::newImage(love::image::CompressedData *cdata) |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
472 { |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
473 // Create the image. |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
474 Image *image = new Image(cdata); |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
475 bool success; |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
476 try |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
477 { |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
478 success = image->load(); |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
479 } |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
480 catch(love::Exception &) |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
481 { |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
482 image->release(); |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
483 throw; |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
484 } |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
485 if (!success) |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
486 { |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
487 image->release(); |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
488 return 0; |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
489 } |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
490 |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
491 return image; |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
492 } |
|
2a5ef265e040
Added support for DXT1/3/5 and BC5/7 compressed textures via love.image.CompressedData. Some internals are still iffy.
Alex Szpakowski <slime73@gmail.com>
parents:
1418
diff
changeset
|
493 |
| 1096 | 494 Quad *Graphics::newQuad(float x, float y, float w, float h, float sw, float sh) |
| 495 { | |
| 496 Quad::Viewport v; | |
| 497 v.x = x; | |
| 498 v.y = y; | |
| 499 v.w = w; | |
| 500 v.h = h; | |
| 501 return new Quad(v, sw, sh); | |
| 502 } | |
| 503 | |
| 504 Font *Graphics::newFont(love::font::Rasterizer *r, const Image::Filter &filter) | |
| 505 { | |
|
1307
1c61424c6024
Cleaned up exception handling code when creating new fonts, spritebatches, and shaders
Alex Szpakowski <slime73@gmail.com>
parents:
1306
diff
changeset
|
506 return new Font(r, filter); |
| 1096 | 507 } |
| 508 | |
| 509 SpriteBatch *Graphics::newSpriteBatch(Image *image, int size, int usage) | |
| 510 { | |
|
1307
1c61424c6024
Cleaned up exception handling code when creating new fonts, spritebatches, and shaders
Alex Szpakowski <slime73@gmail.com>
parents:
1306
diff
changeset
|
511 return new SpriteBatch(image, size, usage); |
| 1096 | 512 } |
| 513 | |
| 514 ParticleSystem *Graphics::newParticleSystem(Image *image, int size) | |
| 515 { | |
| 516 return new ParticleSystem(image, size); | |
| 517 } | |
| 518 | |
|
1137
4296fccb2da4
Fix Issue #476: Add HDR Canvas (thanks, Alexander Szpakowski!).
vrld <vrld@vrld.org>
parents:
1107
diff
changeset
|
519 Canvas *Graphics::newCanvas(int width, int height, Canvas::TextureType texture_type) |
| 1096 | 520 { |
|
1399
fa3eabb3602a
Added MRT support to canvases via love.graphics.setCanvases(c1, c2, ...), and an 'effects' callback function in shaders.
Alex Szpakowski <slime73@gmail.com>
parents:
1397
diff
changeset
|
521 if (texture_type == Canvas::TYPE_HDR && !Canvas::isHDRSupported()) |
|
1137
4296fccb2da4
Fix Issue #476: Add HDR Canvas (thanks, Alexander Szpakowski!).
vrld <vrld@vrld.org>
parents:
1107
diff
changeset
|
522 throw Exception("HDR Canvases are not supported by your OpenGL implementation"); |
|
4296fccb2da4
Fix Issue #476: Add HDR Canvas (thanks, Alexander Szpakowski!).
vrld <vrld@vrld.org>
parents:
1107
diff
changeset
|
523 |
|
4296fccb2da4
Fix Issue #476: Add HDR Canvas (thanks, Alexander Szpakowski!).
vrld <vrld@vrld.org>
parents:
1107
diff
changeset
|
524 while (GL_NO_ERROR != glGetError()) |
|
4296fccb2da4
Fix Issue #476: Add HDR Canvas (thanks, Alexander Szpakowski!).
vrld <vrld@vrld.org>
parents:
1107
diff
changeset
|
525 /* clear opengl error flag */; |
|
4296fccb2da4
Fix Issue #476: Add HDR Canvas (thanks, Alexander Szpakowski!).
vrld <vrld@vrld.org>
parents:
1107
diff
changeset
|
526 |
|
4296fccb2da4
Fix Issue #476: Add HDR Canvas (thanks, Alexander Szpakowski!).
vrld <vrld@vrld.org>
parents:
1107
diff
changeset
|
527 Canvas *canvas = new Canvas(width, height, texture_type); |
| 1096 | 528 GLenum err = canvas->getStatus(); |
| 529 | |
|
1106
7428fd56552d
Fix some typos in comments.
Marc Lepage <mlepage@antimeta.com>
parents:
1105
diff
changeset
|
530 // everything ok, return canvas (early out) |
| 1096 | 531 if (err == GL_FRAMEBUFFER_COMPLETE) |
| 532 return canvas; | |
| 533 | |
| 534 // create error message | |
| 535 std::stringstream error_string; | |
| 536 error_string << "Cannot create canvas: "; | |
| 537 switch (err) | |
| 538 { | |
| 539 | |
| 540 case GL_FRAMEBUFFER_UNSUPPORTED: | |
| 541 error_string << "Not supported by your OpenGL implementation."; | |
| 542 break; | |
| 543 | |
| 544 // remaining error codes are highly unlikely: | |
| 545 case GL_FRAMEBUFFER_UNDEFINED: | |
| 546 case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: | |
| 547 case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: | |
| 548 case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: | |
| 549 case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: | |
| 550 case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: | |
| 551 error_string << "Error in implementation. Possible fix: Make canvas width and height powers of two."; | |
| 552 break; | |
| 553 | |
| 554 default: | |
| 555 // my intel hda card wrongly returns 0 to glCheckFramebufferStatus() but sets | |
| 556 // no error flag. I think it meant to return GL_FRAMEBUFFER_UNSUPPORTED, but who | |
| 557 // knows. | |
| 558 if (glGetError() == GL_NO_ERROR) | |
| 559 error_string << "May not be supported by your OpenGL implementation."; | |
| 560 // the remaining error is an indication of a serious fuckup since it should | |
| 561 // only be returned if glCheckFramebufferStatus() was called with the wrong | |
| 562 // arguments. | |
| 563 else | |
| 564 error_string << "Cannot create canvas: Aliens did it (OpenGL error code: " << glGetError() << ")"; | |
| 565 } | |
| 566 | |
| 567 canvas->release(); | |
| 568 throw Exception(error_string.str().c_str()); | |
| 569 return NULL; // never reached | |
| 570 } | |
| 571 | |
|
1239
61021c783f82
Improved shader member variable names, fixed up XCode project file
Alex Szpakowski <slime73@gmail.com>
parents:
1235
diff
changeset
|
572 Shader *Graphics::newShader(const Shader::ShaderSources &sources) |
| 1096 | 573 { |
|
1307
1c61424c6024
Cleaned up exception handling code when creating new fonts, spritebatches, and shaders
Alex Szpakowski <slime73@gmail.com>
parents:
1306
diff
changeset
|
574 return new Shader(sources); |
| 1096 | 575 } |
| 576 | |
| 577 void Graphics::setColor(const Color &c) | |
| 578 { | |
|
1442
d732e302eae6
Internally keep track of the value of the current color (issue #564)
Alex Szpakowski <slime73@gmail.com>
parents:
1439
diff
changeset
|
579 opengl::setCurrentColor(c); |
| 1096 | 580 } |
| 581 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1307
diff
changeset
|
582 Color Graphics::getColor() const |
| 1096 | 583 { |
|
1442
d732e302eae6
Internally keep track of the value of the current color (issue #564)
Alex Szpakowski <slime73@gmail.com>
parents:
1439
diff
changeset
|
584 return opengl::getCurrentColor(); |
| 1096 | 585 } |
| 586 | |
| 587 void Graphics::setBackgroundColor(const Color &c) | |
| 588 { | |
| 589 glClearColor((float)c.r/255.0f, (float)c.g/255.0f, (float)c.b/255.0f, (float)c.a/255.0f); | |
| 590 } | |
| 591 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1307
diff
changeset
|
592 Color Graphics::getBackgroundColor() const |
| 1096 | 593 { |
| 594 float c[4]; | |
| 595 glGetFloatv(GL_COLOR_CLEAR_VALUE, c); | |
| 596 | |
| 597 Color t; | |
| 598 t.r = (unsigned char)(255.0f*c[0]); | |
| 599 t.g = (unsigned char)(255.0f*c[1]); | |
| 600 t.b = (unsigned char)(255.0f*c[2]); | |
| 601 t.a = (unsigned char)(255.0f*c[3]); | |
| 602 | |
| 603 return t; | |
| 604 } | |
| 605 | |
| 606 void Graphics::setFont(Font *font) | |
| 607 { | |
| 608 if (currentFont != 0) | |
| 609 currentFont->release(); | |
| 610 | |
| 611 currentFont = font; | |
| 612 | |
| 613 if (font != 0) | |
| 614 currentFont->retain(); | |
| 615 } | |
| 616 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1307
diff
changeset
|
617 Font *Graphics::getFont() const |
| 1096 | 618 { |
| 619 return currentFont; | |
| 620 } | |
| 621 | |
|
1328
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
622 void Graphics::setColorMask(bool r, bool g, bool b, bool a) |
|
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
623 { |
|
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
624 colorMask[0] = r; |
|
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
625 colorMask[1] = g; |
|
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
626 colorMask[2] = b; |
|
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
627 colorMask[3] = a; |
|
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
628 |
|
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
629 glColorMask((GLboolean) r, (GLboolean) g, (GLboolean) b, (GLboolean) a); |
|
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
630 } |
|
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
631 |
|
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
632 const bool *Graphics::getColorMask() const |
|
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
633 { |
|
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
634 return colorMask; |
|
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
635 } |
|
0089652f335f
Added love.graphics.setColorMask(r, g, b, a) and love.graphics.getColorMask()
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
636 |
| 1096 | 637 void Graphics::setBlendMode(Graphics::BlendMode mode) |
| 638 { | |
|
1329
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
639 const int gl_1_4 = GLEE_VERSION_1_4; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
640 |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
641 GLenum func = GL_FUNC_ADD; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
642 GLenum src_rgb = GL_ONE; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
643 GLenum src_a = GL_ONE; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
644 GLenum dst_rgb = GL_ZERO; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
645 GLenum dst_a = GL_ZERO; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
646 |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
647 switch (mode) |
| 1096 | 648 { |
|
1329
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
649 case BLEND_ALPHA: |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
650 if (gl_1_4 || GLEE_EXT_blend_func_separate) |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
651 { |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
652 src_rgb = GL_SRC_ALPHA; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
653 src_a = GL_ONE; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
654 dst_rgb = dst_a = GL_ONE_MINUS_SRC_ALPHA; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
655 } |
| 1096 | 656 else |
|
1329
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
657 { |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
658 // Fallback for OpenGL implementations without support for separate blend functions. |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
659 // This will most likely only be used for the Microsoft software renderer and |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
660 // since it's still stuck with OpenGL 1.1, the only expected difference is a |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
661 // different alpha value when reading back the default framebuffer (newScreenshot). |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
662 src_rgb = src_a = GL_SRC_ALPHA; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
663 dst_rgb = dst_a = GL_ONE_MINUS_SRC_ALPHA; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
664 } |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
665 break; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
666 case BLEND_MULTIPLICATIVE: |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
667 src_rgb = src_a = GL_DST_COLOR; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
668 dst_rgb = dst_a = GL_ZERO; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
669 break; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
670 case BLEND_PREMULTIPLIED: |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
671 src_rgb = src_a = GL_ONE; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
672 dst_rgb = dst_a = GL_ONE_MINUS_SRC_ALPHA; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
673 break; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
674 case BLEND_SUBTRACTIVE: |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
675 func = GL_FUNC_REVERSE_SUBTRACT; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
676 case BLEND_ADDITIVE: |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
677 src_rgb = src_a = GL_SRC_ALPHA; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
678 dst_rgb = dst_a = GL_ONE; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
679 break; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
680 case BLEND_NONE: |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
681 default: |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
682 src_rgb = src_a = GL_ONE; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
683 dst_rgb = dst_a = GL_ZERO; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
684 break; |
| 1096 | 685 } |
|
1329
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
686 |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
687 if (gl_1_4 || GLEE_ARB_imaging) |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
688 glBlendEquation(func); |
| 1096 | 689 else if (GLEE_EXT_blend_minmax && GLEE_EXT_blend_subtract) |
|
1329
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
690 glBlendEquationEXT(func); |
| 1096 | 691 else |
| 692 { | |
|
1329
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
693 if (func == GL_FUNC_REVERSE_SUBTRACT) |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
694 throw Exception("This graphics card does not support the subtractive blend mode!"); |
| 1096 | 695 // GL_FUNC_ADD is the default even without access to glBlendEquation, so that'll still work. |
| 696 } | |
| 697 | |
|
1329
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
698 if (src_rgb == src_a && dst_rgb == dst_a) |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
699 glBlendFunc(src_rgb, dst_rgb); |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
700 else |
| 1096 | 701 { |
|
1329
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
702 if (gl_1_4) |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
703 glBlendFuncSeparate(src_rgb, dst_rgb, src_a, dst_a); |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
704 else if (GLEE_EXT_blend_func_separate) |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
705 glBlendFuncSeparateEXT(src_rgb, dst_rgb, src_a, dst_a); |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
706 else |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
707 throw Exception("This graphics card does not support separated rgb and alpha blend functions!"); |
| 1096 | 708 } |
| 709 } | |
| 710 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1307
diff
changeset
|
711 Graphics::BlendMode Graphics::getBlendMode() const |
| 1096 | 712 { |
|
1329
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
713 const int gl_1_4 = GLEE_VERSION_1_4; |
|
1311
6cb3ba5f25c1
Fixed love.graphics.getBlendMode on systems which don't support the subtractive blend mode
Alex Szpakowski <slime73@gmail.com>
parents:
1310
diff
changeset
|
714 |
|
1329
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
715 GLint src_rgb, src_a, dst_rgb, dst_a; |
|
1311
6cb3ba5f25c1
Fixed love.graphics.getBlendMode on systems which don't support the subtractive blend mode
Alex Szpakowski <slime73@gmail.com>
parents:
1310
diff
changeset
|
716 GLint equation = GL_FUNC_ADD; |
|
6cb3ba5f25c1
Fixed love.graphics.getBlendMode on systems which don't support the subtractive blend mode
Alex Szpakowski <slime73@gmail.com>
parents:
1310
diff
changeset
|
717 |
|
1329
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
718 if (gl_1_4 || GLEE_EXT_blend_func_separate) |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
719 { |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
720 glGetIntegerv(GL_BLEND_SRC_RGB, &src_rgb); |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
721 glGetIntegerv(GL_BLEND_SRC_ALPHA, &src_a); |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
722 glGetIntegerv(GL_BLEND_DST_RGB, &dst_rgb); |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
723 glGetIntegerv(GL_BLEND_DST_ALPHA, &dst_a); |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
724 } |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
725 else |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
726 { |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
727 glGetIntegerv(GL_BLEND_SRC, &src_rgb); |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
728 glGetIntegerv(GL_BLEND_DST, &dst_rgb); |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
729 src_a = src_rgb; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
730 dst_a = dst_rgb; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
731 } |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
732 |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
733 if (gl_1_4 || GLEE_ARB_imaging || (GLEE_EXT_blend_minmax && GLEE_EXT_blend_subtract)) |
|
1311
6cb3ba5f25c1
Fixed love.graphics.getBlendMode on systems which don't support the subtractive blend mode
Alex Szpakowski <slime73@gmail.com>
parents:
1310
diff
changeset
|
734 glGetIntegerv(GL_BLEND_EQUATION, &equation); |
| 1096 | 735 |
| 736 if (equation == GL_FUNC_REVERSE_SUBTRACT) // && src == GL_SRC_ALPHA && dst == GL_ONE | |
| 737 return BLEND_SUBTRACTIVE; | |
|
1329
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
738 // Everything else has equation == GL_FUNC_ADD. |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
739 else if (src_rgb == src_a && dst_rgb == dst_a) |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
740 { |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
741 if (src_rgb == GL_SRC_ALPHA && dst_rgb == GL_ONE) |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
742 return BLEND_ADDITIVE; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
743 else if (src_rgb == GL_SRC_ALPHA && dst_rgb == GL_ONE_MINUS_SRC_ALPHA) |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
744 return BLEND_ALPHA; // alpha blend mode fallback for very old OpenGL versions. |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
745 else if (src_rgb == GL_DST_COLOR && dst_rgb == GL_ZERO) |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
746 return BLEND_MULTIPLICATIVE; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
747 else if (src_rgb == GL_ONE && dst_rgb == GL_ONE_MINUS_SRC_ALPHA) |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
748 return BLEND_PREMULTIPLIED; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
749 else if (src_rgb == GL_ONE && dst_rgb == GL_ZERO) |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
750 return BLEND_NONE; |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
751 } |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
752 else if (src_rgb == GL_SRC_ALPHA && src_a == GL_ONE && |
|
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
753 dst_rgb == GL_ONE_MINUS_SRC_ALPHA && dst_a == GL_ONE_MINUS_SRC_ALPHA) |
| 1096 | 754 return BLEND_ALPHA; |
| 755 | |
|
1329
7888160f9a41
The "alpha" blend mode now outputs more useful/intuitive alpha values (thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
756 throw Exception("Unknown blend mode"); |
| 1096 | 757 } |
| 758 | |
|
1396
c70b35593b3d
Renamed love.graphics.setDefaultImageFilter to love.graphics.setDefaultFilter
Alex Szpakowski <slime73@gmail.com>
parents:
1394
diff
changeset
|
759 void Graphics::setDefaultFilter(const Image::Filter &f) |
|
1172
1bf09d0c4a54
Applied patch from issue #542 (texture filtering inconsistencies) in main LÖVE repository
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1157
diff
changeset
|
760 { |
|
1bf09d0c4a54
Applied patch from issue #542 (texture filtering inconsistencies) in main LÖVE repository
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1157
diff
changeset
|
761 Image::setDefaultFilter(f); |
|
1bf09d0c4a54
Applied patch from issue #542 (texture filtering inconsistencies) in main LÖVE repository
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1157
diff
changeset
|
762 } |
|
1bf09d0c4a54
Applied patch from issue #542 (texture filtering inconsistencies) in main LÖVE repository
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1157
diff
changeset
|
763 |
|
1396
c70b35593b3d
Renamed love.graphics.setDefaultImageFilter to love.graphics.setDefaultFilter
Alex Szpakowski <slime73@gmail.com>
parents:
1394
diff
changeset
|
764 const Image::Filter &Graphics::getDefaultFilter() const |
| 1096 | 765 { |
| 766 return Image::getDefaultFilter(); | |
| 767 } | |
| 768 | |
|
1394
8c7ef7189365
Moved anisotropic filtering to Image:setFilter(min, mag, anisotropy), added anisotropic filtering support to canvases and fonts
Alex Szpakowski <slime73@gmail.com>
parents:
1393
diff
changeset
|
769 void Graphics::setDefaultMipmapFilter(Image::FilterMode filter, float sharpness) |
|
1393
251c40067246
Added anisotropic filtering functionality for images, consolidated mipmap methods into Image:setMipmapFilter(filtermode, sharpness, anisotropy), added love.graphics.setDefaultMipmapFilter(filtermode, sharpness, anisotropy)
Alex Szpakowski <slime73@gmail.com>
parents:
1389
diff
changeset
|
770 { |
|
251c40067246
Added anisotropic filtering functionality for images, consolidated mipmap methods into Image:setMipmapFilter(filtermode, sharpness, anisotropy), added love.graphics.setDefaultMipmapFilter(filtermode, sharpness, anisotropy)
Alex Szpakowski <slime73@gmail.com>
parents:
1389
diff
changeset
|
771 Image::setDefaultMipmapFilter(filter); |
|
1394
8c7ef7189365
Moved anisotropic filtering to Image:setFilter(min, mag, anisotropy), added anisotropic filtering support to canvases and fonts
Alex Szpakowski <slime73@gmail.com>
parents:
1393
diff
changeset
|
772 Image::setDefaultMipmapSharpness(sharpness); |
|
1393
251c40067246
Added anisotropic filtering functionality for images, consolidated mipmap methods into Image:setMipmapFilter(filtermode, sharpness, anisotropy), added love.graphics.setDefaultMipmapFilter(filtermode, sharpness, anisotropy)
Alex Szpakowski <slime73@gmail.com>
parents:
1389
diff
changeset
|
773 } |
|
251c40067246
Added anisotropic filtering functionality for images, consolidated mipmap methods into Image:setMipmapFilter(filtermode, sharpness, anisotropy), added love.graphics.setDefaultMipmapFilter(filtermode, sharpness, anisotropy)
Alex Szpakowski <slime73@gmail.com>
parents:
1389
diff
changeset
|
774 |
|
1394
8c7ef7189365
Moved anisotropic filtering to Image:setFilter(min, mag, anisotropy), added anisotropic filtering support to canvases and fonts
Alex Szpakowski <slime73@gmail.com>
parents:
1393
diff
changeset
|
775 void Graphics::getDefaultMipmapFilter(Image::FilterMode *filter, float *sharpness) const |
|
1393
251c40067246
Added anisotropic filtering functionality for images, consolidated mipmap methods into Image:setMipmapFilter(filtermode, sharpness, anisotropy), added love.graphics.setDefaultMipmapFilter(filtermode, sharpness, anisotropy)
Alex Szpakowski <slime73@gmail.com>
parents:
1389
diff
changeset
|
776 { |
|
251c40067246
Added anisotropic filtering functionality for images, consolidated mipmap methods into Image:setMipmapFilter(filtermode, sharpness, anisotropy), added love.graphics.setDefaultMipmapFilter(filtermode, sharpness, anisotropy)
Alex Szpakowski <slime73@gmail.com>
parents:
1389
diff
changeset
|
777 *filter = Image::getDefaultMipmapFilter(); |
|
1394
8c7ef7189365
Moved anisotropic filtering to Image:setFilter(min, mag, anisotropy), added anisotropic filtering support to canvases and fonts
Alex Szpakowski <slime73@gmail.com>
parents:
1393
diff
changeset
|
778 *sharpness = Image::getDefaultMipmapSharpness(); |
|
1393
251c40067246
Added anisotropic filtering functionality for images, consolidated mipmap methods into Image:setMipmapFilter(filtermode, sharpness, anisotropy), added love.graphics.setDefaultMipmapFilter(filtermode, sharpness, anisotropy)
Alex Szpakowski <slime73@gmail.com>
parents:
1389
diff
changeset
|
779 } |
|
251c40067246
Added anisotropic filtering functionality for images, consolidated mipmap methods into Image:setMipmapFilter(filtermode, sharpness, anisotropy), added love.graphics.setDefaultMipmapFilter(filtermode, sharpness, anisotropy)
Alex Szpakowski <slime73@gmail.com>
parents:
1389
diff
changeset
|
780 |
| 1096 | 781 void Graphics::setLineWidth(float width) |
| 782 { | |
| 783 lineWidth = width; | |
| 784 } | |
| 785 | |
| 786 void Graphics::setLineStyle(Graphics::LineStyle style) | |
| 787 { | |
| 788 lineStyle = style; | |
| 789 } | |
| 790 | |
| 791 void Graphics::setLine(float width, Graphics::LineStyle style) | |
| 792 { | |
| 793 setLineWidth(width); | |
| 794 | |
| 795 if (style == 0) | |
| 796 return; | |
| 797 setLineStyle(style); | |
| 798 } | |
| 799 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1307
diff
changeset
|
800 float Graphics::getLineWidth() const |
| 1096 | 801 { |
| 802 return lineWidth; | |
| 803 } | |
| 804 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1307
diff
changeset
|
805 Graphics::LineStyle Graphics::getLineStyle() const |
| 1096 | 806 { |
| 807 return lineStyle; | |
| 808 } | |
| 809 | |
| 810 void Graphics::setPointSize(float size) | |
| 811 { | |
| 812 glPointSize((GLfloat)size); | |
| 813 } | |
| 814 | |
| 815 void Graphics::setPointStyle(Graphics::PointStyle style) | |
| 816 { | |
| 817 if (style == POINT_SMOOTH) | |
| 818 glEnable(GL_POINT_SMOOTH); | |
| 819 else // love::POINT_ROUGH | |
| 820 glDisable(GL_POINT_SMOOTH); | |
| 821 } | |
| 822 | |
| 823 void Graphics::setPoint(float size, Graphics::PointStyle style) | |
| 824 { | |
| 825 if (style == POINT_SMOOTH) | |
| 826 glEnable(GL_POINT_SMOOTH); | |
| 827 else // POINT_ROUGH | |
| 828 glDisable(GL_POINT_SMOOTH); | |
| 829 | |
| 830 glPointSize((GLfloat)size); | |
| 831 } | |
| 832 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1307
diff
changeset
|
833 float Graphics::getPointSize() const |
| 1096 | 834 { |
| 835 GLfloat size; | |
| 836 glGetFloatv(GL_POINT_SIZE, &size); | |
| 837 return (float)size; | |
| 838 } | |
| 839 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1307
diff
changeset
|
840 Graphics::PointStyle Graphics::getPointStyle() const |
| 1096 | 841 { |
| 842 if (glIsEnabled(GL_POINT_SMOOTH) == GL_TRUE) | |
| 843 return POINT_SMOOTH; | |
| 844 else | |
| 845 return POINT_ROUGH; | |
| 846 } | |
| 847 | |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1307
diff
changeset
|
848 int Graphics::getMaxPointSize() const |
| 1096 | 849 { |
| 850 GLint max; | |
| 851 glGetIntegerv(GL_POINT_SIZE_MAX, &max); | |
| 852 return (int)max; | |
| 853 } | |
| 854 | |
| 855 void Graphics::print(const char *str, float x, float y , float angle, float sx, float sy, float ox, float oy, float kx, float ky) | |
| 856 { | |
| 857 if (currentFont != 0) | |
| 858 { | |
| 859 std::string text(str); | |
|
1105
1bd1670a04e1
Close issue #408: printf-justify alignment.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
860 currentFont->print(text, x, y, 0.0, angle, sx, sy, ox, oy, kx, ky); |
| 1096 | 861 } |
| 862 } | |
| 863 | |
|
1389
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
864 void Graphics::printf(const char *str, float x, float y, float wrap, AlignMode align, float angle, float sx, float sy, float ox, float oy, float kx, float ky) |
| 1096 | 865 { |
| 866 if (currentFont == 0) | |
| 867 return; | |
| 868 | |
| 869 using namespace std; | |
| 870 string text(str); | |
| 871 vector<string> lines_to_draw = currentFont->getWrap(text, wrap); | |
| 872 | |
|
1389
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
873 glPushMatrix(); |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
874 |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
875 static Matrix t; |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
876 t.setTransformation(ceil(x), ceil(y), angle, sx, sy, ox, oy, kx, ky); |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
877 glMultMatrixf((const GLfloat *)t.getElements()); |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
878 |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
879 x = y = 0.0f; |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
880 |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
881 try |
| 1096 | 882 { |
|
1389
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
883 // now for the actual printing |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
884 vector<string>::const_iterator line_iter, line_end = lines_to_draw.end(); |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
885 float letter_spacing = 0.0f; |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
886 for (line_iter = lines_to_draw.begin(); line_iter != line_end; ++line_iter) |
| 1096 | 887 { |
|
1389
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
888 float width = static_cast<float>(currentFont->getWidth(*line_iter)); |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
889 switch (align) |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
890 { |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
891 case ALIGN_RIGHT: |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
892 currentFont->print(*line_iter, ceil(x + (wrap - width)), ceil(y), 0.0f); |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
893 break; |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
894 case ALIGN_CENTER: |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
895 currentFont->print(*line_iter, ceil(x + (wrap - width) / 2), ceil(y), 0.0f); |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
896 break; |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
897 case ALIGN_JUSTIFY: |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
898 if (line_iter->length() > 1 && (line_iter+1) != line_end) |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
899 letter_spacing = (wrap - width) / float(line_iter->length() - 1); |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
900 else |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
901 letter_spacing = 0.0f; |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
902 currentFont->print(*line_iter, ceil(x), ceil(y), letter_spacing); |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
903 break; |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
904 case ALIGN_LEFT: |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
905 default: |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
906 currentFont->print(*line_iter, ceil(x), ceil(y), 0.0f); |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
907 break; |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
908 } |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
909 y += currentFont->getHeight() * currentFont->getLineHeight(); |
| 1096 | 910 } |
| 911 } | |
|
1389
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
912 catch (love::Exception &) |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
913 { |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
914 glPopMatrix(); |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
915 throw; |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
916 } |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
917 |
|
ac121b0d7258
Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky
Alex Szpakowski <slime73@gmail.com>
parents:
1373
diff
changeset
|
918 glPopMatrix(); |
| 1096 | 919 } |
| 920 | |
| 921 /** | |
| 922 * Primitives | |
| 923 **/ | |
| 924 | |
| 925 void Graphics::point(float x, float y) | |
| 926 { | |
|
1213
56db65b1f103
Bind texture id 0 (no texture) instead of disabling/re-enabling texturing entirely, when drawing graphics primitives. This both allows shaders to potentially use their own textures when drawing textureless primitives, and reduces overhead caused by constant GL state changes when drawing many graphics primitives.
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1207
diff
changeset
|
927 bindTexture(0); |
| 1096 | 928 glBegin(GL_POINTS); |
| 929 glVertex2f(x, y); | |
| 930 glEnd(); | |
| 931 } | |
| 932 | |
| 933 // Calculate line boundary points u1 and u2. Sketch: | |
| 934 // u1 | |
| 935 // -------------+---...___ | |
| 936 // | ```'''-- --- | |
| 937 // p- - - - - - q- - . _ _ | w/2 | |
| 938 // | ` ' ' r + | |
| 939 // -------------+---...___ | w/2 | |
| 940 // u2 ```'''-- --- | |
| 941 // | |
| 942 // u1 and u2 depend on four things: | |
| 943 // - the half line width w/2 | |
| 944 // - the previous line vertex p | |
| 945 // - the current line vertex q | |
| 946 // - the next line vertex r | |
| 947 // | |
| 948 // u1/u2 are the intersection points of the parallel lines to p-q and q-r, | |
| 949 // i.e. the point where | |
| 950 // | |
| 951 // (p + w/2 * n1) + mu * (q - p) = (q + w/2 * n2) + lambda * (r - q) (u1) | |
| 952 // (p - w/2 * n1) + mu * (q - p) = (q - w/2 * n2) + lambda * (r - q) (u2) | |
| 953 // | |
| 954 // with n1,n2 being the normals on the segments p-q and q-r: | |
| 955 // | |
| 956 // n1 = perp(q - p) / |q - p| | |
| 957 // n2 = perp(r - q) / |r - q| | |
| 958 // | |
| 959 // The intersection points can be calculated using cramers rule. | |
| 960 static void pushIntersectionPoints(Vector *vertices, Vector *overdraw, | |
| 961 int pos, int count, float hw, float overdraw_factor, | |
| 962 const Vector &p, const Vector &q, const Vector &r) | |
| 963 { | |
| 964 // calculate line directions | |
| 965 Vector s = (q - p); | |
| 966 Vector t = (r - q); | |
| 967 | |
| 968 // calculate vertex displacement vectors | |
| 969 Vector n1 = s.getNormal(); | |
| 970 Vector n2 = t.getNormal(); | |
| 971 n1.normalize(); | |
| 972 n2.normalize(); | |
| 973 float det_norm = n1 ^ n2; // will be close to zero if the angle between the normals is sharp | |
| 974 n1 *= hw; | |
| 975 n2 *= hw; | |
| 976 | |
| 977 // lines parallel -> assume intersection at displacement points | |
| 978 if (fabs(det_norm) <= .03) | |
| 979 { | |
| 980 vertices[pos] = q - n2; | |
| 981 vertices[pos+1] = q + n2; | |
| 982 } | |
| 983 // real intersection -> calculate boundary intersection points with cramers rule | |
| 984 else | |
| 985 { | |
| 986 float det = s ^ t; | |
| 987 Vector d = n1 - n2; | |
| 988 Vector b = s - d; // s = q - p | |
| 989 Vector c = s + d; | |
| 990 float lambda = (b ^ t) / det; | |
| 991 float mu = (c ^ t) / det; | |
| 992 | |
| 993 // ordering for GL_TRIANGLE_STRIP | |
| 994 vertices[pos] = p + s*mu - n1; // u1 | |
| 995 vertices[pos+1] = p + s*lambda + n1; // u2 | |
| 996 } | |
| 997 | |
| 998 if (overdraw) | |
| 999 { | |
| 1000 // displacement of the overdraw vertices | |
| 1001 Vector x = (vertices[pos] - q) * overdraw_factor; | |
| 1002 | |
| 1003 overdraw[pos] = vertices[pos]; | |
| 1004 overdraw[pos+1] = vertices[pos] + x; | |
| 1005 | |
| 1006 overdraw[2*count-pos-2] = vertices[pos+1]; | |
| 1007 overdraw[2*count-pos-1] = vertices[pos+1] - x; | |
| 1008 } | |
| 1009 } | |
| 1010 | |
| 1011 // precondition: | |
| 1012 // glEnableClientState(GL_VERTEX_ARRAY); | |
| 1013 static void draw_overdraw(Vector *overdraw, size_t count, float pixel_size, bool looping) | |
| 1014 { | |
| 1015 // if not looping, the outer overdraw vertices need to be displaced | |
| 1016 // to cover the line endings, i.e.: | |
| 1017 // +- - - - //- - + +- - - - - //- - - + | |
| 1018 // +-------//-----+ : +-------//-----+ : | |
| 1019 // | core // line | --> : | core // line | : | |
| 1020 // +-----//-------+ : +-----//-------+ : | |
| 1021 // +- - //- - - - + +- - - //- - - - - + | |
| 1022 if (!looping) | |
| 1023 { | |
| 1024 Vector s = overdraw[1] - overdraw[3]; | |
| 1025 s.normalize(); | |
| 1026 s *= pixel_size; | |
| 1027 overdraw[1] += s; | |
| 1028 overdraw[2*count-1] += s; | |
| 1029 | |
| 1030 Vector t = overdraw[count-1] - overdraw[count-3]; | |
| 1031 t.normalize(); | |
| 1032 t *= pixel_size; | |
| 1033 overdraw[count-1] += t; | |
| 1034 overdraw[count+1] += t; | |
| 1035 | |
| 1036 // we need to draw two more triangles to close the | |
| 1037 // overdraw at the line start. | |
| 1038 overdraw[2*count] = overdraw[0]; | |
| 1039 overdraw[2*count+1] = overdraw[1]; | |
| 1040 } | |
| 1041 | |
| 1042 // prepare colors: | |
| 1043 // even indices in overdraw* point to inner vertices => alpha = current-alpha, | |
| 1044 // odd indices point to outer vertices => alpha = 0. | |
|
1442
d732e302eae6
Internally keep track of the value of the current color (issue #564)
Alex Szpakowski <slime73@gmail.com>
parents:
1439
diff
changeset
|
1045 Color c = opengl::getCurrentColor(); |
| 1096 | 1046 |
| 1047 Color *colors = new Color[2*count+2]; | |
| 1048 for (size_t i = 0; i < 2*count+2; ++i) | |
| 1049 { | |
|
1442
d732e302eae6
Internally keep track of the value of the current color (issue #564)
Alex Szpakowski <slime73@gmail.com>
parents:
1439
diff
changeset
|
1050 colors[i] = c; |
|
d732e302eae6
Internally keep track of the value of the current color (issue #564)
Alex Szpakowski <slime73@gmail.com>
parents:
1439
diff
changeset
|
1051 // avoids branching. equiv to if (i%2 == 1) colors[i].a = 0; |
|
d732e302eae6
Internally keep track of the value of the current color (issue #564)
Alex Szpakowski <slime73@gmail.com>
parents:
1439
diff
changeset
|
1052 colors[i].a *= GLubyte(i % 2 == 0); |
| 1096 | 1053 } |
| 1054 | |
| 1055 // draw faded out line halos | |
| 1056 glEnableClientState(GL_COLOR_ARRAY); | |
| 1057 glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors); | |
| 1058 glVertexPointer(2, GL_FLOAT, 0, (const GLvoid *)overdraw); | |
| 1059 glDrawArrays(GL_TRIANGLE_STRIP, 0, 2*count + 2 * int(!looping)); | |
| 1060 glDisableClientState(GL_COLOR_ARRAY); | |
| 1061 // "if GL_COLOR_ARRAY is enabled, the value of the current color is | |
| 1062 // undefined after glDrawArrays executes" | |
|
1442
d732e302eae6
Internally keep track of the value of the current color (issue #564)
Alex Szpakowski <slime73@gmail.com>
parents:
1439
diff
changeset
|
1063 |
|
d732e302eae6
Internally keep track of the value of the current color (issue #564)
Alex Szpakowski <slime73@gmail.com>
parents:
1439
diff
changeset
|
1064 opengl::setCurrentColor(c); |
| 1096 | 1065 |
| 1066 delete[] colors; | |
| 1067 } | |
| 1068 | |
| 1069 void Graphics::polyline(const float *coords, size_t count) | |
| 1070 { | |
| 1071 Vector *vertices = new Vector[count]; // two vertices for every line end-point | |
| 1072 Vector *overdraw = NULL; | |
| 1073 | |
| 1074 Vector p,q,r; | |
| 1075 bool looping = (coords[0] == coords[count-2]) && (coords[1] == coords[count-1]); | |
| 1076 | |
| 1077 float halfwidth = lineWidth/2.f; | |
| 1078 float pixel_size = 1.f; | |
| 1079 float overdraw_factor = .0f; | |
| 1080 | |
| 1081 if (lineStyle == LINE_SMOOTH) | |
| 1082 { | |
| 1083 overdraw = new Vector[2*count+2]; | |
| 1084 // TODO: is there a better way to get the pixel size at the current scale? | |
| 1085 GLfloat m[16]; | |
| 1086 glGetFloatv(GL_MODELVIEW_MATRIX, m); | |
| 1087 float det = m[0]*m[5]*m[10] + m[4]*m[9]*m[2] + m[8]*m[1]*m[6]; | |
| 1088 det -= m[2]*m[5]*m[8] + m[6]*m[9]*m[0] + m[10]*m[1]*m[4]; | |
| 1089 pixel_size = 1.f / sqrt(det); | |
| 1090 | |
| 1091 overdraw_factor = pixel_size / halfwidth; | |
| 1092 halfwidth = std::max(.0f, halfwidth - .25f*pixel_size); | |
| 1093 } | |
| 1094 | |
| 1095 // get line vertex boundaries | |
| 1096 // if not looping, extend the line at the beginning, else use last point as `p' | |
| 1097 r = Vector(coords[0], coords[1]); | |
| 1098 if (!looping) | |
| 1099 q = r * 2 - Vector(coords[2], coords[3]); | |
| 1100 else | |
| 1101 q = Vector(coords[count-4], coords[count-3]); | |
| 1102 | |
| 1103 for (size_t i = 0; i+3 < count; i += 2) | |
| 1104 { | |
| 1105 p = q; | |
| 1106 q = r; | |
| 1107 r = Vector(coords[i+2], coords[i+3]); | |
| 1108 pushIntersectionPoints(vertices, overdraw, i, count, halfwidth, overdraw_factor, p,q,r); | |
| 1109 } | |
| 1110 | |
| 1111 // if not looping, extend the line at the end, else use first point as `r' | |
| 1112 p = q; | |
| 1113 q = r; | |
| 1114 if (!looping) | |
| 1115 r += q - p; | |
| 1116 else | |
| 1117 r = Vector(coords[2], coords[3]); | |
| 1118 pushIntersectionPoints(vertices, overdraw, count-2, count, halfwidth, overdraw_factor, p,q,r); | |
| 1119 // end get line vertex boundaries | |
| 1120 | |
| 1121 // draw the core line | |
|
1213
56db65b1f103
Bind texture id 0 (no texture) instead of disabling/re-enabling texturing entirely, when drawing graphics primitives. This both allows shaders to potentially use their own textures when drawing textureless primitives, and reduces overhead caused by constant GL state changes when drawing many graphics primitives.
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1207
diff
changeset
|
1122 bindTexture(0); |
| 1096 | 1123 glEnableClientState(GL_VERTEX_ARRAY); |
| 1124 glVertexPointer(2, GL_FLOAT, 0, (const GLvoid *)vertices); | |
| 1125 glDrawArrays(GL_TRIANGLE_STRIP, 0, count); | |
| 1126 | |
| 1127 // draw the line halo (antialiasing) | |
| 1128 if (lineStyle == LINE_SMOOTH) | |
| 1129 draw_overdraw(overdraw, count, pixel_size, looping); | |
| 1130 | |
| 1131 glDisableClientState(GL_VERTEX_ARRAY); | |
| 1132 | |
| 1133 // cleanup | |
| 1134 delete[] vertices; | |
| 1135 if (lineStyle == LINE_SMOOTH) | |
| 1136 delete[] overdraw; | |
| 1137 } | |
| 1138 | |
| 1139 void Graphics::rectangle(DrawMode mode, float x, float y, float w, float h) | |
| 1140 { | |
|
1373
4df5cb3bd028
Really fixed love.graphics.rectangle
Alex Szpakowski <slime73@gmail.com>
parents:
1372
diff
changeset
|
1141 float coords[] = {x,y, x,y+h, x+w,y+h, x+w,y, x,y}; |
| 1096 | 1142 polygon(mode, coords, 5 * 2); |
| 1143 } | |
| 1144 | |
| 1145 void Graphics::circle(DrawMode mode, float x, float y, float radius, int points) | |
| 1146 { | |
| 1147 float two_pi = static_cast<float>(LOVE_M_PI * 2); | |
| 1148 if (points <= 0) points = 1; | |
| 1149 float angle_shift = (two_pi / points); | |
| 1150 float phi = .0f; | |
| 1151 | |
| 1152 float *coords = new float[2 * (points + 1)]; | |
| 1153 for (int i = 0; i < points; ++i, phi += angle_shift) | |
| 1154 { | |
| 1155 coords[2*i] = x + radius * cos(phi); | |
| 1156 coords[2*i+1] = y + radius * sin(phi); | |
| 1157 } | |
| 1158 | |
| 1159 coords[2*points] = coords[0]; | |
| 1160 coords[2*points+1] = coords[1]; | |
| 1161 | |
| 1162 polygon(mode, coords, (points + 1) * 2); | |
| 1163 | |
| 1164 delete[] coords; | |
| 1165 } | |
| 1166 | |
| 1167 void Graphics::arc(DrawMode mode, float x, float y, float radius, float angle1, float angle2, int points) | |
| 1168 { | |
| 1169 // Nothing to display with no points or equal angles. (Or is there with line mode?) | |
| 1170 if (points <= 0 || angle1 == angle2) | |
| 1171 return; | |
| 1172 | |
| 1173 // Oh, you want to draw a circle? | |
| 1174 if (fabs(angle1 - angle2) >= 2.0f * (float) LOVE_M_PI) | |
| 1175 { | |
| 1176 circle(mode, x, y, radius, points); | |
| 1177 return; | |
| 1178 } | |
| 1179 | |
| 1180 float angle_shift = (angle2 - angle1) / points; | |
| 1181 // Bail on precision issues. | |
| 1182 if (angle_shift == 0.0) | |
| 1183 return; | |
| 1184 | |
| 1185 float phi = angle1; | |
| 1186 int num_coords = (points + 3) * 2; | |
| 1187 float *coords = new float[num_coords]; | |
| 1188 coords[0] = coords[num_coords - 2] = x; | |
| 1189 coords[1] = coords[num_coords - 1] = y; | |
| 1190 | |
| 1191 for (int i = 0; i <= points; ++i, phi += angle_shift) | |
| 1192 { | |
| 1193 coords[2 * (i+1)] = x + radius * cos(phi); | |
| 1194 coords[2 * (i+1) + 1] = y + radius * sin(phi); | |
| 1195 } | |
| 1196 | |
| 1197 // GL_POLYGON can only fill-draw convex polygons, so we need to do stuff manually here | |
| 1198 if (mode == DRAW_LINE) | |
| 1199 { | |
| 1200 polyline(coords, num_coords); // Artifacts at sharp angles if set to looping. | |
| 1201 } | |
| 1202 else | |
| 1203 { | |
|
1213
56db65b1f103
Bind texture id 0 (no texture) instead of disabling/re-enabling texturing entirely, when drawing graphics primitives. This both allows shaders to potentially use their own textures when drawing textureless primitives, and reduces overhead caused by constant GL state changes when drawing many graphics primitives.
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1207
diff
changeset
|
1204 bindTexture(0); |
| 1096 | 1205 glEnableClientState(GL_VERTEX_ARRAY); |
| 1206 glVertexPointer(2, GL_FLOAT, 0, (const GLvoid *) coords); | |
| 1207 glDrawArrays(GL_TRIANGLE_FAN, 0, points + 2); | |
| 1208 glDisableClientState(GL_VERTEX_ARRAY); | |
| 1209 } | |
| 1210 | |
| 1211 delete[] coords; | |
| 1212 } | |
| 1213 | |
| 1214 /// @param mode the draw mode | |
| 1215 /// @param coords the coordinate array | |
| 1216 /// @param count the number of coordinates/size of the array | |
| 1217 void Graphics::polygon(DrawMode mode, const float *coords, size_t count) | |
| 1218 { | |
| 1219 // coords is an array of a closed loop of vertices, i.e. | |
| 1220 // coords[count-2] = coords[0], coords[count-1] = coords[1] | |
| 1221 if (mode == DRAW_LINE) | |
| 1222 { | |
| 1223 polyline(coords, count); | |
| 1224 } | |
| 1225 else | |
| 1226 { | |
|
1213
56db65b1f103
Bind texture id 0 (no texture) instead of disabling/re-enabling texturing entirely, when drawing graphics primitives. This both allows shaders to potentially use their own textures when drawing textureless primitives, and reduces overhead caused by constant GL state changes when drawing many graphics primitives.
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1207
diff
changeset
|
1227 bindTexture(0); |
| 1096 | 1228 glEnableClientState(GL_VERTEX_ARRAY); |
| 1229 glVertexPointer(2, GL_FLOAT, 0, (const GLvoid *)coords); | |
| 1230 glDrawArrays(GL_POLYGON, 0, count/2-1); // opengl will close the polygon for us | |
| 1231 glDisableClientState(GL_VERTEX_ARRAY); | |
| 1232 } | |
| 1233 } | |
| 1234 | |
|
1364
79162aad3481
love.graphics.newScreenshot replaces alpha with full opacity by default (issue #374, thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1340
diff
changeset
|
1235 love::image::ImageData *Graphics::newScreenshot(love::image::Image *image, bool copyAlpha) |
| 1096 | 1236 { |
|
1365
ed450b9c8bb4
love.graphics.newScreenshot now uses the size of the current canvas (if applicable), instead of adding transparency or clipping to match the screen size
Alex Szpakowski <slime73@gmail.com>
parents:
1364
diff
changeset
|
1237 int w = getRenderWidth(); |
|
ed450b9c8bb4
love.graphics.newScreenshot now uses the size of the current canvas (if applicable), instead of adding transparency or clipping to match the screen size
Alex Szpakowski <slime73@gmail.com>
parents:
1364
diff
changeset
|
1238 int h = getRenderHeight(); |
| 1096 | 1239 |
| 1240 int row = 4*w; | |
| 1241 | |
| 1242 int size = row*h; | |
| 1243 | |
| 1244 GLubyte *pixels = new GLubyte[size]; | |
| 1245 GLubyte *screenshot = new GLubyte[size]; | |
| 1246 | |
| 1247 glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels); | |
| 1248 | |
|
1364
79162aad3481
love.graphics.newScreenshot replaces alpha with full opacity by default (issue #374, thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1340
diff
changeset
|
1249 if (!copyAlpha) |
|
79162aad3481
love.graphics.newScreenshot replaces alpha with full opacity by default (issue #374, thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1340
diff
changeset
|
1250 { |
|
79162aad3481
love.graphics.newScreenshot replaces alpha with full opacity by default (issue #374, thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1340
diff
changeset
|
1251 // Replace alpha values with full opacity. |
|
79162aad3481
love.graphics.newScreenshot replaces alpha with full opacity by default (issue #374, thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1340
diff
changeset
|
1252 for (int i = 3; i < size; i += 4) |
|
79162aad3481
love.graphics.newScreenshot replaces alpha with full opacity by default (issue #374, thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1340
diff
changeset
|
1253 pixels[i] = 255; |
|
79162aad3481
love.graphics.newScreenshot replaces alpha with full opacity by default (issue #374, thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1340
diff
changeset
|
1254 } |
|
79162aad3481
love.graphics.newScreenshot replaces alpha with full opacity by default (issue #374, thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1340
diff
changeset
|
1255 |
| 1096 | 1256 // OpenGL sucks and reads pixels from the lower-left. Let's fix that. |
| 1257 | |
| 1258 GLubyte *src = pixels - row, *dst = screenshot + size; | |
| 1259 | |
| 1260 for (int i = 0; i < h; ++i) | |
| 1261 memcpy(dst-=row, src+=row, row); | |
| 1262 | |
|
1364
79162aad3481
love.graphics.newScreenshot replaces alpha with full opacity by default (issue #374, thanks Boolsheet)
Alex Szpakowski <slime73@gmail.com>
parents:
1340
diff
changeset
|
1263 love::image::ImageData *img = image->newImageData(w, h, (void *) screenshot); |
| 1096 | 1264 |
| 1265 delete [] pixels; | |
| 1266 delete [] screenshot; | |
| 1267 | |
| 1268 return img; | |
| 1269 } | |
| 1270 | |
| 1271 void Graphics::push() | |
| 1272 { | |
| 1273 if (userMatrices == matrixLimit) | |
|
1157
29c84a47f61a
Close issue #519: Maximum stack depth reached error message.
vrld <vrld@vrld.org>
parents:
1139
diff
changeset
|
1274 throw Exception("Maximum stack depth reached. (More pushes than pops?)"); |
| 1096 | 1275 glPushMatrix(); |
| 1276 ++userMatrices; | |
| 1277 } | |
| 1278 | |
| 1279 void Graphics::pop() | |
| 1280 { | |
| 1281 if (userMatrices < 1) | |
| 1282 throw Exception("Minimum stack depth reached. (More pops than pushes?)"); | |
| 1283 glPopMatrix(); | |
| 1284 --userMatrices; | |
| 1285 } | |
| 1286 | |
| 1287 void Graphics::rotate(float r) | |
| 1288 { | |
| 1289 glRotatef(LOVE_TODEG(r), 0, 0, 1); | |
| 1290 } | |
| 1291 | |
| 1292 void Graphics::scale(float x, float y) | |
| 1293 { | |
| 1294 glScalef(x, y, 1); | |
| 1295 } | |
| 1296 | |
| 1297 void Graphics::translate(float x, float y) | |
| 1298 { | |
| 1299 glTranslatef(x, y, 0); | |
| 1300 } | |
| 1301 | |
| 1302 void Graphics::shear(float kx, float ky) | |
| 1303 { | |
| 1304 Matrix t; | |
| 1305 t.setShear(kx, ky); | |
| 1306 glMultMatrixf((const GLfloat *)t.getElements()); | |
| 1307 } | |
| 1308 | |
|
1321
30d0e4cb3d2b
Added love.graphics.origin(): resets the coordinate system (replaces the current transformation matrix with the identity)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
1309 void Graphics::origin() |
|
30d0e4cb3d2b
Added love.graphics.origin(): resets the coordinate system (replaces the current transformation matrix with the identity)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
1310 { |
|
30d0e4cb3d2b
Added love.graphics.origin(): resets the coordinate system (replaces the current transformation matrix with the identity)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
1311 glLoadIdentity(); |
|
30d0e4cb3d2b
Added love.graphics.origin(): resets the coordinate system (replaces the current transformation matrix with the identity)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
1312 } |
|
30d0e4cb3d2b
Added love.graphics.origin(): resets the coordinate system (replaces the current transformation matrix with the identity)
Alex Szpakowski <slime73@gmail.com>
parents:
1311
diff
changeset
|
1313 |
|
1310
2061cc4dc762
Constified many Graphics and Window methods
Alex Szpakowski <slime73@gmail.com>
parents:
1307
diff
changeset
|
1314 bool Graphics::hasFocus() const |
| 1096 | 1315 { |
| 1316 return currentWindow->hasFocus(); | |
| 1317 } | |
| 1318 | |
| 1319 } // opengl | |
| 1320 } // graphics | |
| 1321 } // love |
