diff options
| author | raysan5 <raysan5@gmail.com> | 2013-11-30 18:12:40 +0100 |
|---|---|---|
| committer | raysan5 <raysan5@gmail.com> | 2013-11-30 18:12:40 +0100 |
| commit | 294533ccda115b5e638ab1f9219f86d73c9c4550 (patch) | |
| tree | 79231c1eba341e091dcbcb5c8182c27222af3195 /src/textures.c | |
| parent | c7220ab1b3692d81c999fcf37afdf9908d728350 (diff) | |
| download | raylib-294533ccda115b5e638ab1f9219f86d73c9c4550.tar.gz raylib-294533ccda115b5e638ab1f9219f86d73c9c4550.zip | |
Updated to version 1.0.2
Some functions added (collision detection)
Check CHANGELOG for details
Diffstat (limited to 'src/textures.c')
| -rw-r--r-- | src/textures.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/textures.c b/src/textures.c index 3ccb5358..19eb09b4 100644 --- a/src/textures.c +++ b/src/textures.c @@ -157,6 +157,36 @@ Texture2D LoadTextureEx(const char *fileName, bool createPOT, bool mipmaps) return texture; } +// Create a Texture2D from Image data +// NOTE: Image is not unloaded, it should be done manually... +Texture2D CreateTexture2D(Image image) +{ + Texture2D texture; + + // Convert image 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, image.width, image.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image.pixels); + + // NOTE: Not using mipmappings (texture for 2D drawing) + // At this point we have the image converted to texture and uploaded to GPU + + texture.glId = id; + texture.width = image.width; + texture.height = image.height; + + return texture; +} + // Unload texture from GPU memory void UnloadTexture(Texture2D texture) { |
