Java Code Examples for org.newdawn.slick.opengl.renderer.SGL#GL_RGB

The following examples show how to use org.newdawn.slick.opengl.renderer.SGL#GL_RGB . 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
/**
   * Get a texture from a image file
   * 
   * @param in The stream from which we can load the image
   * @param resourceName The name to give this image in the internal cache
   * @param flipped True if we should flip the image on the y-axis while loading
   * @param target The texture target we're loading this texture into
   * @param minFilter The scaling down filter
   * @param magFilter The scaling up filter
* @param transparent The colour to interpret as transparent or null if none
   * @return The texture loaded
   * @throws IOException Indicates a failure to load the image
   */
  private TextureImpl getTexture(InputStream in, 
  						  String resourceName, 
                            int target, 
                            int magFilter, 
                            int minFilter, boolean flipped, int[] transparent) throws IOException 
  { 
      // create the texture ID for this texture 
      ByteBuffer textureBuffer;
      
      LoadableImageData imageData = ImageDataFactory.getImageDataFor(resourceName);
  	textureBuffer = imageData.loadImage(new BufferedInputStream(in), flipped, transparent);

      int textureID = createTextureID(); 
      TextureImpl texture = new TextureImpl(resourceName, target, textureID); 
      // bind this texture 
      GL.glBindTexture(target, textureID); 
 
      int width;
      int height;
      int texWidth;
      int texHeight;
      
      boolean hasAlpha;
      
  	width = imageData.getWidth();
  	height = imageData.getHeight();
  	hasAlpha = imageData.getDepth() == 32;
  	
  	texture.setTextureWidth(imageData.getTexWidth());
  	texture.setTextureHeight(imageData.getTexHeight());

      texWidth = texture.getTextureWidth();
      texHeight = texture.getTextureHeight();

      IntBuffer temp = BufferUtils.createIntBuffer(16);
      GL.glGetInteger(SGL.GL_MAX_TEXTURE_SIZE, temp);
      int max = temp.get(0);
      if ((texWidth > max) || (texHeight > max)) {
      	throw new IOException("Attempt to allocate a texture to big for the current hardware");
      }
      
      int srcPixelFormat = hasAlpha ? SGL.GL_RGBA : SGL.GL_RGB;
      int componentCount = hasAlpha ? 4 : 3;
      
      texture.setWidth(width);
      texture.setHeight(height);
      texture.setAlpha(hasAlpha);

      if (holdTextureData) {
      	texture.setTextureData(srcPixelFormat, componentCount, minFilter, magFilter, textureBuffer);
      }
      
      GL.glTexParameteri(target, GL.GL_TEXTURE_MIN_FILTER, minFilter); 
      GL.glTexParameteri(target, GL.GL_TEXTURE_MAG_FILTER, magFilter); 
      
      // produce a texture from the byte buffer
      GL.glTexImage2D(target, 
                    0, 
                    dstPixelFormat, 
                    get2Fold(width), 
                    get2Fold(height), 
                    0, 
                    srcPixelFormat, 
                    SGL.GL_UNSIGNED_BYTE, 
                    textureBuffer); 
      
      return texture; 
  }
 
Example 2
/**
 * Get a texture from a image file
 * 
 * @param dataSource The image data to generate the texture from
 * @param filter The filter to use when scaling the texture
 * @return The texture created
 * @throws IOException Indicates the texture is too big for the hardware
 */
public Texture getTexture(ImageData dataSource, int filter) throws IOException
{ 
	int target = SGL.GL_TEXTURE_2D;

    ByteBuffer textureBuffer;
	textureBuffer = dataSource.getImageBufferData();
	
    // create the texture ID for this texture 
    int textureID = createTextureID(); 
    TextureImpl texture = new TextureImpl("generated:"+dataSource, target ,textureID); 
    
    int minFilter = filter;
    int magFilter = filter;
    boolean flipped = false;
    
    // bind this texture 
    GL.glBindTexture(target, textureID); 
	
    int width;
    int height;
    int texWidth;
    int texHeight;
    
    boolean hasAlpha;
	
	width = dataSource.getWidth();
	height = dataSource.getHeight();
	hasAlpha = dataSource.getDepth() == 32;
	
	texture.setTextureWidth(dataSource.getTexWidth());
	texture.setTextureHeight(dataSource.getTexHeight());

    texWidth = texture.getTextureWidth();
    texHeight = texture.getTextureHeight();
    
    int srcPixelFormat = hasAlpha ? SGL.GL_RGBA : SGL.GL_RGB;
    int componentCount = hasAlpha ? 4 : 3;
    
    texture.setWidth(width);
    texture.setHeight(height);
    texture.setAlpha(hasAlpha);
    
    IntBuffer temp = BufferUtils.createIntBuffer(16);
    GL.glGetInteger(SGL.GL_MAX_TEXTURE_SIZE, temp);
    int max = temp.get(0);
    if ((texWidth > max) || (texHeight > max)) {
    	throw new IOException("Attempt to allocate a texture to big for the current hardware");
    }

    if (holdTextureData) {
    	texture.setTextureData(srcPixelFormat, componentCount, minFilter, magFilter, textureBuffer);
    }
    
    GL.glTexParameteri(target, SGL.GL_TEXTURE_MIN_FILTER, minFilter); 
    GL.glTexParameteri(target, SGL.GL_TEXTURE_MAG_FILTER, magFilter); 
    
    // produce a texture from the byte buffer
    GL.glTexImage2D(target, 
                  0, 
                  dstPixelFormat, 
                  get2Fold(width), 
                  get2Fold(height), 
                  0, 
                  srcPixelFormat, 
                  SGL.GL_UNSIGNED_BYTE, 
                  textureBuffer); 
    
    return texture; 
}
 
Example 3
/**
 * 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;
}
 
Example 4
/**
 * Copy an area of the rendered screen into an image. The width and height
 * of the area are assumed to match that of the image
 * 
 * @param target
 *            The target image
 * @param x
 *            The x position to copy from
 * @param y
 *            The y position to copy from
 */
public void copyArea(Image target, int x, int y) {
	int format = target.getTexture().hasAlpha() ? SGL.GL_RGBA : SGL.GL_RGB;
	target.bind();
	GL.glCopyTexImage2D(SGL.GL_TEXTURE_2D, 0, format, x, screenHeight
			- (y + target.getHeight()), target.getTexture()
			.getTextureWidth(), target.getTexture().getTextureHeight(), 0);
	target.ensureInverted();
}