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

The following examples show how to use org.lwjgl.opengl.GL11#glTexSubImage2D() . 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: ClientDynamicTexture.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
public void setByteBuffer(IntBuffer buffer) {
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, getTextureId());
	
	//Just clamp to edge
	//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);
	
	//Scale linearly
	//GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
	//GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
	
	//GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
	
	//GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
	try {
		GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, image.getWidth(), image.getHeight(), GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
	} catch(IllegalArgumentException e) {
		e.printStackTrace();
		AdvancedRocketry.logger.warn("Planet image generation FX failed!");
	}
}
 
Example 2
Source File: LWJGL15DrawContext.java    From settlers-remake with MIT License 5 votes vote down vote up
@Override
public void updateTexture(TextureHandle texture, int left, int bottom,
		int width, int height, ShortBuffer data) {
	bindTexture(texture);
	GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, left, bottom, width, height,
			GL11.GL_RGBA, GL12.GL_UNSIGNED_SHORT_4_4_4_4, data);
}
 
Example 3
Source File: Texture.java    From mapwriter with MIT License 5 votes vote down vote up
public synchronized void updateTextureArea(int x, int y, int w, int h) {
	try {
		this.bind();
		GL11.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, this.w);
		this.pixelBuf.position((y * this.w) + x);
		GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, x, y, w, h, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, this.pixelBuf);
		GL11.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, 0);
	} catch (NullPointerException e) {
		MwUtil.log("MwTexture.updatePixels: null pointer exception (texture %d)", this.id);
	}
}
 
Example 4
Source File: Test.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
private final static void updateTexture(int width, int height, IntBuffer pixel_data) {
	GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, width, height, GL11.GL_RGBA, GL12.GL_UNSIGNED_INT_8_8_8_8, pixel_data);
}
 
Example 5
Source File: Video.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Updates the video.
 * @param syncTime the nanosecond time the video should sync to (forward direction only)
 */
private void update(long syncTime) {
	if (finished || closed || pauseFrame > 0 || videoStream == null)
		return;

	// initialize frames
	if (!initialized) {
		videoIndex = 0;
		initFrame = System.nanoTime();
		if (pauseFrame != 0)
			pauseFrame = initFrame;

		// change pixel store alignment to prevent distortion
		GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
		GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);

		initialized = true;
	}

	if (!isTimeForNextFrame(syncTime))
		return;

	// grab and skip frames (if needed)
	ByteBuffer texBuffer = null;
	final int backlog = 5;
	int framesRead = 0;
	do {
		// free extra frames
		if (framesRead > 0) {
			videoStream.freeFrameData(texBuffer);
			texBuffer = null;
			videoIndex++;
		}

		// grab next frame
		texBuffer = videoStream.pollFrameData();
		if (texBuffer == VideoStream.EOF) {
			finished = true;
			return;
		}
		if (texBuffer == null)
			return;

		framesRead++;
	} while (hasVideoBacklogOver(backlog, syncTime));

	// render to texture
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, image.getTexture().getTextureID());
	GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, metadata.width, metadata.height, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, texBuffer);

	videoStream.freeFrameData(texBuffer);
	videoIndex++;
}
 
Example 6
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 7
Source File: GlyphPage.java    From gdx-skineditor with Apache License 2.0 4 votes vote down vote up
/** Loads a single glyph to the backing texture, if it fits. */
private void renderGlyph (Glyph glyph, int width, int height) {
	
	// Draw the glyph to the scratch image using Java2D.
	scratchGraphics.setComposite(AlphaComposite.Clear);
	scratchGraphics.fillRect(0, 0, MAX_GLYPH_SIZE, MAX_GLYPH_SIZE);
	scratchGraphics.setComposite(AlphaComposite.SrcOver);
	if (unicodeFont.getNativeRendering()) {
		for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();) {
			Effect effect = (Effect)iter.next();
			if (effect instanceof ColorEffect) scratchGraphics.setColor(((ColorEffect)effect).getColor());
		}
		scratchGraphics.setColor(java.awt.Color.white);
		scratchGraphics.setFont(unicodeFont.getFont());
		scratchGraphics.drawString("" + (char)glyph.getCodePoint(), 0, unicodeFont.getAscent());
	} else {
		scratchGraphics.setColor(java.awt.Color.white);
		for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();)
			((Effect)iter.next()).draw(scratchImage, scratchGraphics, unicodeFont, glyph);
		glyph.setShape(null); // The shape will never be needed again.
	}

	width = Math.min(width, texture.getWidth());
	height = Math.min(height, texture.getHeight());

	WritableRaster raster = scratchImage.getRaster();
	int[] row = new int[width];
	for (int y = 0; y < height; y++) {
		raster.getDataElements(0, y, width, 1, row);
		scratchIntBuffer.put(row);
	}
	GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, pageX, pageY, width, height, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE,
		scratchByteBuffer);
	scratchIntBuffer.clear();

	float u = pageX / (float)texture.getWidth();
	float v = pageY / (float)texture.getHeight();
	float u2 = (pageX + width) / (float)texture.getWidth();
	float v2 = (pageY + height) / (float)texture.getHeight();
	glyph.setTexture(texture, u, v, u2, v2);
}
 
Example 8
Source File: ImmediateModeOGLRenderer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void glTexSubImage2D(int glTexture2d, int i, int pageX, int pageY,
		int width, int height, int glBgra, int glUnsignedByte,
		ByteBuffer scratchByteBuffer) {
	GL11.glTexSubImage2D(glTexture2d, i, pageX, pageY, width, height, glBgra, glUnsignedByte, scratchByteBuffer);
}