當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。