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


Java InternalTextureLoader.createTextureID方法代码示例

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


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

示例1: getTexture

import org.newdawn.slick.opengl.InternalTextureLoader; //导入方法依赖的package包/类
/**
 * Load a texture into OpenGL from a BufferedImage
 * 
 * @param resourceName
 *            The location of the resource to load
 * @param resourceimage
 *            The BufferedImage we are converting
 * @param target
 *            The GL target to load the texture against
 * @param dstPixelFormat
 *            The pixel format of the screen
 * @param minFilter
 *            The minimising filter
 * @param magFilter
 *            The magnification filter
 * @return The loaded texture
 * @throws IOException
 *             Indicates a failure to access the resource
 */
public static Texture getTexture(String resourceName,
		BufferedImage resourceimage, int target, int dstPixelFormat,
		int minFilter, int magFilter) throws IOException {
	ImageIOImageData data = new ImageIOImageData();int srcPixelFormat = 0;

	// create the texture ID for this texture
	int textureID = InternalTextureLoader.createTextureID();
	TextureImpl texture = new TextureImpl(resourceName, target, textureID);

	// Enable texturing
	Renderer.get().glEnable(SGL.GL_TEXTURE_2D);

	// bind this texture
	Renderer.get().glBindTexture(target, textureID);

	BufferedImage bufferedImage = resourceimage;
	texture.setWidth(bufferedImage.getWidth());
	texture.setHeight(bufferedImage.getHeight());

	if (bufferedImage.getColorModel().hasAlpha()) {
		srcPixelFormat = SGL.GL_RGBA;
	} else {
		srcPixelFormat = SGL.GL_RGB;
	}

	// convert that image into a byte buffer of texture data
	ByteBuffer textureBuffer = data.imageToByteBuffer(bufferedImage, false, false, null);
	texture.setTextureHeight(data.getTexHeight());
	texture.setTextureWidth(data.getTexWidth());
	texture.setAlpha(data.getDepth() == 32);
	
	if (target == SGL.GL_TEXTURE_2D) {
		Renderer.get().glTexParameteri(target, SGL.GL_TEXTURE_MIN_FILTER, minFilter);
		Renderer.get().glTexParameteri(target, SGL.GL_TEXTURE_MAG_FILTER, magFilter);
		
        if (Renderer.get().canTextureMirrorClamp()) {
        	Renderer.get().glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_S, SGL.GL_MIRROR_CLAMP_TO_EDGE_EXT);
        	Renderer.get().glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_T, SGL.GL_MIRROR_CLAMP_TO_EDGE_EXT);
        } else {
        	Renderer.get().glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_S, SGL.GL_CLAMP);
        	Renderer.get().glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_T, SGL.GL_CLAMP);
        }
	}

	Renderer.get().glTexImage2D(target, 
                     0, 
                     dstPixelFormat, 
                     texture.getTextureWidth(), 
                     texture.getTextureHeight(), 
                     0, 
                     srcPixelFormat, 
                     SGL.GL_UNSIGNED_BYTE, 
                     textureBuffer); 

	return texture;
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:76,代码来源:BufferedImageUtil.java

示例2: resolved

import org.newdawn.slick.opengl.InternalTextureLoader; //导入方法依赖的package包/类
@Override
public Object resolved(Object ret_) throws PromiseException
{
        pending.decrementAndGet();
        
        Object[] ret = (Object[]) ret_;
        
        ByteBuffer textureBytes = (ByteBuffer) ret[0];
        int imageWidth = (Integer) ret[1];
        int imageHeight = (Integer) ret[2];
        boolean hasAlpha = ((Integer) ret[3]) == 32;
        int texWidth = (Integer) ret[4];
        int texHeight = (Integer) ret[5];
        
        int srcPixelFormat = hasAlpha ? GL11.GL_RGBA : GL11.GL_RGB;
        int componentCount = hasAlpha ? 4 : 3;
        
        IntBuffer temp = BufferUtils.createIntBuffer(16);
        GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE, temp);
        int max = temp.get(0);
        if ((texWidth > max) || (texHeight > max))
        {
                texture.error = true;
                log.log(Level.SEVERE, "Attempt to allocate a texture too big for the current hardware");
                return null;
        }
        
        texture.textureID = InternalTextureLoader.createTextureID();
        GL11.glBindTexture(texture.target, texture.textureID); 
        
        // todo: different filters?
        GL11.glTexParameteri(texture.target, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); 
        GL11.glTexParameteri(texture.target, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
        
        GL11.glTexImage2D(
                texture.target, 
                0, 
                GL11.GL_RGBA8, 
                InternalTextureLoader.get2Fold(imageWidth), 
                InternalTextureLoader.get2Fold(imageHeight), 
                0, 
                srcPixelFormat, 
                GL11.GL_UNSIGNED_BYTE, 
                textureBytes);
        
        texture.imageWidth = imageWidth;
        texture.imageHeight = imageHeight;
        texture.texWidth = texWidth;
        texture.texHeight = texHeight;
        texture.alpha = hasAlpha;
        texture.widthRatio = (float)imageWidth / texWidth;
        texture.heightRatio = (float)imageHeight / texHeight;
        texture.error = false;
        texture.loaded();
        
        log.log(Level.INFO, "Texture {0} loaded. {1}", new Object[] { texture.getResourceKey(), hasAlpha});
        
        return null;
}
 
开发者ID:Periapsis,项目名称:aphelion,代码行数:60,代码来源:AsyncTextureLoader.java


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