<p>Answering my own question!
The reason for this behaviour is that I forgot to activate shader program before passing matrices to it!</p>

CC BY-SA 3.0
2016-03-16T16:01:20.923Z
2016-03-16T16:01:20.923Z
videogamechef
<p>You would want to provide us with the implementation of the shaders you use, or at the very least the result of shader compilation.</p>

<p>A simple typo in a shader obviously prevents compilation and therefore successful rasterization of the object.</p>

<p>In short, check your shader !</p>

CC BY-SA 3.0
2016-03-14T18:26:00.437Z
I got the problem!
videogamechef
CC BY-SA 3.0
2016-03-14T18:22:33.197Z
2016-03-14T18:22:33.197Z
Vingt-2
<p>I was trying to draw a plane and cubes in a framebuffer but nothing is drawing in that framebuffer besides clearing it with a color.
Here's the code...</p>

<pre><code>//C++ Headers
#include&lt;cassert&gt;

//Third party Headers
#include&lt;GL/glew.h&gt;
#include&lt;GLFW/glfw3.h&gt;
#include&lt;SOIL.h&gt;

//My Headers
#include"SLMath/SLMath.hpp"
#include"GLOBALS.h"


//Author Headers
#include"Shader.h"
#include"Texture.h"


//linking libraries

#pragma comment(lib,"OpenGL32.lib")
#pragma comment(lib,"glfw3.lib")
#pragma comment(lib,"glew32.lib")
#pragma comment(lib,"SOIL.lib")


void main()
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_SAMPLES,4);

GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "fUNKY CUBE", 0, 0);
glfwMakeContextCurrent(window);

glewExperimental = GL_TRUE;
glewInit();

glfwSetKeyCallback(window, keyCallback);

assert(glGetError()!=GL_NO_ERROR);

glGenVertexArrays(1,&amp;VAOplane);
glGenVertexArrays(1,&amp;VAOcube);
glGenVertexArrays(1,&amp;VAOquad);
glGenBuffers(1,&amp;VBOplane);
glGenBuffers(1,&amp;VBOcube);
glGenBuffers(1, &amp;VBOquad);

glBindBuffer(GL_ARRAY_BUFFER,VBOplane);
glBufferData(GL_ARRAY_BUFFER,sizeof(plane),plane,GL_STATIC_DRAW);

glBindBuffer(GL_ARRAY_BUFFER,VBOcube);
glBufferData(GL_ARRAY_BUFFER,sizeof(cube),cube,GL_STATIC_DRAW);

glBindBuffer(GL_ARRAY_BUFFER,VBOquad);
glBufferData(GL_ARRAY_BUFFER,sizeof(quad),quad,GL_STATIC_DRAW);

glBindVertexArray(VAOplane);
{
    glBindBuffer(GL_ARRAY_BUFFER,VBOplane);

    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof(GLfloat)*5,(GLvoid*)(0));

    glEnableVertexAttribArray(1);
    glVertexAttribPointer(1,2,GL_FLOAT,GL_FALSE,sizeof(GLfloat)*5,(GLvoid*)(sizeof(GLfloat)*3));
}
glBindVertexArray(0);


glBindVertexArray(VAOcube);
{
    glBindBuffer(GL_ARRAY_BUFFER,VBOcube);

    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof(GLfloat)*8,(GLvoid*)(0));

    glEnableVertexAttribArray(1);
    glVertexAttribPointer(1,2,GL_FLOAT,GL_FALSE,sizeof(GLfloat)*8,(GLvoid*)(sizeof(GLfloat)*6));
}
glBindVertexArray(0);

glBindVertexArray(VAOquad);
{
    glBindBuffer(GL_ARRAY_BUFFER, VBOquad);

    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4, (GLvoid*)(0));

    glEnableVertexAttribArray(1);
    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4, (GLvoid*)(sizeof(GLfloat) * 2));
}
glBindVertexArray(0);




/*Setting up framebuffer*/

GLuint fbo;
glGenFramebuffers(1,&amp;fbo);
glBindFramebuffer(GL_FRAMEBUFFER,fbo);

//Our color attachement
GLuint texColorBuffer;
glGenTextures(1,&amp;texColorBuffer);
glBindTexture(GL_TEXTURE_2D,texColorBuffer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, WIDTH, HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_2D,0);


glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,texColorBuffer,0);

//our depth attachment
GLuint depthRenderbuffer;
glGenRenderbuffers(1,&amp;depthRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER,depthRenderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, WIDTH, HEIGHT);
glBindRenderbuffer(GL_RENDERBUFFER,0);


glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_RENDERBUFFER,depthRenderbuffer);

if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
    assert(0);


glBindFramebuffer(GL_FRAMEBUFFER,0);

glViewport(0,0,WIDTH,HEIGHT);

Texture floorTex("textures/floortexture1.jpg");
Texture cubeTex("textures/cubetexture1.jpg");

Shader shader("vs.txt","fs.txt");
Shader shader2("vs2.txt","fs2.txt");

//glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);

while(!glfwWindowShouldClose(window))
{
    glfwPollEvents();

    glBindFramebuffer(GL_FRAMEBUFFER, fbo);


    glClearColor(0.1,0.0,0.0,0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    //float radius = 5.0f;
    //cameraPos.z = cos(SLMath::radians(glfwGetTime()*30.0f))*radius;
    //cameraPos.x = sin(SLMath::radians(glfwGetTime()*30.0f))*radius;

    SLMath::Mat4 projection;
    SLMath::Mat4 view;
    SLMath::Mat4 model;

    GLint projLoc = glGetUniformLocation(shader.program,"projection");
    GLint viewLoc = glGetUniformLocation(shader.program,"view");
    GLint modelLoc = glGetUniformLocation(shader.program,"model");

    SLMath::perspective(projection,45.0f,(float)WIDTH/(float)HEIGHT,0.1f,100.0f);
    SLMath::lookAt(view,cameraPos,cameraDir,cameraUp);

    glUniformMatrix4fv(projLoc,1,GL_FALSE,projection.valuePtr());
    glUniformMatrix4fv(viewLoc,1,GL_FALSE,view.valuePtr());
    glUniformMatrix4fv(modelLoc,1,GL_FALSE,model.valuePtr());


    floorTex.bind();
    shader.Use();
    glBindVertexArray(VAOplane);
    glDrawArrays(GL_TRIANGLES,0,6);
    glBindVertexArray(0);

    cubeTex.bind();

    for(int i=0;i&lt;3;i++)
    {
        model.reset();
        SLMath::translate(model,cubePositions[i]);
        glUniformMatrix4fv(modelLoc,1,GL_FALSE,model.valuePtr());

        glBindVertexArray(VAOcube);
        glDrawArrays(GL_TRIANGLES,0,36);
        glBindVertexArray(0);

    }

    glBindFramebuffer(GL_FRAMEBUFFER,0);

    glClearColor(1.0f,1.0f,1.0f,1.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glDisable(GL_DEPTH_TEST);

    shader2.Use();
    glBindTexture(GL_TEXTURE_2D, texColorBuffer);
    glBindVertexArray(VAOquad);
    glDrawArrays(GL_TRIANGLES,0,6);
    glBindVertexArray(0);




    glfwSwapBuffers(window);
}


glDeleteBuffers(1, &amp;VBOquad);
glDeleteBuffers(1, &amp;VBOcube);
glDeleteBuffers(1,&amp;VBOplane);
glDeleteVertexArrays(1, &amp;VAOquad);
glDeleteVertexArrays(1, &amp;VAOcube);
glDeleteVertexArrays(1,&amp;VAOplane);
glfwDestroyWindow(window);
glfwTerminate();
exit(EXIT_SUCCESS);
}
</code></pre>

<p>I am getting this...</p>

<p><a href="https://i.sstatic.net/cAx72.png" rel="noreferrer"><img src="https://i.sstatic.net/cAx72.png" alt="enter image description here"></a></p>

<p>instead of this...</p>

<p><a href="https://i.sstatic.net/H3p6i.png" rel="noreferrer"><img src="https://i.sstatic.net/H3p6i.png" alt="enter image description here"></a></p>

<p>I have checked my code several times....what is wrong??</p>

CC BY-SA 3.0
2016-03-13T13:51:29.133Z
If you take a screenshot using Alt and printscreen, instead of printscreen alone, it will just copy the current window instead of the whole screen, so you can show just the relevant part of your screen.
trichoplax is on Codidact now
<opengl><glsl>
Clearing but not drawing objects
videogamechef
# Clearing but not drawing objects

(Asked by: username_0 on 2016-03-13)

I was trying to draw a plane and cubes in a framebuffer but nothing is drawing in that framebuffer besides clearing it with a color.
Here's the code...

```
//C++ Headers
#include<cassert>

//Third party Headers
#include<GL/glew.h>
#include<GLFW/glfw3.h>
#include<SOIL.h>

//My Headers
#include"SLMath/SLMath.hpp"
#include"GLOBALS.h"

//Author Headers
#include"Shader.h"
#include"Texture.h"

//linking libraries

#pragma comment(lib,"OpenGL32.lib")
#pragma comment(lib,"glfw3.lib")
#pragma comment(lib,"glew32.lib")
#pragma comment(lib,"SOIL.lib")

void main()
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_SAMPLES,4);

GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "fUNKY CUBE", 0, 0);
glfwMakeContextCurrent(window);

glewExperimental = GL_TRUE;
glewInit();

glfwSetKeyCallback(window, keyCallback);

assert(glGetError()!=GL_NO_ERROR);

glGenVertexArrays(1,&VAOplane);
glGenVertexArrays(1,&VAOcube);
glGenVertexArrays(1,&VAOquad);
glGenBuffers(1,&VBOplane);
glGenBuffers(1,&VBOcube);
glGenBuffers(1, &VBOquad);

glBindBuffer(GL_ARRAY_BUFFER,VBOplane);
glBufferData(GL_ARRAY_BUFFER,sizeof(plane),plane,GL_STATIC_DRAW);

glBindBuffer(GL_ARRAY_BUFFER,VBOcube);
glBufferData(GL_ARRAY_BUFFER,sizeof(cube),cube,GL_STATIC_DRAW);

glBindBuffer(GL_ARRAY_BUFFER,VBOquad);
glBufferData(GL_ARRAY_BUFFER,sizeof(quad),quad,GL_STATIC_DRAW);

glBindVertexArray(VAOplane);
{
    glBindBuffer(GL_ARRAY_BUFFER,VBOplane);

    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof(GLfloat)*5,(GLvoid*)(0));

    glEnableVertexAttribArray(1);
    glVertexAttribPointer(1,2,GL_FLOAT,GL_FALSE,sizeof(GLfloat)*5,(GLvoid*)(sizeof(GLfloat)*3));
}
glBindVertexArray(0);

glBindVertexArray(VAOcube);
{
    glBindBuffer(GL_ARRAY_BUFFER,VBOcube);

    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof(GLfloat)*8,(GLvoid*)(0));

    glEnableVertexAttribArray(1);
    glVertexAttribPointer(1,2,GL_FLOAT,GL_FALSE,sizeof(GLfloat)*8,(GLvoid*)(sizeof(GLfloat)*6));
}
glBindVertexArray(0);

glBindVertexArray(VAOquad);
{
    glBindBuffer(GL_ARRAY_BUFFER, VBOquad);

    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4, (GLvoid*)(0));

    glEnableVertexAttribArray(1);
    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4, (GLvoid*)(sizeof(GLfloat) * 2));
}
glBindVertexArray(0);

/*Setting up framebuffer*/

GLuint fbo;
glGenFramebuffers(1,&fbo);
glBindFramebuffer(GL_FRAMEBUFFER,fbo);

//Our color attachement
GLuint texColorBuffer;
glGenTextures(1,&texColorBuffer);
glBindTexture(GL_TEXTURE_2D,texColorBuffer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, WIDTH, HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_2D,0);

glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,texColorBuffer,0);

//our depth attachment
GLuint depthRenderbuffer;
glGenRenderbuffers(1,&depthRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER,depthRenderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, WIDTH, HEIGHT);
glBindRenderbuffer(GL_RENDERBUFFER,0);

glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_RENDERBUFFER,depthRenderbuffer);

if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
    assert(0);

glBindFramebuffer(GL_FRAMEBUFFER,0);

glViewport(0,0,WIDTH,HEIGHT);

Texture floorTex("textures/floortexture1.jpg");
Texture cubeTex("textures/cubetexture1.jpg");

Shader shader("vs.txt","fs.txt");
Shader shader2("vs2.txt","fs2.txt");

//glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);

while(!glfwWindowShouldClose(window))
{
    glfwPollEvents();

    glBindFramebuffer(GL_FRAMEBUFFER, fbo);

    glClearColor(0.1,0.0,0.0,0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    //float radius = 5.0f;
    //cameraPos.z = cos(SLMath::radians(glfwGetTime()*30.0f))*radius;
    //cameraPos.x = sin(SLMath::radians(glfwGetTime()*30.0f))*radius;

    SLMath::Mat4 projection;
    SLMath::Mat4 view;
    SLMath::Mat4 model;

    GLint projLoc = glGetUniformLocation(shader.program,"projection");
    GLint viewLoc = glGetUniformLocation(shader.program,"view");
    GLint modelLoc = glGetUniformLocation(shader.program,"model");

    SLMath::perspective(projection,45.0f,(float)WIDTH/(float)HEIGHT,0.1f,100.0f);
    SLMath::lookAt(view,cameraPos,cameraDir,cameraUp);

    glUniformMatrix4fv(projLoc,1,GL_FALSE,projection.valuePtr());
    glUniformMatrix4fv(viewLoc,1,GL_FALSE,view.valuePtr());
    glUniformMatrix4fv(modelLoc,1,GL_FALSE,model.valuePtr());

    floorTex.bind();
    shader.Use();
    glBindVertexArray(VAOplane);
    glDrawArrays(GL_TRIANGLES,0,6);
    glBindVertexArray(0);

    cubeTex.bind();

    for(int i=0;i<3;i++)
    {
        model.reset();
        SLMath::translate(model,cubePositions[i]);
        glUniformMatrix4fv(modelLoc,1,GL_FALSE,model.valuePtr());

        glBindVertexArray(VAOcube);
        glDrawArrays(GL_TRIANGLES,0,36);
        glBindVertexArray(0);

    }

    glBindFramebuffer(GL_FRAMEBUFFER,0);

    glClearColor(1.0f,1.0f,1.0f,1.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glDisable(GL_DEPTH_TEST);

    shader2.Use();
    glBindTexture(GL_TEXTURE_2D, texColorBuffer);
    glBindVertexArray(VAOquad);
    glDrawArrays(GL_TRIANGLES,0,6);
    glBindVertexArray(0);

    glfwSwapBuffers(window);
}

glDeleteBuffers(1, &VBOquad);
glDeleteBuffers(1, &VBOcube);
glDeleteBuffers(1,&VBOplane);
glDeleteVertexArrays(1, &VAOquad);
glDeleteVertexArrays(1, &VAOcube);
glDeleteVertexArrays(1,&VAOplane);
glfwDestroyWindow(window);
glfwTerminate();
exit(EXIT_SUCCESS);
}

```

I am getting this...

[![enter image description here](https://i.sstatic.net/cAx72.png)](https://i.sstatic.net/cAx72.png)

instead of this...

[![enter image description here](https://i.sstatic.net/H3p6i.png)](https://i.sstatic.net/H3p6i.png)

I have checked my code several times....what is wrong??

**Tags:** opengl, glsl

> **Comments:**
> **username_1**: If you take a screenshot using Alt and printscreen, instead of printscreen alone, it will just copy the current window instead of the whole screen, so you can show just the relevant part of your screen.  

---

## 2 answers

### Answer by username_0 on 2016-03-16. Score: 1 | Accepted answer

Answering my own question!
The reason for this behaviour is that I forgot to activate shader program before passing matrices to it!


---

### Answer by username_2 on 2016-03-14. Score: 1

You would want to provide us with the implementation of the shaders you use, or at the very least the result of shader compilation.

A simple typo in a shader obviously prevents compilation and therefore successful rasterization of the object.

In short, check your shader !

> **Comments:**
> **username_0**: I got the problem!  

---

