OpenGL-Texture to wxImage conversion

Hi there,

i want to convert a huge texture stored in my "clsBuffer"-object (see code) to a small wxImage of a given size, but somehow i don't get it.
My plan is, to use OpenGL-methods and not the wxImage-resizing-function to reduce the data to be transfered out of the graphich-memory to the main memory. So my texture is renderd offscreen (using fbo) to temporary texture ("tmpTex") in the image-resolution resolution first. Afterwards the pixeldata should be copied to the image.
The resizing itself, which is done in the fuction "Render2D" wokrs fine (the function is also used for other resizing-operations), but somehow the imagedata is not overwritten.

Here is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
void clsBuffer::RenderImage (wxImage *dst) {  

    int w = dst->GetWidth();        int h = dst->GetHeight();
    
    GLuint tmpTex;
    glGenTextures  (1, &tmpTex);
    glBindTexture  (GL_TEXTURE_2D, tmpTex);
    glTexImage2D   (GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);

    GLuint FBO=0;
    glGenFramebuffers(1, &FBO);
    glBindFramebuffer(GL_FRAMEBUFFER, FBO);

    glViewport      (0, 0, (GLint)w, (GLint)h);

    Render2D ();

    glBindTexture  (GL_TEXTURE_2D, tmpTex);
    glReadPixels   (0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, (GLuint*)(dst->GetData()));
    
    glBindFramebuffer   (GL_FRAMEBUFFER, 0);
    glActiveTexture     (GL_TEXTURE0);
    glDeleteFramebuffers(1, &FBO);
    glDeleteTextures    (1, &tmpTex);   
}


Any idea what is wrong??


Regards,
Frank
Last edited on
Topic archived. No new replies allowed.