OpenGL program won't display any objects?












1















An OpenGL project can't display any object anymore. I tried to remake everything from scratch but it still doesn't works.



Main Code



#include <vector>
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <imgui.h>
#include <imgui_impl_glfw_gl3.h>
#include "Loader.h"

void on_error(int error, const char* description)
{
std::cout << "GLFW error " << error << " : "" << description << """ << std::endl;
}

int main()
{
//Init glfw
glfwSetErrorCallback(on_error);
if (!glfwInit()) return -1;
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

//Init window
auto window = glfwCreateWindow(1920, 1080, "gl_Crane", NULL, NULL);
if (!window) { glfwTerminate(); return -1; }
glfwMakeContextCurrent(window);

//Init glew
glewExperimental = true;
if (glewInit() != GLEW_OK) { glfwTerminate(); return -1; }

//Some opengl options
glEnable(GL_DEPTH_TEST);
glEnable(GL_DEBUG_OUTPUT);
glDepthFunc(GL_LESS);
//glEnable(GL_CULL_FACE);

//matrices
std::vector<glm::vec3> vertices = {
{-.2f, -.2f, 0}, {0, .2f, 0}, {.2f, -.2f, 0}
};
std::vector<glm::vec3> colors = {
{1, 0, 0}, {0, 1, 0}, {0, 0, 1}
};
std::vector<GLushort> indexes = {
0, 1, 2
};

//vertexArray
GLuint vertex_array;
glGenVertexArrays(1, &vertex_array);
glBindVertexArray(vertex_array);

//vertexbuffer
GLuint vertex_buffer;
glGenBuffers(1, &vertex_buffer);
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3) * vertices.size(), vertices.data(), GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), nullptr);

//colorbuffer
GLuint color_buffer;
glGenBuffers(1, &color_buffer);
glBindBuffer(GL_ARRAY_BUFFER, color_buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3) * colors.size(), colors.data(), GL_STATIC_DRAW);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), nullptr);

//indexbuffer
GLuint index_buffer;
glGenBuffers(1, &index_buffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * indexes.size(), indexes.data(), GL_STATIC_DRAW);

glBindVertexArray(0);

//Init shader
auto shader_program = new ShaderProgram;
shader_program->initFromFiles("../Crane/simple.vert", "../Crane/simple.frag");
//shader_program->addUniform("MVP");


ImGui_ImplGlfwGL3_Init(window, true);
glfwSwapInterval(1);

while (!glfwWindowShouldClose(window))
{
ImGui_ImplGlfwGL3_NewFrame();
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);

//maj viewport
int display_w, display_h;
glfwGetFramebufferSize(window, &display_h, &display_w);
glViewport(0, 0, display_w, display_h);

//clear screen
glClearColor(.2f, .2f, .2f, 0);
glClear(GL_COLOR_BUFFER_BIT);

//draw stuff
shader_program->use();
glBindVertexArray(vertex_array);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);

//auto mvp = glm::mat4(1);
//glUniformMatrix4fv(shader_program->uniform("MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
glDrawElements(GL_TRIANGLES, indexes.size(), GL_UNSIGNED_SHORT, nullptr);

glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glBindVertexArray(0);

shader_program->disable();
ImGui::Render();
glfwSwapBuffers(window);
glfwPollEvents();
}
shader_program->disable();
ImGui_ImplGlfwGL3_Shutdown();
glfwTerminate();
return 0;
}


Fragment shader



#version 430
in vec3 fColors;
out vec4 fragColors;
void main()
{
fragColors = vec4(fColors, 1.0);
}


Vertex shader



#version 430    
layout (location = 0) in vec4 vertexPosition;
layout (location = 1) in vec3 vertexColor;
out vec3 fColors;
void main()
{
fColors = vertexColor;
gl_Position = vertexPosition;
}


Additionally, I use the shader loader from here :
r3dux shader loader










share|improve this question





























    1















    An OpenGL project can't display any object anymore. I tried to remake everything from scratch but it still doesn't works.



    Main Code



    #include <vector>
    #include <iostream>
    #include <glm/glm.hpp>
    #include <glm/gtc/type_ptr.hpp>
    #include <GL/glew.h>
    #include <GLFW/glfw3.h>
    #include <imgui.h>
    #include <imgui_impl_glfw_gl3.h>
    #include "Loader.h"

    void on_error(int error, const char* description)
    {
    std::cout << "GLFW error " << error << " : "" << description << """ << std::endl;
    }

    int main()
    {
    //Init glfw
    glfwSetErrorCallback(on_error);
    if (!glfwInit()) return -1;
    glfwWindowHint(GLFW_SAMPLES, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    //Init window
    auto window = glfwCreateWindow(1920, 1080, "gl_Crane", NULL, NULL);
    if (!window) { glfwTerminate(); return -1; }
    glfwMakeContextCurrent(window);

    //Init glew
    glewExperimental = true;
    if (glewInit() != GLEW_OK) { glfwTerminate(); return -1; }

    //Some opengl options
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_DEBUG_OUTPUT);
    glDepthFunc(GL_LESS);
    //glEnable(GL_CULL_FACE);

    //matrices
    std::vector<glm::vec3> vertices = {
    {-.2f, -.2f, 0}, {0, .2f, 0}, {.2f, -.2f, 0}
    };
    std::vector<glm::vec3> colors = {
    {1, 0, 0}, {0, 1, 0}, {0, 0, 1}
    };
    std::vector<GLushort> indexes = {
    0, 1, 2
    };

    //vertexArray
    GLuint vertex_array;
    glGenVertexArrays(1, &vertex_array);
    glBindVertexArray(vertex_array);

    //vertexbuffer
    GLuint vertex_buffer;
    glGenBuffers(1, &vertex_buffer);
    glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3) * vertices.size(), vertices.data(), GL_STATIC_DRAW);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), nullptr);

    //colorbuffer
    GLuint color_buffer;
    glGenBuffers(1, &color_buffer);
    glBindBuffer(GL_ARRAY_BUFFER, color_buffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3) * colors.size(), colors.data(), GL_STATIC_DRAW);
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), nullptr);

    //indexbuffer
    GLuint index_buffer;
    glGenBuffers(1, &index_buffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * indexes.size(), indexes.data(), GL_STATIC_DRAW);

    glBindVertexArray(0);

    //Init shader
    auto shader_program = new ShaderProgram;
    shader_program->initFromFiles("../Crane/simple.vert", "../Crane/simple.frag");
    //shader_program->addUniform("MVP");


    ImGui_ImplGlfwGL3_Init(window, true);
    glfwSwapInterval(1);

    while (!glfwWindowShouldClose(window))
    {
    ImGui_ImplGlfwGL3_NewFrame();
    ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);

    //maj viewport
    int display_w, display_h;
    glfwGetFramebufferSize(window, &display_h, &display_w);
    glViewport(0, 0, display_w, display_h);

    //clear screen
    glClearColor(.2f, .2f, .2f, 0);
    glClear(GL_COLOR_BUFFER_BIT);

    //draw stuff
    shader_program->use();
    glBindVertexArray(vertex_array);
    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);

    //auto mvp = glm::mat4(1);
    //glUniformMatrix4fv(shader_program->uniform("MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
    glDrawElements(GL_TRIANGLES, indexes.size(), GL_UNSIGNED_SHORT, nullptr);

    glDisableVertexAttribArray(0);
    glDisableVertexAttribArray(1);
    glBindVertexArray(0);

    shader_program->disable();
    ImGui::Render();
    glfwSwapBuffers(window);
    glfwPollEvents();
    }
    shader_program->disable();
    ImGui_ImplGlfwGL3_Shutdown();
    glfwTerminate();
    return 0;
    }


    Fragment shader



    #version 430
    in vec3 fColors;
    out vec4 fragColors;
    void main()
    {
    fragColors = vec4(fColors, 1.0);
    }


    Vertex shader



    #version 430    
    layout (location = 0) in vec4 vertexPosition;
    layout (location = 1) in vec3 vertexColor;
    out vec3 fColors;
    void main()
    {
    fColors = vertexColor;
    gl_Position = vertexPosition;
    }


    Additionally, I use the shader loader from here :
    r3dux shader loader










    share|improve this question



























      1












      1








      1








      An OpenGL project can't display any object anymore. I tried to remake everything from scratch but it still doesn't works.



      Main Code



      #include <vector>
      #include <iostream>
      #include <glm/glm.hpp>
      #include <glm/gtc/type_ptr.hpp>
      #include <GL/glew.h>
      #include <GLFW/glfw3.h>
      #include <imgui.h>
      #include <imgui_impl_glfw_gl3.h>
      #include "Loader.h"

      void on_error(int error, const char* description)
      {
      std::cout << "GLFW error " << error << " : "" << description << """ << std::endl;
      }

      int main()
      {
      //Init glfw
      glfwSetErrorCallback(on_error);
      if (!glfwInit()) return -1;
      glfwWindowHint(GLFW_SAMPLES, 4);
      glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
      glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
      glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

      //Init window
      auto window = glfwCreateWindow(1920, 1080, "gl_Crane", NULL, NULL);
      if (!window) { glfwTerminate(); return -1; }
      glfwMakeContextCurrent(window);

      //Init glew
      glewExperimental = true;
      if (glewInit() != GLEW_OK) { glfwTerminate(); return -1; }

      //Some opengl options
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_DEBUG_OUTPUT);
      glDepthFunc(GL_LESS);
      //glEnable(GL_CULL_FACE);

      //matrices
      std::vector<glm::vec3> vertices = {
      {-.2f, -.2f, 0}, {0, .2f, 0}, {.2f, -.2f, 0}
      };
      std::vector<glm::vec3> colors = {
      {1, 0, 0}, {0, 1, 0}, {0, 0, 1}
      };
      std::vector<GLushort> indexes = {
      0, 1, 2
      };

      //vertexArray
      GLuint vertex_array;
      glGenVertexArrays(1, &vertex_array);
      glBindVertexArray(vertex_array);

      //vertexbuffer
      GLuint vertex_buffer;
      glGenBuffers(1, &vertex_buffer);
      glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
      glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3) * vertices.size(), vertices.data(), GL_STATIC_DRAW);
      glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), nullptr);

      //colorbuffer
      GLuint color_buffer;
      glGenBuffers(1, &color_buffer);
      glBindBuffer(GL_ARRAY_BUFFER, color_buffer);
      glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3) * colors.size(), colors.data(), GL_STATIC_DRAW);
      glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), nullptr);

      //indexbuffer
      GLuint index_buffer;
      glGenBuffers(1, &index_buffer);
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer);
      glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * indexes.size(), indexes.data(), GL_STATIC_DRAW);

      glBindVertexArray(0);

      //Init shader
      auto shader_program = new ShaderProgram;
      shader_program->initFromFiles("../Crane/simple.vert", "../Crane/simple.frag");
      //shader_program->addUniform("MVP");


      ImGui_ImplGlfwGL3_Init(window, true);
      glfwSwapInterval(1);

      while (!glfwWindowShouldClose(window))
      {
      ImGui_ImplGlfwGL3_NewFrame();
      ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);

      //maj viewport
      int display_w, display_h;
      glfwGetFramebufferSize(window, &display_h, &display_w);
      glViewport(0, 0, display_w, display_h);

      //clear screen
      glClearColor(.2f, .2f, .2f, 0);
      glClear(GL_COLOR_BUFFER_BIT);

      //draw stuff
      shader_program->use();
      glBindVertexArray(vertex_array);
      glEnableVertexAttribArray(0);
      glEnableVertexAttribArray(1);

      //auto mvp = glm::mat4(1);
      //glUniformMatrix4fv(shader_program->uniform("MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
      glDrawElements(GL_TRIANGLES, indexes.size(), GL_UNSIGNED_SHORT, nullptr);

      glDisableVertexAttribArray(0);
      glDisableVertexAttribArray(1);
      glBindVertexArray(0);

      shader_program->disable();
      ImGui::Render();
      glfwSwapBuffers(window);
      glfwPollEvents();
      }
      shader_program->disable();
      ImGui_ImplGlfwGL3_Shutdown();
      glfwTerminate();
      return 0;
      }


      Fragment shader



      #version 430
      in vec3 fColors;
      out vec4 fragColors;
      void main()
      {
      fragColors = vec4(fColors, 1.0);
      }


      Vertex shader



      #version 430    
      layout (location = 0) in vec4 vertexPosition;
      layout (location = 1) in vec3 vertexColor;
      out vec3 fColors;
      void main()
      {
      fColors = vertexColor;
      gl_Position = vertexPosition;
      }


      Additionally, I use the shader loader from here :
      r3dux shader loader










      share|improve this question
















      An OpenGL project can't display any object anymore. I tried to remake everything from scratch but it still doesn't works.



      Main Code



      #include <vector>
      #include <iostream>
      #include <glm/glm.hpp>
      #include <glm/gtc/type_ptr.hpp>
      #include <GL/glew.h>
      #include <GLFW/glfw3.h>
      #include <imgui.h>
      #include <imgui_impl_glfw_gl3.h>
      #include "Loader.h"

      void on_error(int error, const char* description)
      {
      std::cout << "GLFW error " << error << " : "" << description << """ << std::endl;
      }

      int main()
      {
      //Init glfw
      glfwSetErrorCallback(on_error);
      if (!glfwInit()) return -1;
      glfwWindowHint(GLFW_SAMPLES, 4);
      glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
      glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
      glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

      //Init window
      auto window = glfwCreateWindow(1920, 1080, "gl_Crane", NULL, NULL);
      if (!window) { glfwTerminate(); return -1; }
      glfwMakeContextCurrent(window);

      //Init glew
      glewExperimental = true;
      if (glewInit() != GLEW_OK) { glfwTerminate(); return -1; }

      //Some opengl options
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_DEBUG_OUTPUT);
      glDepthFunc(GL_LESS);
      //glEnable(GL_CULL_FACE);

      //matrices
      std::vector<glm::vec3> vertices = {
      {-.2f, -.2f, 0}, {0, .2f, 0}, {.2f, -.2f, 0}
      };
      std::vector<glm::vec3> colors = {
      {1, 0, 0}, {0, 1, 0}, {0, 0, 1}
      };
      std::vector<GLushort> indexes = {
      0, 1, 2
      };

      //vertexArray
      GLuint vertex_array;
      glGenVertexArrays(1, &vertex_array);
      glBindVertexArray(vertex_array);

      //vertexbuffer
      GLuint vertex_buffer;
      glGenBuffers(1, &vertex_buffer);
      glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
      glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3) * vertices.size(), vertices.data(), GL_STATIC_DRAW);
      glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), nullptr);

      //colorbuffer
      GLuint color_buffer;
      glGenBuffers(1, &color_buffer);
      glBindBuffer(GL_ARRAY_BUFFER, color_buffer);
      glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3) * colors.size(), colors.data(), GL_STATIC_DRAW);
      glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), nullptr);

      //indexbuffer
      GLuint index_buffer;
      glGenBuffers(1, &index_buffer);
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer);
      glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * indexes.size(), indexes.data(), GL_STATIC_DRAW);

      glBindVertexArray(0);

      //Init shader
      auto shader_program = new ShaderProgram;
      shader_program->initFromFiles("../Crane/simple.vert", "../Crane/simple.frag");
      //shader_program->addUniform("MVP");


      ImGui_ImplGlfwGL3_Init(window, true);
      glfwSwapInterval(1);

      while (!glfwWindowShouldClose(window))
      {
      ImGui_ImplGlfwGL3_NewFrame();
      ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);

      //maj viewport
      int display_w, display_h;
      glfwGetFramebufferSize(window, &display_h, &display_w);
      glViewport(0, 0, display_w, display_h);

      //clear screen
      glClearColor(.2f, .2f, .2f, 0);
      glClear(GL_COLOR_BUFFER_BIT);

      //draw stuff
      shader_program->use();
      glBindVertexArray(vertex_array);
      glEnableVertexAttribArray(0);
      glEnableVertexAttribArray(1);

      //auto mvp = glm::mat4(1);
      //glUniformMatrix4fv(shader_program->uniform("MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
      glDrawElements(GL_TRIANGLES, indexes.size(), GL_UNSIGNED_SHORT, nullptr);

      glDisableVertexAttribArray(0);
      glDisableVertexAttribArray(1);
      glBindVertexArray(0);

      shader_program->disable();
      ImGui::Render();
      glfwSwapBuffers(window);
      glfwPollEvents();
      }
      shader_program->disable();
      ImGui_ImplGlfwGL3_Shutdown();
      glfwTerminate();
      return 0;
      }


      Fragment shader



      #version 430
      in vec3 fColors;
      out vec4 fragColors;
      void main()
      {
      fragColors = vec4(fColors, 1.0);
      }


      Vertex shader



      #version 430    
      layout (location = 0) in vec4 vertexPosition;
      layout (location = 1) in vec3 vertexColor;
      out vec3 fColors;
      void main()
      {
      fColors = vertexColor;
      gl_Position = vertexPosition;
      }


      Additionally, I use the shader loader from here :
      r3dux shader loader







      c++ opengl glfw glm-math






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 1:05









      genpfault

      41.9k95398




      41.9k95398










      asked Nov 13 '18 at 23:26









      gaspard thiriongaspard thirion

      82




      82
























          1 Answer
          1






          active

          oldest

          votes


















          4














          In your program the Depth Test (glEnable(GL_DEPTH_TEST)).

          The depth of a fragment is stored in a separate buffer. This buffer has to be cleared too, at the begin of every frame, as you do it with the color buffer. See glClear:



          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


          Of course, if you would disable the depth test, then you would "see" the triangle, too.






          share|improve this answer
























          • I got the same answer from another source as well and it is correct. Thanks you :)

            – gaspard thirion
            Nov 14 '18 at 6:59











          • @gaspardthirion You're welcome.

            – Rabbid76
            Nov 14 '18 at 7:02











          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%2f53290996%2fopengl-program-wont-display-any-objects%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









          4














          In your program the Depth Test (glEnable(GL_DEPTH_TEST)).

          The depth of a fragment is stored in a separate buffer. This buffer has to be cleared too, at the begin of every frame, as you do it with the color buffer. See glClear:



          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


          Of course, if you would disable the depth test, then you would "see" the triangle, too.






          share|improve this answer
























          • I got the same answer from another source as well and it is correct. Thanks you :)

            – gaspard thirion
            Nov 14 '18 at 6:59











          • @gaspardthirion You're welcome.

            – Rabbid76
            Nov 14 '18 at 7:02
















          4














          In your program the Depth Test (glEnable(GL_DEPTH_TEST)).

          The depth of a fragment is stored in a separate buffer. This buffer has to be cleared too, at the begin of every frame, as you do it with the color buffer. See glClear:



          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


          Of course, if you would disable the depth test, then you would "see" the triangle, too.






          share|improve this answer
























          • I got the same answer from another source as well and it is correct. Thanks you :)

            – gaspard thirion
            Nov 14 '18 at 6:59











          • @gaspardthirion You're welcome.

            – Rabbid76
            Nov 14 '18 at 7:02














          4












          4








          4







          In your program the Depth Test (glEnable(GL_DEPTH_TEST)).

          The depth of a fragment is stored in a separate buffer. This buffer has to be cleared too, at the begin of every frame, as you do it with the color buffer. See glClear:



          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


          Of course, if you would disable the depth test, then you would "see" the triangle, too.






          share|improve this answer













          In your program the Depth Test (glEnable(GL_DEPTH_TEST)).

          The depth of a fragment is stored in a separate buffer. This buffer has to be cleared too, at the begin of every frame, as you do it with the color buffer. See glClear:



          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


          Of course, if you would disable the depth test, then you would "see" the triangle, too.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 6:03









          Rabbid76Rabbid76

          35.8k113247




          35.8k113247













          • I got the same answer from another source as well and it is correct. Thanks you :)

            – gaspard thirion
            Nov 14 '18 at 6:59











          • @gaspardthirion You're welcome.

            – Rabbid76
            Nov 14 '18 at 7:02



















          • I got the same answer from another source as well and it is correct. Thanks you :)

            – gaspard thirion
            Nov 14 '18 at 6:59











          • @gaspardthirion You're welcome.

            – Rabbid76
            Nov 14 '18 at 7:02

















          I got the same answer from another source as well and it is correct. Thanks you :)

          – gaspard thirion
          Nov 14 '18 at 6:59





          I got the same answer from another source as well and it is correct. Thanks you :)

          – gaspard thirion
          Nov 14 '18 at 6:59













          @gaspardthirion You're welcome.

          – Rabbid76
          Nov 14 '18 at 7:02





          @gaspardthirion You're welcome.

          – Rabbid76
          Nov 14 '18 at 7:02


















          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%2f53290996%2fopengl-program-wont-display-any-objects%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

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python