Freddy
Freddy

Reputation: 2279

glfw3 - This draw call is entirely out of view frustum

I am facing a strange issue with a very small OpenGL 4.4 application.

Before we begin here are the basics.

Fragment Shader

#version 440
out vec4 color;
void main(void)
{
  color = vec4(1.0, 0.0, 0.0, 1.0);
}

Vertex Shader

#version 440
layout(location = 0) in vec2 P;
void main(void)
{
  gl_Position = vec4(P, 0.0, 1.0);
}

VBO

  GLuint vbo;
  glGenBuffers(1, &vbo);
  glBindBuffer(GL_ARRAY_BUFFER, vbo);
  constexpr std::array<GLfloat, 12> vertex = 
  {
      -1.0f,  0.0f,
      -1.0f, -1.0f,
       0.0f,  0.0f,
       0.0f,  0.0f,
      -1.0f, -1.0f,
       0.0f, -1.0f

  };
  glBufferData(GL_ARRAY_BUFFER, sizeof(vertex[0]) * vertex.size(), vertex.data(), GL_STATIC_DRAW);

VAO

GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL);

Drawing Command

glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, vertex.size());

Based on the above I am expecting to see a red box in the lower left hand side of the screen.

What I have tried

At first I thought their must be an issue with the vertex data and it being incorrect on the GPU. However, using NSight I can confirm my vertex data is making it over to the GPU correctly.

enter image description here

What really has me confused is the error message I am getting from Nsight. That my draw call is completely out of the view frustrum.

enter image description here

This has me confused because I am passing the vertex data in device normalized coordinates. The only clipping should be from the viewport which is being set when the glfw window is created.

It has been a while since working with OpenGL. I am sure their is one small thing I overlooked, but without any errors being reported I am stuck.

Upvotes: 1

Views: 131

Answers (1)

Freddy
Freddy

Reputation: 2279

Well ladies and gentlemen, it was exactly as I suspected. One small thing I forgot to do.

glEnableVertexAttribArray

I never enabled my vertex data.

Upvotes: 0

Related Questions