Java Code Examples for org.lwjgl.opengl.GL11#glGenTextures()

The following examples show how to use org.lwjgl.opengl.GL11#glGenTextures() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LWJGL15DrawContext.java    From settlers-remake with MIT License 6 votes vote down vote up
@Override
public TextureHandle generateTexture(int width, int height, ShortBuffer data, String name) {
	int texture = GL11.glGenTextures();
	if (texture == 0) {
		return null;
	}

	//fix strange alpha test problem (minimap and landscape are unaffected)
	ShortBuffer bfr = BufferUtils.createShortBuffer(data.capacity());
	int cap = data.capacity();
	for(int i = 0;i != cap;i++)	bfr.put(i, data.get(i));

	TextureHandle textureHandle = new TextureHandle(this, texture);
	bindTexture(textureHandle);
	GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0,
			GL11.GL_RGBA, GL12.GL_UNSIGNED_SHORT_4_4_4_4, bfr);
	setTextureParameters();

	setObjectLabel(GL11.GL_TEXTURE, texture, name + "-tex");

	return textureHandle;
}
 
Example 2
Source File: CurveRenderState.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Reads the first row of the slider gradient texture and upload it as
 * a 1D texture to OpenGL if it hasn't already been done.
 */
public void initGradient() {
	if (gradientTexture == 0) {
		Image slider = GameImage.SLIDER_GRADIENT.getImage().getScaledCopy(1.0f / GameImage.getUIscale());
		staticState.gradientTexture = GL11.glGenTextures();
		ByteBuffer buff = BufferUtils.createByteBuffer(slider.getWidth() * 4);
		for (int i = 0; i < slider.getWidth(); ++i) {
			Color col = slider.getColor(i, 0);
			buff.put((byte) (255 * col.r));
			buff.put((byte) (255 * col.g));
			buff.put((byte) (255 * col.b));
			buff.put((byte) (255 * col.a));
		}
		buff.flip();
		GL11.glBindTexture(GL11.GL_TEXTURE_1D, gradientTexture);
		GL11.glTexImage1D(GL11.GL_TEXTURE_1D, 0, GL11.GL_RGBA, slider.getWidth(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buff);
		ContextCapabilities capabilities = GLContext.getCapabilities();
		if (capabilities.OpenGL30) {
			GL30.glGenerateMipmap(GL11.GL_TEXTURE_1D);
		} else if (capabilities.GL_EXT_framebuffer_object) {
			EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_1D);
		} else {
			GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
		}
	}
}
 
Example 3
Source File: LegacyCurveRenderState.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Reads the first row of the slider gradient texture and upload it as
 * a 1D texture to OpenGL if it hasn't already been done.
 */
public void initGradient() {
	if (gradientTexture == 0) {
		Image slider = GameImage.SLIDER_GRADIENT_EXPERIMENTAL.getImage().getScaledCopy(1.0f / GameImage.getUIscale());
		staticState.gradientTexture = GL11.glGenTextures();
		ByteBuffer buff = BufferUtils.createByteBuffer(slider.getWidth() * 4);
		for (int i = 0; i < slider.getWidth(); ++i) {
			Color col = slider.getColor(i, 0);
			buff.put((byte) (255 * col.r));
			buff.put((byte) (255 * col.g));
			buff.put((byte) (255 * col.b));
			buff.put((byte) (255 * col.a));
		}
		buff.flip();
		GL11.glBindTexture(GL11.GL_TEXTURE_1D, gradientTexture);
		GL11.glTexImage1D(GL11.GL_TEXTURE_1D, 0, GL11.GL_RGBA, slider.getWidth(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buff);
		EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_1D);
	}
}
 
Example 4
Source File: CurveRenderState.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Reads the first row of the slider gradient texture and upload it as
 * a 1D texture to OpenGL if it hasn't already been done.
 */
public void initGradient() {
	if (gradientTexture == 0) {
		Image slider = GameImage.SLIDER_GRADIENT.getImage().getScaledCopy(1.0f / GameImage.getUIscale());
		staticState.gradientTexture = GL11.glGenTextures();
		ByteBuffer buff = BufferUtils.createByteBuffer(slider.getWidth() * 4);
		for (int i = 0; i < slider.getWidth(); ++i) {
			Color col = slider.getColor(i, 0);
			buff.put((byte) (255 * col.b));
			buff.put((byte) (255 * col.b)); // I know this looks strange...
			buff.put((byte) (255 * col.b));
			buff.put((byte) (255 * col.a));
		}
		buff.flip();
		GL11.glBindTexture(GL11.GL_TEXTURE_1D, gradientTexture);
		GL11.glTexImage1D(GL11.GL_TEXTURE_1D, 0, GL11.GL_RGBA, slider.getWidth(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buff);
		EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_1D);
	}
}
 
Example 5
Source File: FrameBufferContainer.java    From LookingGlass with GNU General Public License v3.0 6 votes vote down vote up
private void allocateFrameBuffer() {
	if (this.framebuffer != 0) return;

	this.framebuffer = EXTFramebufferObject.glGenFramebuffersEXT(); //Release via: EXTFramebufferObject.glDeleteFramebuffersEXT(framebuffer);
	this.depthBuffer = EXTFramebufferObject.glGenRenderbuffersEXT(); //Release via: EXTFramebufferObject.glDeleteRenderbuffersEXT(depthBuffer);

	EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, this.framebuffer);

	EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, depthBuffer);
	if (MinecraftForgeClient.getStencilBits() == 0) EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, GL14.GL_DEPTH_COMPONENT24, width, height);
	else EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, org.lwjgl.opengl.EXTPackedDepthStencil.GL_DEPTH24_STENCIL8_EXT, width, height);

	EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, depthBuffer);
	if (MinecraftForgeClient.getStencilBits() != 0) EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_STENCIL_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, depthBuffer);

	this.texture = GL11.glGenTextures(); //Release via: GL11.glDeleteTextures(colorTexture);
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.texture);
	GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
	GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL11.GL_RGBA, GL11.GL_INT, (java.nio.ByteBuffer) null);
	EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, this.texture, 0);

	EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);
}
 
Example 6
Source File: Test.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
private final static int createTexture(int width, int height, IntBuffer pixel_data) {
	IntBuffer handle_buffer = BufferUtils.createIntBuffer(1);
	GL11.glGenTextures(handle_buffer);
	int tex_handle = handle_buffer.get(0);

	GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex_handle);
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
	GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL12.GL_UNSIGNED_INT_8_8_8_8, pixel_data);

	return tex_handle;
}
 
Example 7
Source File: Texture.java    From mapwriter with MIT License 5 votes vote down vote up
public Texture(int w, int h, int fillColour, int minFilter, int maxFilter, int textureWrap) {
	this.id = GL11.glGenTextures();
	this.w = w;
	this.h = h;
	this.pixelBuf = MwUtil.allocateDirectIntBuffer(w * h);
	this.fillRect(0, 0, w, h, fillColour);
	this.pixelBuf.position(0);
	this.bind();
	GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, w, h, 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, this.pixelBuf);
	this.setTexParameters(minFilter, maxFilter, textureWrap);
}
 
Example 8
Source File: Rendertarget.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new FBO.
 * @param width the width
 * @param height the height
 */
private Rendertarget(int width, int height) {
	this.width = width;
	this.height = height;
	fboID = EXTFramebufferObject.glGenFramebuffersEXT();
	vboID = GL15.glGenBuffers();
	textureID = GL11.glGenTextures();
	depthBufferID = EXTFramebufferObject.glGenRenderbuffersEXT();
}
 
Example 9
Source File: GenericShader.java    From LWJGUI with MIT License 5 votes vote down vote up
public GenericShader(URL vertexShader, URL fragmentShader) {

		// make the shader
		vertexId = compileShader(vertexShader, true);
		fragmentId = compileShader(fragmentShader, false);
		posLoc = 0;
		texCoordLoc = 1;
		id = createProgram(
				vertexId,
				new int[] { fragmentId },
				new String[] { "inPos", "inTexCoord" },
				new int[] { posLoc, texCoordLoc }
				);

		projMatLoc = GL20.glGetUniformLocation(id, "projectionMatrix");
		viewMatLoc = GL20.glGetUniformLocation(id, "viewMatrix");
		worldMatLoc = GL20.glGetUniformLocation(id, "worldMatrix");
		
		// Generic white texture
		texId = GL11.glGenTextures();
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);
		int wid = 1;
		int hei = 1;
		ByteBuffer data = BufferUtils.createByteBuffer(wid*hei*4);
		while(data.hasRemaining()) {
			data.put((byte) (255 & 0xff));
		}
		data.flip();
		GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, wid, hei, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, data);
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
	}
 
Example 10
Source File: ClientDynamicTexture.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
/**
 * Returns the GL texture ID of this image, if it doesnt exist, then creates it
 * @return the GL texture ID of this image
 */
public int getTextureId() {
	if(textureId != -1)
		return textureId;
	
	textureId = GL11.glGenTextures();
	return textureId;
}
 
Example 11
Source File: Rendertarget.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new FBO.
 * @param width the width
 * @param height the height
 */
private Rendertarget(int width, int height) {
	this.width = width;
	this.height = height;
	fboID = EXTFramebufferObject.glGenFramebuffersEXT();
	vboID = GL15.glGenBuffers();
	textureID = GL11.glGenTextures();
	depthBufferID = EXTFramebufferObject.glGenRenderbuffersEXT();
}
 
Example 12
Source File: TextureUtils.java    From OpenGL-Animation with The Unlicense 5 votes vote down vote up
protected static int loadTextureToOpenGL(TextureData data, TextureBuilder builder) {
	int texID = GL11.glGenTextures();
	GL13.glActiveTexture(GL13.GL_TEXTURE0);
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID);
	GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
	GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, data.getWidth(), data.getHeight(), 0, GL12.GL_BGRA,
			GL11.GL_UNSIGNED_BYTE, data.getBuffer());
	if (builder.isMipmap()) {
		GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
		if (builder.isAnisotropic() && GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic) {
			GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0);
			GL11.glTexParameterf(GL11.GL_TEXTURE_2D, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT,
					4.0f);
		}
	} else if (builder.isNearest()) {
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
	} else {
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
	}
	if (builder.isClampEdges()) {
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
	} else {
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
	}
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
	return texID;
}
 
Example 13
Source File: TextureAttachment.java    From LowPolyWater with The Unlicense 5 votes vote down vote up
@Override
public void init(int attachment, int width, int height, int samples) {	
	int texture = GL11.glGenTextures();
	super.setBufferId(texture);	
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);	
	indicateStorageType(width, height);
	setTextureParams();
	GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, attachment, GL11.GL_TEXTURE_2D, texture, 0);
}
 
Example 14
Source File: OpenGL3_TheQuadTextured.java    From ldparteditor with MIT License 4 votes vote down vote up
private int loadPNGTexture(String filename, int textureUnit) {
    ByteBuffer buf = null;
    int tWidth = 0;
    int tHeight = 0;
     
    try {
        // Open the PNG file as an InputStream
        InputStream in = new FileInputStream(filename);
        // Link the PNG decoder to this stream
        PNGDecoder decoder = new PNGDecoder(in);
         
        // Get the width and height of the texture
        tWidth = decoder.getWidth();
        tHeight = decoder.getHeight();
         
         
        // Decode the PNG file in a ByteBuffer
        buf = ByteBuffer.allocateDirect(
                4 * decoder.getWidth() * decoder.getHeight());
        decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA);
        buf.flip();
         
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(-1);
    }
     
    // Create a new texture object in memory and bind it
    int texId = GL11.glGenTextures();
    GL13.glActiveTexture(textureUnit);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);
     
    // All RGB bytes are aligned to each other and each component is 1 byte
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
     
    // Upload the texture data and generate mip maps (for scaling)
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, tWidth, tHeight, 0, 
            GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf);
    GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
     
    // Setup the ST coordinate system
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
     
    // Setup what to do when the texture has to be scaled
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, 
            GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, 
            GL11.GL_LINEAR_MIPMAP_LINEAR);
     
    this.exitOnGLError("loadPNGTexture");
     
    return texId;
}
 
Example 15
Source File: LwjglTextureUtils.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static int createTexture(BufferedImage imageData, TextureFilter filterMode)
{
	imageData = convertToGlFormat(imageData);
	
	IntBuffer buff = BufferUtils.createIntBuffer(16);
	buff.limit(1);
	GL11.glGenTextures(buff);
	
	int textureId = buff.get();
	
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
	if (filterMode == TextureFilter.NEAREST)
	{
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
	}
	else
	{
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
	}
	
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
	
	ByteBuffer scratch = ByteBuffer.allocateDirect(4*imageData.getWidth()*imageData.getHeight());

	Raster raster = imageData.getRaster();
	byte data[] = (byte[])raster.getDataElements(0, 0, imageData.getWidth(), imageData.getHeight(), null);
	scratch.clear();
	scratch.put(data);
	scratch.rewind();
	
	GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA,					// Mip level & Internal format
						imageData.getWidth(), imageData.getHeight(), 0,		// width, height, border
						GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE,				// pixel data format
						scratch);											// pixel data
	
	GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0,
			0, 0,
			imageData.getWidth(), imageData.getHeight(),
			GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE,			// format, type
			scratch);
	
	return textureId;
}
 
Example 16
Source File: LwjglTextureUtils.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static int createTexture(BufferedImage[] mips, TextureFilter filterMode)
{
	IntBuffer buff = BufferUtils.createIntBuffer(16);
	buff.limit(1);
	GL11.glGenTextures(buff);
	
	int textureId = buff.get();
	
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
	if (filterMode == TextureFilter.NEAREST)
	{
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR);
	}
	else
	{
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
	}
	
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
	
	for (int mip=0; mip<mips.length; mip++)
	{
		BufferedImage imageData = mips[mip];
		imageData = convertToGlFormat(imageData);
		
		ByteBuffer scratch = ByteBuffer.allocateDirect(4*imageData.getWidth()*imageData.getHeight());

		Raster raster = imageData.getRaster();
		byte data[] = (byte[])raster.getDataElements(0, 0, imageData.getWidth(), imageData.getHeight(), null);
		scratch.clear();
		scratch.put(data);
		scratch.rewind();
		
		GL11.glTexImage2D(GL11.GL_TEXTURE_2D, mip, GL11.GL_RGBA,				// Mip level & Internal format
							imageData.getWidth(), imageData.getHeight(), 0,		// width, height, border
							GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE,				// pixel data format
							scratch);											// pixel data
		
	//	GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0,
	//			0, 0,
	//			imageData.getWidth(), imageData.getHeight(),
	//			GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE,			// format, type
	//			scratch);
	}
	
	return textureId;
}
 
Example 17
Source File: TrueTypeFont.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 4 votes vote down vote up
public static int loadImage(BufferedImage bufferedImage) {
    try {
	    short width       = (short)bufferedImage.getWidth();
	    short height      = (short)bufferedImage.getHeight();
	    //textureLoader.bpp = bufferedImage.getColorModel().hasAlpha() ? (byte)32 : (byte)24;
	    int bpp = (byte)bufferedImage.getColorModel().getPixelSize();
	    ByteBuffer byteBuffer;
	    DataBuffer db = bufferedImage.getData().getDataBuffer();
	    if (db instanceof DataBufferInt) {
	    	int intI[] = ((DataBufferInt)(bufferedImage.getData().getDataBuffer())).getData();
	    	byte newI[] = new byte[intI.length * 4];
	    	for (int i = 0; i < intI.length; i++) {
	    		byte b[] = intToByteArray(intI[i]);
	    		int newIndex = i*4;

	    		newI[newIndex]   = b[1];
	    		newI[newIndex+1] = b[2];
	    		newI[newIndex+2] = b[3];
	    		newI[newIndex+3] = b[0];
	    	}

	    	byteBuffer  = ByteBuffer.allocateDirect(
	    			width*height*(bpp/8))
		                           .order(ByteOrder.nativeOrder())
		                            .put(newI);
	    } else {
	    	byteBuffer  = ByteBuffer.allocateDirect(
	    			width*height*(bpp/8))
		                           .order(ByteOrder.nativeOrder())
		                            .put(((DataBufferByte)(bufferedImage.getData().getDataBuffer())).getData());
	    }
	    byteBuffer.flip();


	    int internalFormat = GL11.GL_RGBA8,
		format = GL11.GL_RGBA;
		IntBuffer   textureId =  BufferUtils.createIntBuffer(1);;
		GL11.glGenTextures(textureId);
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId.get(0));

		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);


		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
		//GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
		//GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_NEAREST);

		//GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
		//GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR);
		//GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_NEAREST);

		GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);

		GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, internalFormat, width, height, format, GL11.GL_UNSIGNED_BYTE, byteBuffer);
		return textureId.get(0);

	} catch (Exception e) {
    	e.printStackTrace();
    	System.exit(-1);
    }

	return -1;
}
 
Example 18
Source File: ImmediateModeOGLRenderer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void glGenTextures(IntBuffer ids) {
	GL11.glGenTextures(ids);
}
 
Example 19
Source File: OffscreenBuffer.java    From LWJGUI with MIT License 4 votes vote down vote up
/**
 * Resize the buffer to desired width/height
 * @param width
 * @param height
 * @return
 */
public boolean resize(int width, int height) {
	if (this.width == width && this.height == height) {
		return false;
	}
	
	this.width = width;
	this.height = height;

	// resize the texture
	if (texId != 0) {
		GL11.glDeleteTextures(texId);
		GL30.glDeleteFramebuffers(fboId);
		GL30.glDeleteRenderbuffers(renderId);
		texId = 0;
		fboId = 0;
		renderId = 0;
	}
	
	// Create texture
	if ( texId == 0 )
		texId = GL11.glGenTextures();
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);
	GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, 0);
	
	// Set default filtering
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
	GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
	GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
	
	// update the framebuf
	if (fboId == 0)
		fboId = GL30.glGenFramebuffers();
	GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fboId);
	GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, texId, 0);
	
	// The depth buffer
	if ( renderId == 0 )
		renderId = GL30.glGenRenderbuffers();
	GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, renderId);
	GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL11.GL_DEPTH_COMPONENT, width, height);
	GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, renderId);
	
	// remove the old quad
	quadDirty = true;
	

	GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
	
	return true;
}