From 944a1a6e8b03c9858ac72e646f29bcefd2f16826 Mon Sep 17 00:00:00 2001 From: Bill Meltsner Date: Fri, 27 Aug 2010 08:52:14 -0500 Subject: [PATCH] SpriteBatches are now affected by love.graphics.setColor() --- src/modules/graphics/opengl/SpriteBatch.cpp | 73 ++++++++++----------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/src/modules/graphics/opengl/SpriteBatch.cpp b/src/modules/graphics/opengl/SpriteBatch.cpp index 053f64ced..8a15c01a4 100644 --- a/src/modules/graphics/opengl/SpriteBatch.cpp +++ b/src/modules/graphics/opengl/SpriteBatch.cpp @@ -1,21 +1,21 @@ -/** -* Copyright (c) 2006-2010 LOVE Development Team -* -* This software is provided 'as-is', without any express or implied -* warranty. In no event will the authors be held liable for any damages -* arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute it -* freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not -* claim that you wrote the original software. If you use this software -* in a product, an acknowledgment in the product documentation would be -* appreciated but is not required. -* 2. Altered source versions must be plainly marked as such, and must not be -* misrepresented as being the original software. -* 3. This notice may not be removed or altered from any source distribution. +/** +* Copyright (c) 2006-2010 LOVE Development Team +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would be +* appreciated but is not required. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. **/ #include "SpriteBatch.h" @@ -153,23 +153,23 @@ namespace opengl next = 0; } - void * SpriteBatch::lock() - { - // If already locked, prevent from locking again. - if(lockp != 0) - return lockp; - - glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); - lockp = (vertex *)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); - return lockp; - } - - void SpriteBatch::unlock() - { - glUnmapBuffer(GL_ARRAY_BUFFER); - lockp = 0; - glBindBuffer(GL_ARRAY_BUFFER, 0); - } + void * SpriteBatch::lock() + { + // If already locked, prevent from locking again. + if(lockp != 0) + return lockp; + + glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); + lockp = (vertex *)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); + return lockp; + } + + void SpriteBatch::unlock() + { + glUnmapBuffer(GL_ARRAY_BUFFER); + lockp = 0; + glBindBuffer(GL_ARRAY_BUFFER, 0); + } void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const { @@ -185,19 +185,16 @@ namespace opengl // Enable vertex arrays. glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); // Bind the VBO buffer. glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo[1]); - glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), (GLvoid*)0); glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)(sizeof(unsigned char)*4)); glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)(sizeof(unsigned char)*4+sizeof(float)*2)); glDrawElements(GL_TRIANGLES, next*6, GL_UNSIGNED_SHORT, 0); // Disable vertex arrays. - glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);