Page 1 of 1

Problem with Scale and OpenGL

Posted: 2007-12-31T08:18:31-07:00
by tomf
I have a little OpenGL application which uses ImageMagick for loading images. The only problem is that after scaling the image looks really strange. Without scaling it works perfectly.

I know it's no imagemagick error, because if I write the scaled version into a new file it looks ok. But maybe somebody knows what the scaling function does - because I have no idea why it doesn't work after the scaling.

My code:

Code: Select all

Magick::Image image;
image.read(Magick::Geometry(info->new_size, info->new_size), info->file_info.absoluteFilePath().toStdString());
image.scale(Magick::Geometry(info->new_size, info->new_size));

Magick::Blob blob;
image.magick("RGBA");
image.write(&blob);

image.write("c:/testtest.jpg");

glBindTexture(GL_TEXTURE_2D, info->texture_id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8 , image.columns(), image.rows(), 0, GL_BGRA, GL_UNSIGNED_BYTE, blob.data());
And here the images (first not scaled, second scaled):
Image

Re: Problem with Scale and OpenGL

Posted: 2008-01-02T19:34:26-07:00
by anthony
Are you sure that openGL can read JPEG images. Looks like you are attempting to read a raw RGB image data rather than JPEG image data you are passing it.

By the way interesting image.

PS; scaling may not be what you want. Scaling works by simply averaging rows and columns together to produce a smaller image, it is not a proper resizing of the image which uses a filter averging method to improve the final result.

see IM examples Resize for complete details.

Re: Problem with Scale and OpenGL

Posted: 2008-01-06T07:06:50-07:00
by tomf
Thx you are right.There was something wrong with the format. I changed my write to

Code: Select all

image.write(&blob, "RGBA", 8)
and now it works perfectly.