Hi
I believe that this something every opengl programmer encounter initially . I am trying to render a quad as follows:
void loadGeometry()
{
//load the vertices for the floor
//make and bind the vertex array object
glGenVertexArrays(1,&gVAO);
glBindVertexArray(gVAO);
//make and bind the vertex buffer object
glGenBuffers(1,&gVBO);
glBindBuffer(GL_ARRAY_BUFFER,gVBO);
//put the quad verteices and texture coordinates into the VBO
GLfloat vertexData[] = {-20.0f,0.0f,-20.0f, 0.0f,0.0f,
20.0f,0.0f,-20.0f, 20.0f,0.0f,
20.0f,0.0f,20.0f, 20.0f,20.0f,
-20.0f,0.0f,20.0f, 0.0f,20.0f};
glBufferData(GL_ARRAY_BUFFER,sizeof(vertexData),vertexData,GL_STATIC_DRAW);
//connect the xyz of the vertexData to the "position" attribute of the vertex shader
glEnableVertexAttribArray(floorProgram->attrib("position"));
glVertexAttribPointer(floorProgram->attrib("position"),3,GL_FLOAT,GL_FALSE,5*sizeof(GLfloat),NULL);
//connect the uv coordinates to the "posTexCoord" attribute of the vertex shader
glEnableVertexAttribArray(floorProgram->attrib("posTexCoord"));
glVertexAttribPointer(floorProgram->attrib("posTexCoord"),2,GL_FLOAT,GL_TRUE,
5*sizeof(GLfloat),
(const GLvoid*)(3 * sizeof(GLfloat)));
//unbind the vertex array object
glBindVertexArray(0);
floorProgram->stopUsing();
}
And then i am rendering with the following snippet:
void render(double time)
{
static const GLfloat one = 1.0f;
glViewport(0,0,winWidth,winHeight);
glClearBufferfv(GL_COLOR,0,backgroundcolor);
glClearBufferfv(GL_DEPTH,0,&one);
//use the floor program
floorProgram->use();
//the floor texture is already bound, no need to bind it again
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,floorTex);
floorProgram->setUniform("tex",floorTex);
//send the camera matrix to the shader
floorProgram->setUniform("camera",camera->matrix());
//bind the VAO - the quad
glBindVertexArray(gVAO);
//draw the VAO - the quad
glDrawArrays(GL_TRIANGLES,0,1*2*3);
//unbind the VAO
glBindVertexArray(0);
glBindTexture(GL_TEXTURE_2D,0);
floorProgram->stopUsing();
}
I am getting blank screen, and now i am clueless. I am not sure about the parameter of the glDrawArrays(…) though. A quad could be rendered as - one face with 2 triangles and each triangle with 3 vertices. So in total we shall be dealing with 3*2 = 6 elements to be rendered. Is it right ?
The camera is initialized as follows:
camera = new tdogl::Camera();
camera->setPosition(glm::vec3(1,0,9));
camera->setViewportAspectRatio((float)winWidth/winHeight);
I have changed the camera position as well, but no sight of the quad.
Some hint is appreciated to find the quad!
Thanks