I'm trying to make some "images" within OpenGL ES 2.0 but I'm having some problems. What I want is to build a framebuffer object, let's say one of 400x300 pixels, and then render some graphics using an orthogonal projections.

The way I create the framebuffer object I think is right. This is the vertex array which holds it:

GLfloat vertexData[] = { // X Y Z U V -0.5f, 0.5f, 0.0f, 0.0f, 0.0f, // Top-left 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, // Top-right 0.5f, -0.5f, 0.0f, 1.0f, 1.0f, // Bottom-right -0.5f, -0.5f, 0.0f, 0.0f, 1.0f // Bottom-left };

Later, I create the texture and renderbuffer with the same size (i.e. 400x300). Also, I don't really know if the previous vertexData is right, shouldn't it be using 400x300 instead 1x1 ?

Also, the problem arrives when I build the projection and view matrix:

_projection = glm::ortho(0.0f, 400.0f, 300.0f, 0.0f, 0.0f, 1.0f); _view = glm::lookAt(glm::vec3(0,0,1), glm::vec3(0,0,0), glm::vec3(0,1,0));

When I use them, I don't see anything on the screen. However when I set them to identity matrix I see my painted graphics to the framebuffer object, but of course I want to map pixel coordinates to opengl coordinates in order to draw images easily.

This is the code I use to draw the elements painted to the framebuffer object:

// Bind the framebuffer glBindFramebuffer(GL_FRAMEBUFFER, _framebufferObject); // Set viewport to size of texture map and erase previous image glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, 400, 300); // Render every GraphicComponents to the FBO for(GraphicComponent* gc : _graphicComponents) { gc->render(); } // Unbind the FBO so rendering will return to the backbuffer glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(0, 0, _screenWidth, _screenHeight);

The render method of the GraphicComponent class just draws the element. For example, for a RectangleComponent:

void RectangleComponent::render() { _shader.useProgram(); glVertexAttribPointer(_colorHandler, 3, GL_FLOAT, GL_FALSE, 0, _vertexData); glEnableVertexAttribArray(_colorHandler); glUniformMatrix4fv(_mvpHandler, 1, GL_FALSE, glm::value_ptr(_projectionMatrix * _viewMatrix * _modelMatrix)); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, _indices); }

Which works really fine when I draw it outside of my framebuffer object.

TL;DR I want to draw some elements like rectangles, texts, etc to a framebuffer object but I don't know which sizes (or vertex positions) use for my elements when they are rendered to the framebuffer object. Also, I want the elements in the framebuffer object be rendered in an orthogonal projection, so they have their opengl coordinates mapped to screen pixels and their upper-left corner at (0,0).