Commits

Alex Szpakowski committed 89cc720

Changed images and canvases to draw using triangle strips instead of deprecated quads, removed useless (?) love.graphics.drawTest function

  • Participants
  • Parent commits b01df32
  • Branches GLES2-compatibility

Comments (0)

Files changed (7)

src/modules/graphics/opengl/Canvas.cpp

 	vertices[1].x = 0;
 	vertices[1].y = 0;
 	vertices[2].x = w;
-	vertices[2].y = 0;
+	vertices[2].y = h;
 	vertices[3].x = w;
-	vertices[3].y = h;
+	vertices[3].y = 0;
 
 	// texture coordinates
 	vertices[0].s = 0;
 	vertices[1].s = 0;
 	vertices[1].t = 1;
 	vertices[2].s = 1;
-	vertices[2].t = 1;
+	vertices[2].t = 0;
 	vertices[3].s = 1;
-	vertices[3].t = 0;
+	vertices[3].t = 1;
 
 	settings.filter = Image::getDefaultFilter();
 
 	glReadPixels(x, height - y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel_rgba);
 
 	if (current)
-		strategy->bindFBO( current->fbo );
+		strategy->bindFBO(current->fbo);
 	else
-		strategy->bindFBO( 0 );
+		strategy->bindFBO(0);
 }
 
 void Canvas::setFilter(const Image::Filter &f)
 	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 	glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].x);
 	glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].s);
-	glDrawArrays(GL_QUADS, 0, 4);
+	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 	glDisableClientState(GL_VERTEX_ARRAY);
 

src/modules/graphics/opengl/Font.cpp

 	float dx = 0.0f; // spacing counter for newline handling
 	float dy = 0.0f;
 
+	Context *ctx = getContext();
+
 	// keeps track of when we need to switch textures in our vertex array
 	std::vector<GlyphArrayDrawInfo> glyphinfolist;
 
 		std::vector<GlyphArrayDrawInfo>::const_iterator it;
 		for (it = glyphinfolist.begin(); it != glyphinfolist.end(); ++it)
 		{
-			getContext()->bindTexture(it->texture);
+			ctx->bindTexture(it->texture);
 
 			int startvertex = it->startquad * 4;
 			int numvertices = it->numquads * 4;

src/modules/graphics/opengl/Graphics.cpp

 	glMultMatrixf((const GLfloat *)t.getElements());
 }
 
-void Graphics::drawTest(Image *image, float x, float y, float a, float sx, float sy, float ox, float oy)
-{
-	image->bind();
-
-	// Buffer for transforming the image.
-	vertex buf[4];
-
-	Matrix t;
-	t.translate(x, y);
-	t.rotate(a);
-	t.scale(sx, sy);
-	t.translate(ox, oy);
-	t.transform(buf, image->getVertices(), 4);
-
-	const vertex *vertices = image->getVertices();
-
-	glEnableClientState(GL_VERTEX_ARRAY);
-	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-	glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&buf[0].x);
-	glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&vertices[0].s);
-	glDrawArrays(GL_QUADS, 0, 4);
-	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-	glDisableClientState(GL_VERTEX_ARRAY);
-}
-
 bool Graphics::hasFocus()
 {
 	return currentWindow->hasFocus();

src/modules/graphics/opengl/Graphics.h

 	void translate(float x, float y);
 	void shear(float kx, float ky);
 
-	void drawTest(Image *image, float x, float y, float a, float sx, float sy, float ox, float oy);
-
 	bool hasFocus();
 private:
 

src/modules/graphics/opengl/Image.cpp

 	vertices[1].x = 0;
 	vertices[1].y = height;
 	vertices[2].x = width;
-	vertices[2].y = height;
+	vertices[2].y = 0;
 	vertices[3].x = width;
-	vertices[3].y = 0;
+	vertices[3].y = height;
 
 	vertices[0].s = 0;
 	vertices[0].t = 0;
 	vertices[1].s = 0;
 	vertices[1].t = 1;
 	vertices[2].s = 1;
-	vertices[2].t = 1;
+	vertices[2].t = 0;
 	vertices[3].s = 1;
-	vertices[3].t = 0;
+	vertices[3].t = 1;
 
 	filter = getDefaultFilter();
 }
 	vertices[1].x = 0;
 	vertices[1].y = (float)h;
 	vertices[2].x = (float)w;
-	vertices[2].y = (float)h;
+	vertices[2].y = 0;
 	vertices[3].x = (float)w;
-	vertices[3].y = 0;
+	vertices[3].y = (float)h;
 
 	float tx = (float)x/width;
 	float ty = (float)y/height;
 	vertices[1].s = tx;
 	vertices[1].t = ty+th;
 	vertices[2].s = tx+tw;
-	vertices[2].t = ty+th;
+	vertices[2].t = ty;
 	vertices[3].s = tx+tw;
-	vertices[3].t = ty;
+	vertices[3].t = ty+th;
 }
 
 void Image::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
 	float t = height/p2height;
 
 	vertices[1].t = t;
-	vertices[2].t = t;
 	vertices[2].s = s;
+	vertices[3].t = t;
 	vertices[3].s = s;
 
 	glTexImage2D(GL_TEXTURE_2D,
 	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 	glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].x);
 	glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&v[0].s);
-	glDrawArrays(GL_QUADS, 0, 4);
+	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 	glDisableClientState(GL_VERTEX_ARRAY);
 

src/modules/graphics/opengl/wrap_Graphics.cpp

 	return 0;
 }
 
-int w_drawTest(lua_State *L)
-{
-	Image *image = luax_checktype<Image>(L, 1, "Image", GRAPHICS_IMAGE_T);
-	float x = (float)luaL_optnumber(L, 2, 0.0f);
-	float y = (float)luaL_optnumber(L, 3, 0.0f);
-	float angle = (float)luaL_optnumber(L, 4, 0.0f);
-	float sx = (float)luaL_optnumber(L, 5, 1.0f);
-	float sy = (float)luaL_optnumber(L, 6, sx);
-	float ox = (float)luaL_optnumber(L, 7, 0);
-	float oy = (float)luaL_optnumber(L, 8, 0);
-	instance->drawTest(image, x, y, angle, sx, sy, ox, oy);
-	return 0;
-}
-
 int w_print(lua_State *L)
 {
 	const char *str = luaL_checkstring(L, 1);
 
 	{ "draw", w_draw },
 	{ "drawq", w_drawq },
-	{ "drawTest", w_drawTest },
 
 	{ "print", w_print },
 	{ "printf", w_printf },

src/modules/graphics/opengl/wrap_Graphics.h

 int w_isSupported(lua_State *L);
 int w_draw(lua_State *L);
 int w_drawq(lua_State *L);
-int w_drawTest(lua_State *L);
 int w_print(lua_State *L);
 int w_printf(lua_State *L);
 int w_point(lua_State *L);