PDA

View Full Version : how to scale a rgb image with opengl api



ccczzzlll
08-16-2012, 03:24 PM
I am a beginner and have a src_buffer of RGB image 800x480 and dst_buffer of RGB image 720x480, want to scaler a RGB image with opengl API, here is my source code, but it doesn't work:

glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glEnable(GL_TEXTURE_2D);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 800, 480, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, src_buffer);

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
glScalef(0.9, 1.0, 1.0);
glPopMatrix();

glReadPixels(0, 0, 720, 480, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, dst_buffer);

But the data of dst_buffer is same as the data of src_buffer, could you point out where I am wrong?

Alfonse Reinheart
08-16-2012, 07:40 PM
It's not entirely the same. It only has the first 720 horizontal pixels, for example.

You gave OpenGL image data. Then you read part of that same image data back.

OpenGL isn't really for doing image scaling. That's something you could do easily enough on the CPU, and probably faster (no round-trip of copying the data to the GPU and then copying the scaled data back).

ccczzzlll
08-17-2012, 08:18 AM
It's not entirely the same. It only has the first 720 horizontal pixels, for example.

You gave OpenGL image data. Then you read part of that same image data back.

OpenGL isn't really for doing image scaling. That's something you could do easily enough on the CPU, and probably faster (no round-trip of copying the data to the GPU and then copying the scaled data back).

No, I compared all data, it is same. Actually, it will run on embedded system, CPU is too slow for this kind process and consume CPU usage.