Added a dynamic array.
This commit is contained in:
		@@ -7,23 +7,51 @@
 | 
			
		||||
 | 
			
		||||
#include "image.h"
 | 
			
		||||
 | 
			
		||||
void imageInit(image_t *image, texture_t *texture) {
 | 
			
		||||
void imageInit(image_t *image) {
 | 
			
		||||
  image->quad.verticeCount = -1;
 | 
			
		||||
  imageSetTexture(image, texture);
 | 
			
		||||
  image->width = 1;
 | 
			
		||||
  image->height = 1;
 | 
			
		||||
  imageSetTexture(image, NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void imageSetTexture(image_t *image, texture_t *texture) {
 | 
			
		||||
  imageSetTextureAndCrop(image, texture,
 | 
			
		||||
    0, 0,
 | 
			
		||||
    texture == NULL ? 0 : (float)texture->width,
 | 
			
		||||
    texture == NULL ? 0 : (float)texture->height
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void imageSetTextureAndCrop(image_t *image, texture_t *texture,
 | 
			
		||||
  float x, float y, float width, float height
 | 
			
		||||
) {
 | 
			
		||||
  float u0, u1, v0, v1;
 | 
			
		||||
  if(image->quad.verticeCount != -1) {
 | 
			
		||||
    primitiveDispose(&image->quad);
 | 
			
		||||
    image->quad.verticeCount = -1;
 | 
			
		||||
  }
 | 
			
		||||
  if(texture == NULL) return;
 | 
			
		||||
 | 
			
		||||
  u0 = x / texture->width;
 | 
			
		||||
  u1 = u0 + (width / texture->width);
 | 
			
		||||
  v0 = y / texture->height;
 | 
			
		||||
  v1 = v0 + (height / texture->height);
 | 
			
		||||
  
 | 
			
		||||
  image->texture = texture;
 | 
			
		||||
  quadInit(&image->quad, 0, 0,0,0,0, texture->width,texture->height,1,1);
 | 
			
		||||
  quadInit(&image->quad, 0,
 | 
			
		||||
    0,0,u0,v0,
 | 
			
		||||
    1,1,u1,v1
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void imageRender(image_t *image, shader_t *shader, float x, float y) {
 | 
			
		||||
  shaderUsePosition(shader, x, y, 0, 0, 0, 0);
 | 
			
		||||
  if(image->texture == NULL) return;
 | 
			
		||||
  shaderUsePositionAndScale(shader,
 | 
			
		||||
    x,y,0,
 | 
			
		||||
    0,0,0,
 | 
			
		||||
    image->width, image->height, 1
 | 
			
		||||
  );
 | 
			
		||||
  shaderUseTexture(shader, image->texture);
 | 
			
		||||
  primitiveDraw(&image->quad, 0, -1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -15,9 +15,8 @@
 | 
			
		||||
 * Initialize an image.
 | 
			
		||||
 * 
 | 
			
		||||
 * @param image Image to initialize.
 | 
			
		||||
 * @param texture Texture to use for initialization.
 | 
			
		||||
 */
 | 
			
		||||
void imageInit(image_t *image, texture_t *texture);
 | 
			
		||||
void imageInit(image_t *image);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Set the texture for an image. This will also initialize the underlying quad.
 | 
			
		||||
@@ -27,6 +26,21 @@ void imageInit(image_t *image, texture_t *texture);
 | 
			
		||||
 */
 | 
			
		||||
void imageSetTexture(image_t *image, texture_t *texture);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Set the texture for an image. This will also initialize the underlying quad.
 | 
			
		||||
 * Also allows cropping of the texture image.
 | 
			
		||||
 * 
 | 
			
		||||
 * @param image Image to set the texture for.
 | 
			
		||||
 * @param texture Texture to use.
 | 
			
		||||
 * @param x X position of the crop.
 | 
			
		||||
 * @param y Y position of the crop.
 | 
			
		||||
 * @param width Width of the crop.
 | 
			
		||||
 * @param height Height of the crop.
 | 
			
		||||
 */
 | 
			
		||||
void imageSetTextureAndCrop(image_t *image, texture_t *texture,
 | 
			
		||||
  float x, float y, float width, float height
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Render an image
 | 
			
		||||
 * 
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user