After you've called a loading routine and assuming that the image has been loaded correctly, you can get the width of the surface with MySDL_Surface^.w and the height with MySDL_Surface^.h. (var MySDL_Surface: PSDL_Surface should be declared somewhere in your code.) As far as I know w and h are read-only, so don't try to change the values.Originally Posted by PJP Dev
Basically you just need to write your own texture loader or use an existing one.Originally Posted by PJP Dev
For example to convert a SDL_Surface into a texture to be used with OpenGL, you can use this little function (it also scales the surfaces that are not power of 2):
[pascal]
function CreateTexture(SDL_Surface: PSDL_Surface): Integer;
var Texture: TGLuInt;
Begin
Result := -1;
if Assigned(SDL_Surface) then
begin
glGenTextures(1, @Texture);
glBindTexture(GL_TEXTURE_2D, Texture);
if SDL_Surface.format.BytesPerPixel > 3 then glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SDL_Surface^.w, SDL_Surface^.h,0, GL_RGBA, GL_UNSIGNED_BYTE, SDL_Surface^.pixels)
else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, SDL_Surface^.w, SDL_Surface^.h,0, GL_RGB, GL_UNSIGNED_BYTE, SDL_Surface^.pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if SDL_Surface.format.BytesPerPixel > 3 then gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, SDL_Surface^.w, SDL_Surface^.h, GL_RGBA, GL_UNSIGNED_BYTE, SDL_Surface^.pixels)
else gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, SDL_Surface^.w, SDL_Surface^.h, GL_RGB, GL_UNSIGNED_BYTE, SDL_Surface^.pixels);
SDL_FreeSurface(SDL_Surface);
Result := Texture;
end;
End;
...
var
MyTexture: GLuInt;
MySDL_Surface: PSDL_Surface;
begin
// SDL init and OpenGL init
glEnable(GL_TEXTURE_2D);
MySDL_Surface := IMG_Load(...);
MyTexture := CreateTexture(MySDL_Surface);
// Game Loop
while ... do
begin
glBindTexture(GL_TEXTURE_2D, Texture);
// Draw quad here
end;
end.
[/pascal]
Alternatively, you can the easySDL texture loader from DelphiGL:
http://svn.delphigl.com/websvn/filed...es.pas&rev=174
Bookmarks