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

The following examples show how to use org.lwjgl.opengl.GL11#glTexImage1D() . 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: 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 2
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 3
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);
		}
	}
}