Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: how to scale a rgb image with opengl api

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    2

    how to scale a rgb image with opengl api

    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?
    Last edited by ccczzzlll; 08-16-2012 at 07:37 PM.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,712
    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).

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    2
    Quote Originally Posted by Alfonse Reinheart View Post
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •