Permalink
Browse files

remove devil

  • Loading branch information...
Dav1dde committed Mar 4, 2014
1 parent 400ff8e commit 0ba68673a1eb5d0d089c7868889288e014d44ed5
Showing with 56 additions and 64 deletions.
  1. +6 −3 README.md
  2. +6 −4 glamour/gl.d
  3. +44 −57 glamour/texture.d
@@ -8,16 +8,19 @@ glamour
*Glamour* supports these `-version` switches:
* `-version=gl3n` – Adds gl3n support to glamour (you can pass gl3n vectors and matrices directly as uniform).
* `-version=Derelict3` – Uses Derelict3 instead of Derelict2 for `glamour.gl`.
* `-version=glad` – Uses [glad](https://github.com/Dav1dde/glad) for `glamour.gl`.
* `-version=Derelict2` – Uses Derelict2 for `glamour.gl`.
* `-version=Derelict3` – Uses Derelict3 for `glamour.gl`.
* `-version=stb` – Uses `stb_image` to load textures from images.
* `-version=SDLImage` - Uses the `SDL` to load textures from images, this requires `Derelict2` or `Derelict3`.
* `-version=SDLImage2` - Uses the `SDL` to load textures from images, this requires `DerelictSDL2`.
* `-version=SDLImage` - Uses the `SDL` to load textures from images, this requires `DerelictSDL`.1
To build glamour I recommend you to use the `Makefile`:
```
# to build with stb_image
wget -O stb_image.d https://bitbucket.org/dav1d/gl-utils/raw/tip/stb_image/stb_image.d
make DCFLAGS+="-version=Derelict3 -version=stb -version=gl3n `pkg-config --libs --cflags gl3n`"
make DCFLAGS+="-version=glad -version=stb -version=gl3n `pkg-config --libs --cflags gl3n`"
# installing
make install
@@ -6,11 +6,13 @@ If glamour gets compiled with Derelict3, you can not load textures from images w
module glamour.gl;
version(Derelict3) {
public import derelict.opengl3.gl3;
} else version(glad) {
version(glad) {
public import glad.gl.gl;
} else {
} else version(Derelict3) {
public import derelict.opengl3.gl3;
} else version(Derelict2) {
public import derelict.opengl.gl;
public import derelict.opengl.glext;
} else {
static assert(false, "Requires at least \"glad\", \"Derelict2\" or \"Derelict3\", via -version");
}
@@ -11,18 +11,12 @@ private {
version(stb) {
import stb_image : stbi_load, stbi_image_free;
} else version(SDLImage2) {
import derelict.sdl2.sdl;
import derelict.sdl2.image;
} else version(SDLImage) {
version (Derelict3) {
import derelict.sdl2.sdl;
import derelict.sdl2.image;
} else {
import derelict.sdl.sdl;
import derelict.sdl.image;
}
} else {
import derelict.devil.il : ILuint, ilGenImages, ilBindImage, ilLoadImage, ilConvertImage,
ilGetData, ilGetInteger, IL_RGB, IL_UNSIGNED_BYTE,
IL_IMAGE_FORMAT, IL_IMAGE_TYPE, IL_IMAGE_WIDTH, IL_IMAGE_HEIGHT;
import derelict.sdl.sdl;
import derelict.sdl.image;
}
import glamour.util : glenum2size, checkgl;
@@ -272,15 +266,15 @@ class Texture2D : ITexture {
}
}
/// Loads an image and afterwards loads it into a Texture2D struct.
/// Image can be loaded by means of DevIL, stb and SDLImage. To select
/// specific way use versions stb and SDLImage. DevIL is used by default.
///
/// $(RED DevIL/SDLImage must be loaded and initialized manually!)
static Texture2D from_image(string filename) {
auto tex = new Texture2D();
version(stb) {
/// Loads an image and afterwards loads it into a Texture2D struct.
/// Image can be loaded by stb and SDLImage. To select
/// specific way use versions stb, SDLImage2 (SDL2) or SDLImage (SDL1).
///
/// $(RED SDLImage must be loaded and initialized manually!)
static Texture2D from_image(string filename) {
auto tex = new Texture2D();
version(stb) {
int x;
int y;
int comp;
@@ -299,60 +293,53 @@ class Texture2D : ITexture {
}
tex.set_data(data, image_format, x, y, image_format, GL_UNSIGNED_BYTE);
} else version (SDLImage) {
return tex;
}
} else version (SDLImage) {
static Texture2D from_image(string filename) {
auto tex = new Texture2D();
// make sure the texture has the right side up
//thanks to tito http://stackoverflow.com/questions/5862097/sdl-opengl-screenshot-is-black
SDL_Surface* flip(SDL_Surface* surface) {
SDL_Surface* result = SDL_CreateRGBSurface(surface.flags, surface.w, surface.h,
surface.format.BytesPerPixel * 8, surface.format.Rmask, surface.format.Gmask,
surface.format.Bmask, surface.format.Amask);
ubyte* pixels = cast(ubyte*) surface.pixels;
ubyte* rpixels = cast(ubyte*) result.pixels;
//thanks to tito http://stackoverflow.com/questions/5862097/sdl-opengl-screenshot-is-black
SDL_Surface* flip(SDL_Surface* surface) {
SDL_Surface* result = SDL_CreateRGBSurface(surface.flags, surface.w, surface.h,
surface.format.BytesPerPixel * 8, surface.format.Rmask, surface.format.Gmask,
surface.format.Bmask, surface.format.Amask);
ubyte* pixels = cast(ubyte*) surface.pixels;
ubyte* rpixels = cast(ubyte*) result.pixels;
uint pitch = surface.pitch;
uint pxlength = pitch * surface.h;
assert(result != null);
uint pxlength = pitch * surface.h;
for(uint line = 0; line < surface.h; ++line) {
uint pos = line * pitch;
rpixels[pos..pos+pitch] = pixels[(pxlength-pos)-pitch..pxlength-pos];
}
assert(result != null);
return result;
for(uint line = 0; line < surface.h; ++line) {
uint pos = line * pitch;
rpixels[pos..pos+pitch] = pixels[(pxlength-pos)-pitch..pxlength-pos];
}
return result;
}
auto surface = IMG_Load(filename.toStringz());
enforce(surface, new TextureException("Error loading image " ~ filename ~ ": " ~ to!string(SDL_GetError())));
scope(exit) SDL_FreeSurface(surface);
enforce(surface.format.BytesPerPixel == 3 || surface.format.BytesPerPixel == 4, "With SDLImage Glamour supports loading images only with 3 or 4 bytes per pixel format.");
auto image_format = GL_RGB;
if (surface.format.BytesPerPixel == 4) {
image_format = GL_RGBA;
image_format = GL_RGBA;
}
auto flipped = flip(surface);
tex.set_data(flipped.pixels, image_format, surface.w, surface.h, image_format, GL_UNSIGNED_BYTE);
SDL_FreeSurface(flipped);
} else {
/// DevIl is default choice
ILuint id;
ilGenImages(1, &id);
scope(exit) ilDeleteImage(1, id);
if(!ilLoadImage(toStringz(filename))) {
throw new TextureException("Unable to load image: " ~ filename);
}
tex.set_data(ilGetData(), ilGetInteger(IL_IMAGE_FORMAT),
ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT),
ilGetInteger(IL_IMAGE_FORMAT), ilGetInteger(IL_IMAGE_TYPE));
}
return tex;
return tex;
}
}
}

0 comments on commit 0ba6867

Please sign in to comment.