Java Code Examples for org.lwjgl.opengl.GL11#GL_RGBA

The following examples show how to use org.lwjgl.opengl.GL11#GL_RGBA . 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: GLIntImage.java    From tribaltrouble with GNU General Public License v2.0 6 votes vote down vote up
public GLIntImage(Layer layer) {
		this(layer.getWidth(), layer.getHeight(), GL11.GL_RGBA);
		for (int y = 0; y < getHeight(); y++)
			for (int x = 0; x < getWidth(); x++) {
				int ri = ((int)(layer.r.getPixel(x, y)*255 + .5f)) & 0xff;
				int gi = ((int)(layer.g.getPixel(x, y)*255 + .5f)) & 0xff;
				int bi = ((int)(layer.b.getPixel(x, y)*255 + .5f)) & 0xff;
				int ai;
				if (layer.a != null) {
					ai = ((int)(layer.a.getPixel(x, y)*255 + .5f)) & 0xff;
				} else {
					ai = 255;
				}
/*				if (ri < 0) ri = 0;
				if (gi < 0) gi = 0;
				if (bi < 0) bi = 0;
				if (ai < 0) ai = 0;
				if (ri > 255) ri = 255;
				if (gi > 255) gi = 255;
				if (bi > 255) bi = 255;
				if (ai > 255) ai = 255;*/
				int pixel = (ri << 24) | (gi << 16) | (bi << 8) | ai;
				putPixel(x, y, pixel);
			}
	}
 
Example 2
Source File: GeneratorHalos.java    From tribaltrouble with GNU General Public License v2.0 6 votes vote down vote up
public final Texture[] generate() {
	Channel channel_shadow = new Ring(size, size, shadow_parms, Ring.SMOOTH).toChannel();
	Channel channel_ring = new Ring(size, size, ring_parms, Ring.LINEAR).toChannel();
	Channel channel_black = new Channel(size, size).fill(0f);
	Channel channel_white = new Channel(size, size).fill(1f);
	Layer layers[] = new Layer[2];
	layers[SHADOWED] = new Layer(channel_black, channel_black, channel_black, channel_shadow);
	layers[SELECTED] = new Layer(channel_white.copy(), channel_white.copy(), channel_white.copy(), channel_ring);
	layers[SELECTED] = layers[SHADOWED].copy().layerBlend(layers[SELECTED]);
	Texture[] textures = new Texture[layers.length];
	for (int i = 0; i < layers.length; i++) {
		if (Landscape.DEBUG) new GLIntImage(layers[i]).saveAsPNG("generator_halos_" + i);
		textures[i] = new Texture(new GLImage[]{new GLIntImage(layers[i])}, GL11.GL_RGBA, GL11.GL_LINEAR, GL11.GL_LINEAR, GL11.GL_CLAMP, GL11.GL_CLAMP);
	}
	return textures;
}
 
Example 3
Source File: Cursor.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public Cursor(URL url_16_1, int offset_x_16_1, int offset_y_16_1,
			  URL url_32_1, int offset_x_32_1, int offset_y_32_1,
			  URL url_32_8, int offset_x_32_8, int offset_y_32_8) {
	this.offset_x = offset_x_32_8;
	this.offset_y = offset_y_32_8;
	Image image = Image.read(url_32_8);
	int width = image.getWidth();
	int height = image.getHeight();
	GLIntImage img_32_8 = new GLIntImage(width, height, image.getPixels(), GL11.GL_RGBA);

	Image image_16_1 = Image.read(url_16_1);
	GLIntImage img_16_1 = new GLIntImage(image_16_1.getWidth(), image_16_1.getHeight(), image_16_1.getPixels(), GL11.GL_RGBA);
	Image image_32_1 = Image.read(url_32_1);
	GLIntImage img_32_1 = new GLIntImage(image_32_1.getWidth(), image_32_1.getHeight(), image_32_1.getPixels(), GL11.GL_RGBA);
	
	native_cursor = new NativeCursor(img_16_1, offset_x_16_1, offset_y_16_1,
									 img_32_1, offset_x_32_1, offset_y_32_1,
									 img_32_8, offset_x_32_8, offset_y_32_8);

	texture = new Texture(new GLImage[]{img_32_8},
							GL11.GL_RGBA,
							GL11.GL_NEAREST,
							GL11.GL_NEAREST,
							GL11.GL_REPEAT,
							GL11.GL_REPEAT);
	cursor = new Quad(0, 0, 1, 1, 32, 32);
}
 
Example 4
Source File: GeneratorRing.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public final Texture[] generate() {
	Channel channel_ring = new Ring(size, size, ring_parms, Ring.LINEAR).toChannel();
	Channel channel_white = new Channel(size, size).fill(1f);
	Layer layer = new Layer(channel_white.copy(), channel_white.copy(), channel_white.copy(), channel_ring);
	Texture[] textures = new Texture[1];
	textures[0] = new Texture(new GLImage[]{new GLIntImage(layer)}, GL11.GL_RGBA, GL11.GL_LINEAR, GL11.GL_LINEAR, GL11.GL_CLAMP, GL11.GL_CLAMP);
	return textures;
}
 
Example 5
Source File: GeneratorRespond.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public final Texture[] generate() {
	GLIntImage img = new GLIntImage(1, 1, GL11.GL_RGBA);
	img.putPixel(0, 0, COLOR);
	Texture[] textures = new Texture[1];
	textures[0] = new Texture(new GLImage[]{img}, Globals.COMPRESSED_RGBA_FORMAT, GL11.GL_NEAREST, GL11.GL_NEAREST, GL11.GL_REPEAT, GL11.GL_REPEAT);
	return textures;
}
 
Example 6
Source File: BuildingSiteRenderer.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public BuildingSiteRenderer() {
	GLIntImage img = new GLIntImage(16, 16, GL11.GL_RGBA);
	for (int y = 1; y < img.getHeight() - 1; y++)
		for (int x = 1; x < img.getWidth() - 1; x++)
			img.putPixel(x, y, 0xffffffff);
	green = new Texture(new GLIntImage[]{img}, GL11.GL_RGBA, GL11.GL_LINEAR, GL11.GL_LINEAR, GL11.GL_CLAMP, GL11.GL_CLAMP);
}
 
Example 7
Source File: Texture.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
private static int determineMipMapSize(int mipmap, int internal_format, int width, int height) {
	boolean compressed = false;
	if (Settings.getSettings().useTextureCompression()) {
		GL11.glGetTexLevelParameter(GL11.GL_TEXTURE_2D, mipmap, GL13.GL_TEXTURE_COMPRESSED, size_buffer);
		compressed = size_buffer.get(0) == GL11.GL_TRUE;
	}
	if (compressed) {
		GL11.glGetTexLevelParameter(GL11.GL_TEXTURE_2D, mipmap, GL13.GL_TEXTURE_COMPRESSED_IMAGE_SIZE, size_buffer);
		return size_buffer.get(0);
	} else {
		switch (internal_format) {
			case GL13.GL_COMPRESSED_RGB:
			case GL11.GL_RGB:
				return width*height*3;
			case GL13.GL_COMPRESSED_RGBA:
			case GL11.GL_RGBA:
				return width*height*4;
			case GL11.GL_LUMINANCE:
			case GL11.GL_ALPHA8:
			case GL11.GL_ALPHA:
			case GL13.GL_COMPRESSED_LUMINANCE:
			case GL13.GL_COMPRESSED_ALPHA:
				return width*height;
			default:
				throw new RuntimeException("0x" + Integer.toHexString(internal_format));
		}
	}
}
 
Example 8
Source File: Font.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public Font(FontInfo font_info) {
	this.key_array = font_info.getKeyMap();
	TextureFile file = new TextureFile(font_info.getTextureName(),
									   GL11.GL_RGBA,
									   GL11.GL_LINEAR,
									   GL11.GL_LINEAR,
									   GL11.GL_REPEAT,
									   GL11.GL_REPEAT);
	this.texture = (Texture)Resources.findResource(file);
	this.x_border = font_info.getBorderX();
	this.y_border = font_info.getBorderY();
	this.height = font_info.getHeight();
}
 
Example 9
Source File: GLUtils.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public static void saveTexture(int mipmap_level, String filename) {
		GL11.glGetTexLevelParameter(GL11.GL_TEXTURE_2D, mipmap_level, GL11.GL_TEXTURE_WIDTH, int_buf);
		int width = int_buf.get(0);
		GL11.glGetTexLevelParameter(GL11.GL_TEXTURE_2D, mipmap_level, GL11.GL_TEXTURE_HEIGHT, int_buf);
		int height = int_buf.get(0);
		GLImage pixel_data = new GLIntImage(width, height, GL11.GL_RGBA);
		GL11.glGetTexImage(GL11.GL_TEXTURE_2D, mipmap_level, pixel_data.getGLFormat(), pixel_data.getGLType(), pixel_data.getPixels());
//		swizzleColors(pixel_data.getPixels());
		com.oddlabs.util.Utils.flip(pixel_data.getPixels(), width*4, height);
		pixel_data.saveAsPNG(filename);
		System.gc();
	}
 
Example 10
Source File: OffscreenRenderer.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
protected OffscreenRenderer(int width, int height, boolean use_copyteximage) {
	this.width = width;
	this.height = height;
	this.use_copyteximage = use_copyteximage;
	
	if (!use_copyteximage)
		image = new GLIntImage(width, height, GL11.GL_RGBA);
	else
		image = null;
}
 
Example 11
Source File: OffscreenRenderer.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public final void dumpToFile(String filename) {
	GLIntImage image = new GLIntImage(width, height, GL11.GL_RGBA);
	GL11.glReadPixels(0, 0, image.getWidth(), image.getHeight(), image.getGLFormat(), image.getGLType(), image.getPixels());
	System.out.println("filename = " + filename);
	com.oddlabs.util.Utils.flip(image.getPixels(), image.getWidth()*4, image.getHeight());
	image.saveAsPNG(filename);
}
 
Example 12
Source File: Skin.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
private final static Texture loadTexture(String tex_file) {
	TextureFile file = new TextureFile(tex_file,
									   GL11.GL_RGBA,
									   GL11.GL_LINEAR,
									   GL11.GL_LINEAR,
									   GL11.GL_CLAMP,
									   GL11.GL_CLAMP);
	return (Texture)Resources.findResource(file);
}
 
Example 13
Source File: Icons.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
private final static Texture loadTexture(String tex_file) {
	TextureFile file = new TextureFile(tex_file,
									   GL11.GL_RGBA,
									   GL11.GL_LINEAR,
									   GL11.GL_LINEAR,
									   GL11.GL_CLAMP,
									   GL11.GL_CLAMP);
	return (Texture)Resources.findResource(file);
}
 
Example 14
Source File: TextureFile.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
public final GLImage getImage() {
		GLImage img;
/*		URL url_jpg = Utils.class.getResource(loc + ".jpg");
		if (url_jpg != null) {
			BufferedImage bi_rgb = readFile(url_jpg);
			int components = bi_rgb.getColorModel().getNumComponents();
			assert components == 1 || components == 3;
			int width = bi_rgb.getWidth();
			int height = bi_rgb.getHeight();
			byte[] data_rgb = (byte[]) bi_rgb.getRaster().getDataElements(0, 0, width, height, null);
			
			URL url_png_alpha = Utils.class.getResource(loc + "_a.png");
			byte[] data_a;
			if (url_png_alpha != null) {
				BufferedImage bi_a = readFile(url_png_alpha);
				assert bi_a.getColorModel().getNumComponents() == 1;
				assert width == bi_a.getWidth() && height == bi_a.getHeight();
				data_a = (byte[]) bi_a.getRaster().getDataElements(0, 0, width, height, null);
			} else
				data_a = null;

			ByteBuffer buf = ByteBuffer.allocateDirect(4*width*height);
			IntBuffer int_buf = buf.asIntBuffer();
			for (int i = 0; i < int_buf.capacity(); i++) {
				int r = data_rgb[i*components] & 0xff;
				int g;
				int b;
				if (components == 3) {
					g = data_rgb[i*3 + 1] & 0xff;
					b = data_rgb[i*3 + 2] & 0xff;
				} else {
					g = r;
					b = r;
				}
				
				int a;
				if (data_a != null)
					a = data_a[i] & 0xff;
				else
					a = 0xff;
				int pixel = (r << 24) | (g << 16) | (b << 8) | a;
				int_buf.put(i, pixel);
			}
			buf.rewind();
			img = new GLIntImage(width, height, buf, GL11.GL_RGBA);
		} else {*/
			Image image = Image.read(getURL());
			img = new GLIntImage(image.getWidth(), image.getHeight(), image.getPixels(), GL11.GL_RGBA);
//		}
		return img;
	}
 
Example 15
Source File: GLUtils.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
public final static GLIntImage loadAsGLImage(String location) {
	Image img = null;
	img = Image.read(com.oddlabs.util.Utils.makeURL(location));
	GLIntImage glimage = new GLIntImage(img.getWidth(), img.getHeight(), img.getPixels(), GL11.GL_RGBA);
	return glimage;
}
 
Example 16
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;
}