OpenGL - Exception at clear Color












0















I'm trying to open a window using glfw3, and paint the background blue. Here's my code:



#include <gladglad.h>
#include <GLFW/glfw3.h>
GLFWwindow* window;
int main( void )
{
int windowWidth = 1024;
int windowHeight = 768;
glfwInit();
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
window = glfwCreateWindow( 1024, 768, "Tutorial 14 - Render To Texture", NULL, NULL);

glfwMakeContextCurrent(window);

glfwGetFramebufferSize(window, &windowWidth, &windowHeight);
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

glfwPollEvents();
// Dark blue background
glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
return 0;
}


At glClearColor, it throws



Unhandled exception at 0x74D2CB49 in rendertotexture.exe: 0xC0000005: Access violation executing location 0x00000000.


I already tried
GLFW exception on glClearColor and glClear.
I'm using Visual Studio 2017.










share|improve this question




















  • 5





    gladLoadGL()

    – tkausl
    Nov 15 '18 at 18:47






  • 1





    "I already tried GLFW exception on glClearColor and glClear."...then where's your gladLoadGL()/gladLoadGLLoader() call?

    – genpfault
    Nov 15 '18 at 18:54











  • I removed it, when it didn't make a difference

    – Q Stollen
    Nov 15 '18 at 20:00











  • @QStollen: Did you call it after glfwMakeContextCurrent – it needs a OpenGL context bound to the current thread, in order to work.

    – datenwolf
    Nov 15 '18 at 22:28
















0















I'm trying to open a window using glfw3, and paint the background blue. Here's my code:



#include <gladglad.h>
#include <GLFW/glfw3.h>
GLFWwindow* window;
int main( void )
{
int windowWidth = 1024;
int windowHeight = 768;
glfwInit();
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
window = glfwCreateWindow( 1024, 768, "Tutorial 14 - Render To Texture", NULL, NULL);

glfwMakeContextCurrent(window);

glfwGetFramebufferSize(window, &windowWidth, &windowHeight);
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

glfwPollEvents();
// Dark blue background
glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
return 0;
}


At glClearColor, it throws



Unhandled exception at 0x74D2CB49 in rendertotexture.exe: 0xC0000005: Access violation executing location 0x00000000.


I already tried
GLFW exception on glClearColor and glClear.
I'm using Visual Studio 2017.










share|improve this question




















  • 5





    gladLoadGL()

    – tkausl
    Nov 15 '18 at 18:47






  • 1





    "I already tried GLFW exception on glClearColor and glClear."...then where's your gladLoadGL()/gladLoadGLLoader() call?

    – genpfault
    Nov 15 '18 at 18:54











  • I removed it, when it didn't make a difference

    – Q Stollen
    Nov 15 '18 at 20:00











  • @QStollen: Did you call it after glfwMakeContextCurrent – it needs a OpenGL context bound to the current thread, in order to work.

    – datenwolf
    Nov 15 '18 at 22:28














0












0








0


0






I'm trying to open a window using glfw3, and paint the background blue. Here's my code:



#include <gladglad.h>
#include <GLFW/glfw3.h>
GLFWwindow* window;
int main( void )
{
int windowWidth = 1024;
int windowHeight = 768;
glfwInit();
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
window = glfwCreateWindow( 1024, 768, "Tutorial 14 - Render To Texture", NULL, NULL);

glfwMakeContextCurrent(window);

glfwGetFramebufferSize(window, &windowWidth, &windowHeight);
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

glfwPollEvents();
// Dark blue background
glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
return 0;
}


At glClearColor, it throws



Unhandled exception at 0x74D2CB49 in rendertotexture.exe: 0xC0000005: Access violation executing location 0x00000000.


I already tried
GLFW exception on glClearColor and glClear.
I'm using Visual Studio 2017.










share|improve this question
















I'm trying to open a window using glfw3, and paint the background blue. Here's my code:



#include <gladglad.h>
#include <GLFW/glfw3.h>
GLFWwindow* window;
int main( void )
{
int windowWidth = 1024;
int windowHeight = 768;
glfwInit();
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
window = glfwCreateWindow( 1024, 768, "Tutorial 14 - Render To Texture", NULL, NULL);

glfwMakeContextCurrent(window);

glfwGetFramebufferSize(window, &windowWidth, &windowHeight);
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

glfwPollEvents();
// Dark blue background
glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
return 0;
}


At glClearColor, it throws



Unhandled exception at 0x74D2CB49 in rendertotexture.exe: 0xC0000005: Access violation executing location 0x00000000.


I already tried
GLFW exception on glClearColor and glClear.
I'm using Visual Studio 2017.







c++ exception opengl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 18:52









genpfault

42.4k953100




42.4k953100










asked Nov 15 '18 at 18:44









Q StollenQ Stollen

91




91








  • 5





    gladLoadGL()

    – tkausl
    Nov 15 '18 at 18:47






  • 1





    "I already tried GLFW exception on glClearColor and glClear."...then where's your gladLoadGL()/gladLoadGLLoader() call?

    – genpfault
    Nov 15 '18 at 18:54











  • I removed it, when it didn't make a difference

    – Q Stollen
    Nov 15 '18 at 20:00











  • @QStollen: Did you call it after glfwMakeContextCurrent – it needs a OpenGL context bound to the current thread, in order to work.

    – datenwolf
    Nov 15 '18 at 22:28














  • 5





    gladLoadGL()

    – tkausl
    Nov 15 '18 at 18:47






  • 1





    "I already tried GLFW exception on glClearColor and glClear."...then where's your gladLoadGL()/gladLoadGLLoader() call?

    – genpfault
    Nov 15 '18 at 18:54











  • I removed it, when it didn't make a difference

    – Q Stollen
    Nov 15 '18 at 20:00











  • @QStollen: Did you call it after glfwMakeContextCurrent – it needs a OpenGL context bound to the current thread, in order to work.

    – datenwolf
    Nov 15 '18 at 22:28








5




5





gladLoadGL()

– tkausl
Nov 15 '18 at 18:47





gladLoadGL()

– tkausl
Nov 15 '18 at 18:47




1




1





"I already tried GLFW exception on glClearColor and glClear."...then where's your gladLoadGL()/gladLoadGLLoader() call?

– genpfault
Nov 15 '18 at 18:54





"I already tried GLFW exception on glClearColor and glClear."...then where's your gladLoadGL()/gladLoadGLLoader() call?

– genpfault
Nov 15 '18 at 18:54













I removed it, when it didn't make a difference

– Q Stollen
Nov 15 '18 at 20:00





I removed it, when it didn't make a difference

– Q Stollen
Nov 15 '18 at 20:00













@QStollen: Did you call it after glfwMakeContextCurrent – it needs a OpenGL context bound to the current thread, in order to work.

– datenwolf
Nov 15 '18 at 22:28





@QStollen: Did you call it after glfwMakeContextCurrent – it needs a OpenGL context bound to the current thread, in order to work.

– datenwolf
Nov 15 '18 at 22:28












1 Answer
1






active

oldest

votes


















0














You need to initialize glew and call glfwSwapBuffers(window).



See: https://www.glfw.org/docs/3.0/window.html




GLFW windows are always double buffered. That means that you have two rendering buffers; a front buffer and a back buffer. The front buffer is the one being displayed and the back buffer the one you render to.



When the entire frame has been rendered, it is time to swap the back
and the front buffers in order to display what has been rendered and
begin rendering a new frame. This is done with glfwSwapBuffers.




int main(void)
{
GLFWwindow* window;

int windowWidth = 1024;
int windowHeight = 768;
glfwInit();
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
window = glfwCreateWindow(1024, 768, "Tutorial 14 - Render To Texture", NULL, NULL);

glfwMakeContextCurrent(window);

glewExperimental = true; // Needed in core profile
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEWn");
}

glfwGetFramebufferSize(window, &windowWidth, &windowHeight);
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

while (!glfwWindowShouldClose(window))
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
glfwSwapBuffers(window);
glfwPollEvents();
}

return 0;
}





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326034%2fopengl-exception-at-clear-color%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You need to initialize glew and call glfwSwapBuffers(window).



    See: https://www.glfw.org/docs/3.0/window.html




    GLFW windows are always double buffered. That means that you have two rendering buffers; a front buffer and a back buffer. The front buffer is the one being displayed and the back buffer the one you render to.



    When the entire frame has been rendered, it is time to swap the back
    and the front buffers in order to display what has been rendered and
    begin rendering a new frame. This is done with glfwSwapBuffers.




    int main(void)
    {
    GLFWwindow* window;

    int windowWidth = 1024;
    int windowHeight = 768;
    glfwInit();
    glfwWindowHint(GLFW_SAMPLES, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    window = glfwCreateWindow(1024, 768, "Tutorial 14 - Render To Texture", NULL, NULL);

    glfwMakeContextCurrent(window);

    glewExperimental = true; // Needed in core profile
    if (glewInit() != GLEW_OK) {
    fprintf(stderr, "Failed to initialize GLEWn");
    }

    glfwGetFramebufferSize(window, &windowWidth, &windowHeight);
    glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
    glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

    while (!glfwWindowShouldClose(window))
    {
    glClear(GL_COLOR_BUFFER_BIT);
    glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
    glfwSwapBuffers(window);
    glfwPollEvents();
    }

    return 0;
    }





    share|improve this answer




























      0














      You need to initialize glew and call glfwSwapBuffers(window).



      See: https://www.glfw.org/docs/3.0/window.html




      GLFW windows are always double buffered. That means that you have two rendering buffers; a front buffer and a back buffer. The front buffer is the one being displayed and the back buffer the one you render to.



      When the entire frame has been rendered, it is time to swap the back
      and the front buffers in order to display what has been rendered and
      begin rendering a new frame. This is done with glfwSwapBuffers.




      int main(void)
      {
      GLFWwindow* window;

      int windowWidth = 1024;
      int windowHeight = 768;
      glfwInit();
      glfwWindowHint(GLFW_SAMPLES, 4);
      glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
      glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
      glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
      window = glfwCreateWindow(1024, 768, "Tutorial 14 - Render To Texture", NULL, NULL);

      glfwMakeContextCurrent(window);

      glewExperimental = true; // Needed in core profile
      if (glewInit() != GLEW_OK) {
      fprintf(stderr, "Failed to initialize GLEWn");
      }

      glfwGetFramebufferSize(window, &windowWidth, &windowHeight);
      glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
      glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

      while (!glfwWindowShouldClose(window))
      {
      glClear(GL_COLOR_BUFFER_BIT);
      glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
      glfwSwapBuffers(window);
      glfwPollEvents();
      }

      return 0;
      }





      share|improve this answer


























        0












        0








        0







        You need to initialize glew and call glfwSwapBuffers(window).



        See: https://www.glfw.org/docs/3.0/window.html




        GLFW windows are always double buffered. That means that you have two rendering buffers; a front buffer and a back buffer. The front buffer is the one being displayed and the back buffer the one you render to.



        When the entire frame has been rendered, it is time to swap the back
        and the front buffers in order to display what has been rendered and
        begin rendering a new frame. This is done with glfwSwapBuffers.




        int main(void)
        {
        GLFWwindow* window;

        int windowWidth = 1024;
        int windowHeight = 768;
        glfwInit();
        glfwWindowHint(GLFW_SAMPLES, 4);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
        window = glfwCreateWindow(1024, 768, "Tutorial 14 - Render To Texture", NULL, NULL);

        glfwMakeContextCurrent(window);

        glewExperimental = true; // Needed in core profile
        if (glewInit() != GLEW_OK) {
        fprintf(stderr, "Failed to initialize GLEWn");
        }

        glfwGetFramebufferSize(window, &windowWidth, &windowHeight);
        glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
        glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

        while (!glfwWindowShouldClose(window))
        {
        glClear(GL_COLOR_BUFFER_BIT);
        glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
        glfwSwapBuffers(window);
        glfwPollEvents();
        }

        return 0;
        }





        share|improve this answer













        You need to initialize glew and call glfwSwapBuffers(window).



        See: https://www.glfw.org/docs/3.0/window.html




        GLFW windows are always double buffered. That means that you have two rendering buffers; a front buffer and a back buffer. The front buffer is the one being displayed and the back buffer the one you render to.



        When the entire frame has been rendered, it is time to swap the back
        and the front buffers in order to display what has been rendered and
        begin rendering a new frame. This is done with glfwSwapBuffers.




        int main(void)
        {
        GLFWwindow* window;

        int windowWidth = 1024;
        int windowHeight = 768;
        glfwInit();
        glfwWindowHint(GLFW_SAMPLES, 4);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
        window = glfwCreateWindow(1024, 768, "Tutorial 14 - Render To Texture", NULL, NULL);

        glfwMakeContextCurrent(window);

        glewExperimental = true; // Needed in core profile
        if (glewInit() != GLEW_OK) {
        fprintf(stderr, "Failed to initialize GLEWn");
        }

        glfwGetFramebufferSize(window, &windowWidth, &windowHeight);
        glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
        glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

        while (!glfwWindowShouldClose(window))
        {
        glClear(GL_COLOR_BUFFER_BIT);
        glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
        glfwSwapBuffers(window);
        glfwPollEvents();
        }

        return 0;
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 5:20









        AdaRaiderAdaRaider

        671113




        671113
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326034%2fopengl-exception-at-clear-color%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine