aboutsummaryrefslogtreecommitdiff
path: root/src/textures.c
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2014-03-16 20:59:02 +0100
committerraysan5 <raysan5@gmail.com>2014-03-16 20:59:02 +0100
commita68818e320cb90e2bbc772f65343cb79b78770ae (patch)
tree2e823b076a49c002645388db66cc72556536276a /src/textures.c
parent0a71a92eeb6cd05631c268005758bb9d4066f659 (diff)
downloadraylib-1.0.6.tar.gz
raylib-1.0.6.zip
Update to version 1.0.61.0.6
Check CHANGELOG for the list of changes in this release!
Diffstat (limited to 'src/textures.c')
-rw-r--r--src/textures.c68
1 files changed, 19 insertions, 49 deletions
diff --git a/src/textures.c b/src/textures.c
index c0832477..ca0492c4 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -218,37 +218,11 @@ Image LoadImageFromRES(const char *rresName, int resId)
Texture2D LoadTexture(const char *fileName)
{
Texture2D texture;
-
- int imgWidth;
- int imgHeight;
- int imgBpp;
-
- // NOTE: Using stb_image to load images (Supports: BMP, TGA, PNG, JPG, ...)
- // Force loading to 4 components (RGBA)
- byte *imgData = stbi_load(fileName, &imgWidth, &imgHeight, &imgBpp, 4);
-
- // Convert loaded data to OpenGL texture
- //----------------------------------------
- GLuint id;
- glGenTextures(1, &id); // Generate Pointer to the Texture
-
- glBindTexture(GL_TEXTURE_2D, id);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // Set texture to repead on x-axis
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // Set texture to repead on y-axis
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Filter for pixel-perfect drawing, alternative: GL_LINEAR
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Filter for pixel-perfect drawing, alternative: GL_LINEAR
-
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, imgWidth, imgHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, imgData);
-
- // NOTE: Not using mipmappings (texture for 2D drawing)
- // At this point we have the image converted to texture and uploaded to GPU
-
- stbi_image_free(imgData); // Now we can free loaded data from RAM memory
+ Image image;
- texture.glId = id;
- texture.width = imgWidth;
- texture.height = imgHeight;
+ image = LoadImage(fileName);
+ texture = CreateTexture(image);
+ UnloadImage(image);
return texture;
}
@@ -264,23 +238,6 @@ Texture2D LoadTextureFromRES(const char *rresName, int resId)
return texture;
}
-// Load an image as texture (and convert to POT with mipmaps)
-Texture2D LoadTextureEx(const char *fileName, bool createPOT, bool mipmaps)
-{
- Texture2D texture;
-
- // TODO: Load and image and convert to Power-Of-Two
- // NOTE: Conversion could be done just adding extra space to image or by scaling image
- // NOTE: If scaling image, be careful with scaling algorithm (aproximation, bilinear, bicubic...)
-
- // TODO: Generate all required mipmap levels from image and convert to testure (not that easy)
- // NOTE: If using OpenGL 1.1, the only option is doing mipmap generation on CPU side (i.e. gluBuild2DMipmaps)
- // NOTE: raylib tries to minimize external dependencies so, we are not using GLU
- // NOTE: Re-implement some function similar to gluBuild2DMipmaps (not that easy...)
-
- return texture;
-}
-
// Create a Texture2D from Image data
// NOTE: Image is not unloaded, it should be done manually...
Texture2D CreateTexture(Image image)
@@ -294,11 +251,18 @@ Texture2D CreateTexture(Image image)
glBindTexture(GL_TEXTURE_2D, id);
+ // NOTE: glTexParameteri does NOT affect texture uploading, just the way it's used!
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // Set texture to repead on x-axis
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // Set texture to repead on y-axis
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Filter for pixel-perfect drawing, alternative: GL_LINEAR
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Filter for pixel-perfect drawing, alternative: GL_LINEAR
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Filter for pixel-perfect drawing, alternative: GL_LINEAR
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Filter for pixel-perfect drawing, alternative: GL_LINEAR
+ // Trilinear filtering
+ //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // Activate use of mipmaps (must be available)
+ //glGenerateMipmap(GL_TEXTURE_2D); // OpenGL 3.3!
+
+ // Upload texture to GPU
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image.width, image.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image.pixels);
// NOTE: Not using mipmappings (texture for 2D drawing)
@@ -329,6 +293,12 @@ void DrawTexture(Texture2D texture, int posX, int posY, Color tint)
DrawTextureEx(texture, (Vector2){ (float)posX, (float)posY}, 0, 1.0f, tint);
}
+// Draw a Texture2D with position defined as Vector2
+void DrawTextureV(Texture2D texture, Vector2 position, Color tint)
+{
+ DrawTextureEx(texture, position, 0, 1.0f, tint);
+}
+
// Draw a Texture2D with extended parameters
void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint)
{