Browse Source

Fixed smooth lines with love.graphics.origin() after love.graphics.scale

Alex Szpakowski 12 years ago
parent
commit
aa59761177

+ 23 - 21
src/common/Module.cpp

@@ -34,32 +34,34 @@ namespace
 
 namespace love
 {
-	void Module::registerInstance(Module *instance)
-	{
-		if (instance == NULL)
-			throw Exception("Module instance is NULL");
 
-		std::string name(instance->getName());
+void Module::registerInstance(Module *instance)
+{
+	if (instance == NULL)
+		throw Exception("Module instance is NULL");
 
-		std::map<std::string, Module*>::iterator it = registry.find(name);
+	std::string name(instance->getName());
 
-		if (registry.end() != it)
-		{
-			if (it->second == instance)
-				return;
-			throw Exception("Module %s already registered!", instance->getName());
-		}
+	std::map<std::string, Module*>::iterator it = registry.find(name);
 
-		registry.insert(make_pair(name, instance));
+	if (registry.end() != it)
+	{
+		if (it->second == instance)
+			return;
+		throw Exception("Module %s already registered!", instance->getName());
 	}
 
-	Module *Module::getInstance(const char *name)
-	{
-		std::map<std::string, Module*>::iterator it = registry.find(std::string(name));
+	registry.insert(make_pair(name, instance));
+}
 
-		if (registry.end() == it)
-			return NULL;
+Module *Module::getInstance(const char *name)
+{
+	std::map<std::string, Module*>::iterator it = registry.find(std::string(name));
 
-		return it->second;
-	}
-} // namespace love
+	if (registry.end() == it)
+		return NULL;
+
+	return it->second;
+}
+
+} // love

+ 2 - 1
src/common/runtime.cpp

@@ -78,7 +78,7 @@ static int w__eq(lua_State *L)
 	return 1;
 }
 
-Reference *luax_refif (lua_State *L, int type)
+Reference *luax_refif(lua_State *L, int type)
 {
 	Reference *r = 0;
 
@@ -538,6 +538,7 @@ StringMap<Type, TYPE_MAX_ENUM>::Entry typeEntries[] =
 
 	// The modules themselves. Only add abstracted modules here.
 	{"filesystem", MODULE_FILESYSTEM_ID},
+	{"graphics", MODULE_GRAPHICS_ID},
 	{"image", MODULE_IMAGE_ID},
 	{"sound", MODULE_SOUND_ID},
 };

+ 7 - 7
src/modules/graphics/opengl/Graphics.cpp

@@ -199,12 +199,12 @@ bool Graphics::setMode(int width, int height)
 
 void Graphics::unSetMode()
 {
-	// Window creation may destroy the OpenGL context, so we must save the state.
+	// Window re-creation may destroy the GL context, so we must save the state.
 	if (isCreated())
 		savedState = saveState();
 
-	// Unload all volatile objects. These must be reloaded after
-	// the display mode change.
+	// Unload all volatile objects. These must be reloaded after the display
+	// mode change.
 	Volatile::unloadAll();
 
 	gl.deInitContext();
@@ -266,7 +266,8 @@ bool Graphics::isCreated() const
 void Graphics::setScissor(int x, int y, int width, int height)
 {
 	glEnable(GL_SCISSOR_TEST);
-	glScissor(x, getRenderHeight() - (y + height), width, height); // Compensates for the fact that our y-coordinate is reverse of OpenGLs.
+	// Compensates for the fact that our y-coordinate is reverse of OpenGL's.
+	glScissor(x, getRenderHeight() - (y + height), width, height);
 }
 
 void Graphics::setScissor()
@@ -1005,7 +1006,7 @@ static void draw_overdraw(Vector *overdraw, size_t count, float pixel_size, bool
 	glDisableClientState(GL_COLOR_ARRAY);
 	// "if GL_COLOR_ARRAY is enabled, the value of the current color is
 	// undefined after glDrawArrays executes"
-	
+
 	gl.setColor(c);
 
 	delete[] colors;
@@ -1299,8 +1300,7 @@ void Graphics::shear(float kx, float ky)
 void Graphics::origin()
 {
 	glLoadIdentity();
-	pixel_size_stack.clear();
-	pixel_size_stack.push_back(1);
+	pixel_size_stack.back() = 1;
 }
 
 } // opengl

+ 2 - 2
src/modules/graphics/opengl/SpriteBatch.cpp

@@ -124,7 +124,7 @@ int SpriteBatch::addg(Geometry *geom, float x, float y, float a, float sx, float
 		return -1;
 
 	if (geom->getVertexCount() != 4)
-		throw love::Exception("Can only add quadliteral geometries to SpriteBatch");
+		throw love::Exception("Can only add quadrilateral geometries to SpriteBatch");
 
 	for (size_t i = 0; i < 4; i++)
 		sprite[i] = geom->getVertex(i);
@@ -169,9 +169,9 @@ void SpriteBatch::unlock()
 
 void SpriteBatch::setImage(Image *newimage)
 {
+	newimage->retain();
 	image->release();
 	image = newimage;
-	image->retain();
 }
 
 Image *SpriteBatch::getImage()