• Noise drawn from texture using nuklear library

    From Valera Rozuvan@21:1/5 to All on Thu Jul 6 16:22:02 2017
    Hi All!

    I am using nuklear for GUI: https://github.com/vurtun/nuklear . I want to draw an image inside a nuklear window. The image is represented as 1D array [r, g, b, a, r, g, b, a, ...]. I create an OpenGL texture, and try to draw inside nuklear window with
    the following code:

    /* -------------------------------------- */

    // Create an image. For now all pixels are the same.
    int i = 0;
    for (unsigned int y = 0; y < HEIGHT_IMG; ++y){
    for (unsigned int x = 0; x < WIDTH_IMG; ++x){
    imageData[i] = 174;
    imageData[i + 1] = 79;
    imageData[i + 2] = 206;
    imageData[i + 3] = 255;

    i += 4;
    }
    }

    // creating a texture
    unsigned int texture = 42;
    glGenTextures(1, &texture);
    glBindTexture(GL_TEXTURE_2D, texture);

    // set necessary texture parameters
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    // allocate memory and set texture data
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, WIDTH_IMG, HEIGHT_IMG, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);

    // render texture inside current nuklear window
    myImage = nk_image_id((int)texture);
    nk_draw_image(canvas, total_space, &myImage, grid_color);

    /* ------------------------------------------------- */

    For full program listing, along with instruction on how to run this code please see https://github.com/mandelbulb-4d/mandelbulb-4d/blob/a3b9ee89a5ed3f3046204bcaa3e8a6a9c52f7a0c/src2/simple_window/drawing.cpp#L51 .

    The problem is that when I run this code, I see some random noise instead of a solid colored square. See screenshot here: https://user-images.githubusercontent.com/2273090/27911284-34ed78d6-6261-11e7-938a-f48bc9987a0a.png . Why might this be happening?

    Please help me! Any suggestions/comments are welcome.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)