• Welcome to Vampyre Imaging Library Forum. Please login or sign up.
 

Scaling of images when loaded with LoadGLTextureFromStream

Started by jdarling, 4 October 2007, 18:14:45

Previous topic - Next topic

jdarling

I noticed that when I use LoadGLTextureFromStream to load a graphic and the graphic isn't proper power of 2 the final texture is up-scaled to the next power of two.  This causes blurry images when rendering and makes sprite sheet locations all sorts of "fun".  Any chance that there is a way to have the new texture created not scale the original image and instead create a new texture that is proper power of 2 and just has empty space around it?

A picture might be worth a 1000 words in this case.  Given the following source (72x128):

The texture created by LoadGLTextureFromStream is:

I'd rather it be:
(or similar)

As when rendered with OpenGL the current version becomes blurry.

Thanks,
- Jeremy

PS: Sill loving Vampyre :)

Galfar

Yes, images that are not power of two are rescaled when creating GL textures, but only if your graphic card doesn't support non-pow2 textures (these are still not very common though).
I can add option to just copy original image to larger pow2 texture in the future.
In the meantime you can copy your sprites to pow2 images before sending them to GL like this:


uses
  ... ImagingClasses, ImagingOpenGL, ImagingUtility;
var
  Sprite, Pow2Sprite: TSingleImage;
  TexId: GLint;
begin
  // Load orig 72x128 sprite
  Sprite := TSingleImage.CreateFromFile('MySprite72x128.png');
  // Create power of 2 image
  Pow2Sprite := TSingleImage.CreateFromParams(NextPow2(Sprite.Width), NextPow2(Sprite.Height), Sprite.Format);
  // Copy orig sprite to pow2 image
  Sprite.CopyTo(0, 0, Sprite.Width, Sprite.Height, Pow2Sprite, 0, 0);
  // Create GL texture using pow2 imag as a source
  TexId := CreateGLTextureFromImage(Pow2Image.ImageDataPointer^);

  .. do stuff ..
end;



Galfar

I added option that allows creation of pow2 textures from nonpow2 images as you wanted. New code is in SVN repository.
You only need to set PasteNonPow2ImagesIntoPow2 variable to True
to enable it (it is in ImagingOpenGL.pas).
Please let me know if it works ok for you.


arthurprs

Hello gandalf, it works, but is there a way to make the "extra" region transparent ?  ???

Galfar

If you use the new PasteNonPow2ImagesIntoPow2 option it will use pixel color at [0, 0] fill to fill the whole image (like the green color in jdarling's post). So if that is transparent the extra region will be transparent too.
If you want some custom color you can use the approach shown in the code few posts above. Just fill entire Pow2Sprite image with your color.

arthurprs

good, but i have a doubt  ???

the "FillColor parameter" is of pointer type  :o
so how can i pass it as a transparent color  :-\ ???

Galfar

It is a pointer so that it can support all image data formats - it should point to actual pixel color in the same format as the image.
For A8R8G8B8 format the filling code would look like this:

var
  Color: TColor32Rec;
begin
  ....
  Color.A := 0;
  Color.R := 192;
  Color.G := 128;
  Color.B :=  64;
  FillRect(Pow2Sprite.ImageDataPointer^, 0, 0, Pow2Sprite.Width, Pow2Sprite.Height, @Color);   
  ....

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Name:
Email:

Shortcuts: ALT+S save/post or ALT+P preview

SMF spam blocked by CleanTalk