diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index b6abf65a3..c64225ee1 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -202,6 +202,9 @@ bool Graphics::setMode(int width, int height, WindowFlags *flags) // Restore the display state. restoreState(tempState); + pixel_size_stack.clear(); + pixel_size_stack.reserve(5); + pixel_size_stack.push_back(1); // Get the maximum number of matrices // subtract a few to give the engine some room. @@ -241,6 +244,9 @@ void Graphics::reset() Canvas::bindDefaultCanvas(); Shader::detach(); restoreState(s); + pixel_size_stack.clear(); + pixel_size_stack.reserve(5); + pixel_size_stack.push_back(1); } void Graphics::clear() @@ -1090,19 +1096,12 @@ void Graphics::polyline(const float *coords, size_t count) bool looping = (coords[0] == coords[count-2]) && (coords[1] == coords[count-1]); float halfwidth = lineWidth/2.f; - float pixel_size = 1.f; + float pixel_size = pixel_size_stack.back(); float overdraw_factor = .0f; if (lineStyle == LINE_SMOOTH) { overdraw = new Vector[2*count+2]; - // TODO: is there a better way to get the pixel size at the current scale? - GLfloat m[16]; - glGetFloatv(GL_MODELVIEW_MATRIX, m); - float det = m[0]*m[5]*m[10] + m[4]*m[9]*m[2] + m[8]*m[1]*m[6]; - det -= m[2]*m[5]*m[8] + m[6]*m[9]*m[0] + m[10]*m[1]*m[4]; - pixel_size = 1.f / sqrtf(det); - overdraw_factor = pixel_size / halfwidth; halfwidth = std::max(.0f, halfwidth - .25f*pixel_size); } @@ -1338,6 +1337,7 @@ void Graphics::push() throw Exception("Maximum stack depth reached. (More pushes than pops?)"); glPushMatrix(); ++userMatrices; + pixel_size_stack.push_back(pixel_size_stack.back()); } void Graphics::pop() @@ -1346,6 +1346,7 @@ void Graphics::pop() throw Exception("Minimum stack depth reached. (More pops than pushes?)"); glPopMatrix(); --userMatrices; + pixel_size_stack.pop_back(); } void Graphics::rotate(float r) @@ -1356,6 +1357,7 @@ void Graphics::rotate(float r) void Graphics::scale(float x, float y) { glScalef(x, y, 1); + pixel_size_stack.back() *= 2. / double(x + y); } void Graphics::translate(float x, float y) @@ -1373,6 +1375,8 @@ void Graphics::shear(float kx, float ky) void Graphics::origin() { glLoadIdentity(); + pixel_size_stack.clear(); + pixel_size_stack.push_back(1); } bool Graphics::hasFocus() const diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index 89e2b5a7c..d91071d03 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -23,7 +23,8 @@ // STD #include -#include +#include +#include // OpenGL #include "OpenGL.h" @@ -546,6 +547,7 @@ private: Font *currentFont; love::window::Window *currentWindow; + std::vector pixel_size_stack; // stores current size of a pixel (needed for line drawing) LineStyle lineStyle; float lineWidth; GLint matrixLimit;