当前位置: 首页>>代码示例>>Java>>正文


Java Pixmap.getFormat方法代码示例

本文整理汇总了Java中com.badlogic.gdx.graphics.Pixmap.getFormat方法的典型用法代码示例。如果您正苦于以下问题:Java Pixmap.getFormat方法的具体用法?Java Pixmap.getFormat怎么用?Java Pixmap.getFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.badlogic.gdx.graphics.Pixmap的用法示例。


在下文中一共展示了Pixmap.getFormat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTextureFromBytes

import com.badlogic.gdx.graphics.Pixmap; //导入方法依赖的package包/类
/**
 * Transforms byte[] to Texture Region.
 * <p>
 * If you are going to call this method inside firebase callback remember to wrap it<p>
 * into {@code Gdx.app.postRunnable(Runnable)}.
 * The texture will be changed so that it has sides with length of power of 2.
 *
 * @param bytes Byte array with image description
 * @return Texture region representation of given byte array
 */
public static TextureRegion createTextureFromBytes(byte[] bytes)
{
    Pixmap pixmap = new Pixmap(bytes, 0, bytes.length);
    final int orgWidth = pixmap.getWidth();
    final int orgHeight = pixmap.getHeight();
    int width = MathUtils.nextPowerOfTwo(orgWidth);
    int height = MathUtils.nextPowerOfTwo(orgHeight);
    final Pixmap potPixmap = new Pixmap(width, height, pixmap.getFormat());
    potPixmap.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight());
    pixmap.dispose();
    TextureRegion region = new TextureRegion(new Texture(potPixmap), 0, 0, orgWidth, orgHeight);
    potPixmap.dispose();
    return region;
}
 
开发者ID:mk-5,项目名称:gdx-fireapp,代码行数:25,代码来源:ImageHelper.java

示例2: loadRenderModel

import com.badlogic.gdx.graphics.Pixmap; //导入方法依赖的package包/类
private Model loadRenderModel(String name) {
	if (models.containsKey(name)) return models.get(name);						

	// FIXME we load the models synchronously cause we are lazy
	int error = 0;
	PointerBuffer modelPointer = PointerBuffer.allocateDirect(1);
	while (true) {
		error = VRRenderModels.VRRenderModels_LoadRenderModel_Async(name, modelPointer);
		if (error != VR.EVRRenderModelError_VRRenderModelError_Loading) break;
	}
	
	if (error != VR.EVRRenderModelError_VRRenderModelError_None) return null;		
	RenderModel renderModel = new RenderModel(modelPointer.getByteBuffer(RenderModel.SIZEOF));
	
	error = 0;
	PointerBuffer texturePointer = PointerBuffer.allocateDirect(1);
	while (true) {
		error = VRRenderModels.VRRenderModels_LoadTexture_Async(renderModel.diffuseTextureId(), texturePointer);
		if (error != VR.EVRRenderModelError_VRRenderModelError_Loading) break;
	}
	
	if (error != VR.EVRRenderModelError_VRRenderModelError_None) {
		VRRenderModels.VRRenderModels_FreeRenderModel(renderModel);
		return null;
	}
					
	RenderModelTextureMap renderModelTexture = new RenderModelTextureMap(texturePointer.getByteBuffer(RenderModelTextureMap.SIZEOF));
	
	// convert to a Model				
	Mesh mesh = new Mesh(true, renderModel.unVertexCount(), renderModel.unTriangleCount() * 3, VertexAttribute.Position(), VertexAttribute.Normal(), VertexAttribute.TexCoords(0));
	MeshPart meshPart = new MeshPart(name, mesh, 0, renderModel.unTriangleCount() * 3, GL20.GL_TRIANGLES);
	RenderModelVertex.Buffer vertices = renderModel.rVertexData();
	float[] packedVertices = new float[8 * renderModel.unVertexCount()];
	int i = 0;
	while(vertices.remaining() > 0) {
		RenderModelVertex v = vertices.get();			
		packedVertices[i++] = v.vPosition().v(0);
		packedVertices[i++] = v.vPosition().v(1);
		packedVertices[i++] = v.vPosition().v(2);
		
		packedVertices[i++] = v.vNormal().v(0);
		packedVertices[i++] = v.vNormal().v(1);
		packedVertices[i++] = v.vNormal().v(2);
		
		packedVertices[i++] = v.rfTextureCoord().get(0);
		packedVertices[i++] = v.rfTextureCoord().get(1);
	}
	mesh.setVertices(packedVertices);
	short[] indices = new short[renderModel.unTriangleCount() * 3];
	renderModel.IndexData().get(indices);		
	mesh.setIndices(indices);
	
	Pixmap pixmap = new Pixmap(renderModelTexture.unWidth(), renderModelTexture.unHeight(), Format.RGBA8888);
	byte[] pixels = new byte[renderModelTexture.unWidth() * renderModelTexture.unHeight() * 4];
	renderModelTexture.rubTextureMapData(pixels.length).get(pixels);
	pixmap.getPixels().put(pixels);
	pixmap.getPixels().position(0);
	Texture texture = new Texture(new PixmapTextureData(pixmap, pixmap.getFormat(), true, true));
	Material material = new Material(new TextureAttribute(TextureAttribute.Diffuse, texture));		
			
	Model model = new Model();
	model.meshes.add(mesh);
	model.meshParts.add(meshPart);
	model.materials.add(material);
	Node node = new Node();
	node.id = name;		
	node.parts.add(new NodePart(meshPart, material));
	model.nodes.add(node);
	model.manageDisposable(mesh);
	model.manageDisposable(texture);
	
	VRRenderModels.VRRenderModels_FreeRenderModel(renderModel);
	VRRenderModels.VRRenderModels_FreeTexture(renderModelTexture);

	models.put(name, model);
	
	return model;
}
 
开发者ID:justinmarentette11,项目名称:Tower-Defense-Galaxy,代码行数:79,代码来源:VRContext.java


注:本文中的com.badlogic.gdx.graphics.Pixmap.getFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。