Commits

Christian Fischer committed c5be41c

changed spriteframes to store their texture coordinates in pixels

Comments (0)

Files changed (4)

src/core/wiesel/graph/2d/multisprite_node.cpp

 			indices->setBytesPerElement(2);
 		}
 
+		float texture_w = texture->getSize().width;
+		float texture_h = texture->getSize().height;
+
 		for (EntryList::const_iterator it=entries.begin(); it!=entries.end(); it++) {
 			SpriteFrame *frame = it->sprite;
 
+			const SpriteFrame::TextureCoords &tex_coords = frame->getTextureCoordinates();
 			float sprite_x = frame->getInnerRect().position.x + it->offset.x;
 			float sprite_y = frame->getInnerRect().position.y + it->offset.y;
 			float sprite_w = frame->getInnerRect().size.width;
 			VertexBuffer::index_t idx2 = vbo->addVertex(sprite_x + sprite_w, sprite_y + sprite_h);
 			VertexBuffer::index_t idx3 = vbo->addVertex(sprite_x + sprite_w, sprite_y           );
 
-			vbo->setVertexTextureCoordinate(idx0, frame->getTextureCoordinates().tl);
-			vbo->setVertexTextureCoordinate(idx1, frame->getTextureCoordinates().bl);
-			vbo->setVertexTextureCoordinate(idx2, frame->getTextureCoordinates().tr);
-			vbo->setVertexTextureCoordinate(idx3, frame->getTextureCoordinates().br);
+			vbo->setVertexTextureCoordinate(idx0, tex_coords.tl.u/texture_w, tex_coords.tl.v/texture_h);
+			vbo->setVertexTextureCoordinate(idx1, tex_coords.bl.u/texture_w, tex_coords.bl.v/texture_h);
+			vbo->setVertexTextureCoordinate(idx2, tex_coords.tr.u/texture_w, tex_coords.tr.v/texture_h);
+			vbo->setVertexTextureCoordinate(idx3, tex_coords.br.u/texture_w, tex_coords.br.v/texture_h);
 
 			indices->addIndex(idx0);
 			indices->addIndex(idx1);

src/core/wiesel/graph/2d/sprite_node.cpp

 			float sprite_w = getSpriteFrame()->getInnerRect().size.width;
 			float sprite_h = getSpriteFrame()->getInnerRect().size.height;
 
+			const SpriteFrame::TextureCoords &tex_coords = getSpriteFrame()->getTextureCoordinates();
+			float texture_w = texture->getSize().width;
+			float texture_h = texture->getSize().height;
+
 			vbo->clear();
 			vbo->setupVertexPositions(2);
 			vbo->setupTextureLayer(0);
 			vbo->addVertex(sprite_x + sprite_w, sprite_y + sprite_h);
 			vbo->addVertex(sprite_x + sprite_w, sprite_y           );
 
-			vbo->setVertexTextureCoordinate(0, getSpriteFrame()->getTextureCoordinates().tl);
-			vbo->setVertexTextureCoordinate(1, getSpriteFrame()->getTextureCoordinates().bl);
-			vbo->setVertexTextureCoordinate(2, getSpriteFrame()->getTextureCoordinates().tr);
-			vbo->setVertexTextureCoordinate(3, getSpriteFrame()->getTextureCoordinates().br);
+			vbo->setVertexTextureCoordinate(0, tex_coords.tl.u/texture_w, tex_coords.tl.v/texture_h);
+			vbo->setVertexTextureCoordinate(1, tex_coords.bl.u/texture_w, tex_coords.bl.v/texture_h);
+			vbo->setVertexTextureCoordinate(2, tex_coords.tr.u/texture_w, tex_coords.tr.v/texture_h);
+			vbo->setVertexTextureCoordinate(3, tex_coords.br.u/texture_w, tex_coords.br.v/texture_h);
 		}
 		else {
 			float sprite_x   = 0.0f;

src/core/wiesel/resources/graphics/spriteframe.cpp

 		this->inner_rect  = rectangle(texture->getOriginalSize());
 		this->sprite_size = texture->getOriginalSize();
 		
-		float texture_w  = texture->getSize().width;
-		float texture_h  = texture->getSize().height;
-		
-		float texcoord_l = inner_rect.getMinX() / texture_w;
-		float texcoord_t = inner_rect.getMinY() / texture_h;
-		float texcoord_r = inner_rect.getMaxX() / texture_w;
-		float texcoord_b = inner_rect.getMaxY() / texture_h;
+		float texcoord_l = inner_rect.getMinX();
+		float texcoord_t = inner_rect.getMinY();
+		float texcoord_r = inner_rect.getMaxX();
+		float texcoord_b = inner_rect.getMaxY();
 		
 		texture_coordinates.tl = vector2d(texcoord_l, texcoord_t);
 		texture_coordinates.tr = vector2d(texcoord_r, texcoord_t);
 
 		sprite_size = texture_rect.size;
 
-		float texture_w  = texture->getSize().width;
-		float texture_h  = texture->getSize().height;
-
-		float texcoord_l = texture_rect.getMinX() / texture_w;
-		float texcoord_t = texture_rect.getMinY() / texture_h;
-		float texcoord_r = texture_rect.getMaxX() / texture_w;
-		float texcoord_b = texture_rect.getMaxY() / texture_h;
+		float texcoord_l = texture_rect.getMinX();
+		float texcoord_t = texture_rect.getMinY();
+		float texcoord_r = texture_rect.getMaxX();
+		float texcoord_b = texture_rect.getMaxY();
 
 		texture_coordinates.tl = vector2d(texcoord_l, texcoord_t);
 		texture_coordinates.tr = vector2d(texcoord_r, texcoord_t);

src/core/wiesel/resources/graphics/spritesheet.cpp

 				sprite_outer_h = sprite_texture_h;
 			}
 
-			float texture_w = texture->getSize().width;
-			float texture_h = texture->getSize().height;
-
 			rectangle texture_rect(
 						sprite_texture_x,
 						sprite_texture_y,
 						sprite_texture_h
 			);
 			
-			float texcoord_l = texture_rect.getMinX() / texture_w;
-			float texcoord_r = texture_rect.getMaxX() / texture_w;
-			float texcoord_t = texture_rect.getMinY() / texture_h;
-			float texcoord_b = texture_rect.getMaxY() / texture_h;
+			float texcoord_l = texture_rect.getMinX();
+			float texcoord_r = texture_rect.getMaxX();
+			float texcoord_t = texture_rect.getMinY();
+			float texcoord_b = texture_rect.getMaxY();
 
 			switch(rotation) {
 				case 90: {