Delphi-Quellcode:
unit TextureManager;
interface
uses
uTextures;
type
TTextures =
Record
Textur: Cardinal;
Name:
String[32];
end;
TTextureManager =
class
constructor Create;
destructor Destroy;
override;
private
Textures:
array of TTextures;
public
function GetTextureIndex(Text:
String): integer;
procedure AddTexture(FileName, TextureName:
string;
const LoadFromResource: Boolean = FALSE);
procedure BindTexture(TextureName:
string);
end;
implementation
const
GL_TEXTURE_2D = $0DE1;
constructor TTextureManager.Create;
begin
inherited Create;
SetLength(Textures, 0);
end;
destructor TTextureManager.Destroy;
begin
// to do
inherited Destroy;
end;
procedure TTextureManager.AddTexture(FileName, TextureName:
string;
const LoadFromResource: Boolean = FALSE);
begin
Setlength(Textures, length(Textures) + 1);
LoadTexture(Filename, Textures[High(Textures)].Textur, LoadFromResource);
Textures[High(Textures)].
Name := TextureName;
end;
function TTextureManager.GetTextureIndex(Text:
String): integer;
var idx: integer;
begin
idx := 0;
while (Textures[idx].
Name <> Text)
or (idx > High(Textures))
do
inc(idx);
Result := idx;
end;
procedure TTextureManager.BindTexture(TextureName:
string);
begin
glBindTexture(GL_TEXTURE_2D, Textures[GetTextureIndex(TextureName)].Textur);
end;
END.
// End of Unit TextureManager
Zitat von
bigg:
edit: Wobei das Suchen über einen String recht langsam ist, daher nur die Konstante.
Ja, dem ist so. Deswegen wollte ich es eben nicht so wie oben machen. Nuch ich verstehe das mit den Konstanten nicht.
Wie kann ich es denn Anstellen ?
// Edit: ...da fehlte was