Remote sensing image display based on VC++ Win32+CUDA+OpenGL combination and VC++ MFC SDI+CUDA+OpenGL combination: important conclusions obtained!

1. Remote sensing image display based on VC++ Win32+CUDA+OpenGL combination

  Under this combination scheme, OpenGL is set to the following two methods during initialization, and the effect is the same

// setting mode 1 
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA);
 // setting mode 2 
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);

  The pixel data is extracted from the remote sensing image data, and the R, G, B channels can be assigned to the R, G, B three channels of the pixel data memory specified by the OpenGL pixel buffer object (PBO, Pixel Buffer Object) in turn. aisle. The following is the test code for generating pixel data for testing. In the actual remote sensing image display, this code will be replaced by the CUDA kernel function, which is used to extract the real pixel data from the remote sensing image data file.

// Create red texture pixel data 
void CRSQuickLookView::CreateTexturePixel()
{
    int aSwathLengthDownsampled = 1024 * 3 * 512;
    pPixelData =new unsigned char[aSwathLengthDownsampled];
    ZeroMemory(pPixelData,aSwathLengthDownsampled);
    for (int i = 0; i < 512; i++)
    {
        for (int j = 0; j < 1024; j++)
        {
            int offset=i*1024*3+j*3;
            pPixelData[offset] = 255 ; // red 
            pPixelData[offset + 1 ] = 0 ;
            pPixelData[offset + 2] = 0;
        }
    }
}

  Code when drawing:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);

  The GL_RGB setting in the function glTexImage2D() must be strictly consistent with the pixel field in the CreateTexturePixel() function, otherwise the displayed image will be in the shape of a flower block.

2. Remote sensing image display based on VC++ MFC SDI+CUDA+OpenGL combination

  Under this combination scheme, the OpenGL parameters are set as follows during initialization:

static PIXELFORMATDESCRIPTOR pfd = {
        sizeof(PIXELFORMATDESCRIPTOR),
        1,
        PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,            // flag 
        PFD_TYPE_RGBA,            // color mode 
        24 ,                                    // color bits 
        0 , 0 , 0 , 0 , 0 , 0 ,
         0 , 0 , 0 , 0 , 0 , 0 , 0 ,
         32 ,                                   // depth bits 
        0 ,
         0,
        PFD_MAIN_PLANE,
        0,
        0, 0, 0
    };

  It turns out that the field iPixelType of the structure PIXELFORMATDESCRIPTOR in MFC SDI is set to PFD_TYPE_RGBA, which contains the alpha channel, and the pixel domain of the specified texture is GL_RGBA or GL_RGB when the texture is subsequently drawn, and the same drawing result can be obtained, regardless of whether it contains the alpha channel or not. , and has nothing to do with the setting value of the iPixelType field in the previous structure, that is, the following two code forms are used to draw the texture, and the same effect can be obtained. The only requirement is that the GL_RGB setting in the function glTexImage2D() must be strictly consistent with the pixel field in the CreateTexturePixel() function, otherwise the displayed image will be flowery.

//方式1
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
//方式2
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325118294&siteId=291194637