- function TSTW_TextureManager.CreateTexture(Path: String): TSTW_TextureObject;
- var
- tex_surface: PSDL_Surface;
- texture: GLUint;
- err: GLenum;
- x, y: Integer;
- a, b: PtrUInt;
- begin
- Result := nil;
- tex_surface := IMG_Load(PChar(Path));
- if Assigned(tex_surface) then
- begin
- // Texture vertikal spiegeln
- for y := 0 to ((tex_surface^.h - 1) div 2) do
- for x := 0 to tex_surface^.w - 1 do
- begin
- a := SDL_GetPixel(tex_Surface, x, y);
- b := SDL_GetPixel(tex_Surface, x, tex_surface^.h - 1 - y);
- SDL_PutPixel(tex_Surface, x, y, b);
- SDL_PutPixel(tex_Surface, x, tex_Surface^.h - 1 - y, a);
- end;
- glGenTextures(1, @texture);
- glBindTexture(GL_TEXTURE_2D, texture);
- glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexImage2D(GL_TEXTURE_2D, 0, 4, tex_surface^.w, tex_surface^.h, 0, GL_BGRA,
- GL_UNSIGNED_BYTE, tex_surface^.pixels);
- result := TSTW_TextureObject.Create;
- result.Height := tex_surface^.h;
- result.Width := tex_surface^.w;
- result.bpp := tex_surface^.Format^.BitsPerPixel;
- result.glName := texture;
- SDL_FreeSurface(tex_surface);
- end;
- end;