Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Image Manipulation

Tags:

c++

image

So I have made this program for a game and need help with making it a bit more automatic.

The program takes in an image and then displays it. I'm doing this over textures in OpenGL. When I take the screenshot of the game it is usually something about 700x400. I input the height and width into my program, resize the image to 1024x1024 (making it a POT texture for better compatibility) by adding blank space (the original image stays at the top left corner and goes all the way to (700,400) and the rest is just blank; does anyone know the term for this?) and then load it into my program and adjust the corners so only the part from (0,0) to (700,400) is shown.

That's how I handle the display of the image. Now, I would like to make this automatic. So I'd take a 700x400 picture, pass it to the program which would get the image's width and height (700x400), resize it to 1024x1024 by adding blank space and then load it.

So does anyone know a C++ library capable of doing this? I would still be taking the screenshot manually though.

I am using the Simple OpenGL Image Library (SOIL) for loading the picture (.bmp) and converting it into a texture.

Thanks!

like image 357
Tuntuni Avatar asked Nov 14 '22 04:11

Tuntuni


1 Answers

You don't really have to resize by adding blank space to display image properly. In fact, it's really unefficient way to do it, especially because you store images in .bmp format.

SOIL is able to automatically add the blank space when loading textures - maybe just try to load the file as-is, without doing any operations.

From SOIL Documentation:

Can automatically rescale the image to the next largest power-of-two size

Can load rectangluar textures for GUI elements or splash screens (requires GL_ARB/EXT/NV_texture_rectangle)

Anyway, you don't have to use texture to display pixels on the screen. I presume you aren't using shaders for rendering - if it all goes through fixed pipeline, there's glDrawPixels function, which will be much simpler. Just remember to change your SOIL call to SOIL_load_image.

like image 165
Bartek Banachewicz Avatar answered Dec 18 '22 08:12

Bartek Banachewicz