crazy flashing window OpenGL GLFW
Asked Answered
F

1

7

I have completed the following video https://www.youtube.com/watch?v=shpdt6hCsT4 however, my hello world window looked like this: http://s1303.photobucket.com/user/eskimo___/media/screenshot_124_zps890ae561.jpg.html any ideas where I've gone wrong? Im using osx yosemite with the latest GLFW cheers


as requested:

my project folder is comprised of 3 files which were made as part of the process using the terminal:

  1. main.cpp(C++ source code)
  2. Makefile(txt)
  3. test(Unix Executable File)

i've set up the glfw3 library on my mac using homebrew.

Main.cpp, which is what is run to produce the undesired effect in the window pictured, is comprised of the example code at GLFW's documentation part of the website:

include <GLFW/glfw3.h>

int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}
Feckless answered 28/12, 2014 at 17:26 Comment(2)
Nobody can guess what is wrong, just from that screenshot. Please provide the (minimal) necessary code to reproduce this.Jonellejones
Hi Derhass, ive amended accordingly, though unfortunately I couldnt quite manage to put the code in a blockFeckless
C
15

Insert glClear(GL_COLOR_BUFFER_BIT) prior to glfwSwapBuffers - it's basically updating from uninitialized 'framebuffer' memory, which the GL implementation has probably used for other purposes, like backing store, textures, etc., in the Quartz compositor.

Think of it as like a call to malloc; the memory isn't required to be initialized or zeroed.

Cowart answered 28/12, 2014 at 18:28 Comment(2)
Cheers mate that worked perfectly; the terminal even reminded me to append the expression with a semi-colon which was not a problem at all.Feckless
To my very limited knowledge, theres an offscreen buffer(back), which the visible window buffer(front) copies from to display the final result; Does the expression refer to the latter?Feckless

© 2022 - 2024 — McMap. All rights reserved.