Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

crazy flashing window OpenGL GLFW

Tags:

opengl

glfw

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;
}
like image 624
user4397892 Avatar asked Dec 28 '14 17:12

user4397892


People also ask

Do I need OpenGL for GLFW?

By default, the OpenGL context GLFW creates may have any version. You can require a minimum OpenGL version by setting the GLFW_CONTEXT_VERSION_MAJOR and GLFW_CONTEXT_VERSION_MINOR hints before creation. If the required minimum version is not supported on the machine, context (and window) creation fails.

What version of OpenGL does GLFW use?

Explicit creation of OpenGL contexts of version 3.0 and above on Windows and X11, including profiles and flags, is supported by GLFW 2.7 and later.

How do I close GLFW Windows?

When the user attempts to close the window, for example by clicking the close widget or using a key chord like Alt+F4, the close flag of the window is set.


1 Answers

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.

like image 148
Brett Hale Avatar answered Sep 21 '22 10:09

Brett Hale