<div dir="ltr">Hi Brian,<div><br></div><div>Currently I am unable to view anything the render using glsl shader.</div><div>I have tried rendering a simple triangle in immediate mode and it renders fine(off-screen).</div><div>But not able to clear background color.</div><div><br></div><div>My renderScene code for Immediate mode looks something like this:</div><div><br></div><div><div><span class="" style="white-space:pre">   </span>glClear(GL_COLOR_BUFFER_BIT);</div><div><span class="" style="white-space:pre">      </span>glClear(GL_DEPTH_BUFFER_BIT);</div><div><span class="" style="white-space:pre">      </span>glClearColor(0.0f, 0.0f, 0.4f, 0.0f);</div><div><br></div><div><span class="" style="white-space:pre">     </span>// Enable depth test</div><div><span class="" style="white-space:pre">       </span>glEnable(GL_DEPTH_TEST);</div><div><span class="" style="white-space:pre">   </span>// Accept fragment if it closer to the camera than the former one</div><div><span class="" style="white-space:pre">  </span>glDepthFunc(GL_LESS);</div><div><br></div><div><span class="" style="white-space:pre">     </span>// Cull triangles which normal is not towards the camera</div><div><span class="" style="white-space:pre">   </span>glEnable(GL_CULL_FACE);</div><div><br></div><div><span class="" style="white-space:pre">   </span>glBegin(GL_TRIANGLES);</div><div><span class="" style="white-space:pre">     </span>glColor3f(0.5f, 0.0f, 0.0f);</div><div><span class="" style="white-space:pre">       </span>glVertex3f(-1.0f, 0.0f, -1.0f);</div><div><span class="" style="white-space:pre">    </span>glColor3f(0.0f, 0.5f, 0.0f);</div><div><span class="" style="white-space:pre">       </span>glVertex3f(1.0f, 0.0f, -1.0f);</div><div><span class="" style="white-space:pre">     </span>glColor3f(0.0f, 0.0f, 0.5f);</div><div><span class="" style="white-space:pre">       </span>glVertex3f(0.0f, 1.0f, 0.0f);</div><div><span class="" style="white-space:pre">      </span>glEnd();</div><div><br></div><div><span class="" style="white-space:pre">  </span>glFinish();</div><div><span class="" style="white-space:pre">        </span>SaveScreenGrab("mesa_snapshot.tga");</div></div><div><br></div><div><br></div><div>But same triangle using shader doesn't render at all. However the glClearColor clears the screen color correctly.</div><div><br></div><div><br></div><div>Below is the bit of code that I took from (<a href="http://opengl.org">opengl.org</a>) which render the scene into a targa image.</div><div><br></div><div><div><span class="" style="white-space:pre">       </span>// Dark blue background</div><div><span class="" style="white-space:pre">    </span>glClearColor(0.0f, 0.0f, 0.4f, 0.0f);</div><div><br></div><div><span class="" style="white-space:pre">     </span>// Enable depth test</div><div><span class="" style="white-space:pre">       </span>glEnable(GL_DEPTH_TEST);</div><div><span class="" style="white-space:pre">   </span>// Accept fragment if it closer to the camera than the former one</div><div><span class="" style="white-space:pre">  </span>glDepthFunc(GL_LESS);</div><div><br></div><div><span class="" style="white-space:pre">     </span>// Create and compile our GLSL program from the shaders</div><div><span class="" style="white-space:pre">    </span>GLuint programID = LoadShaders("camera.vertexshader", "camera.fragmentshader");</div><div><br></div><div><span class="" style="white-space:pre">       </span>// Get a handle for our "MVP" uniform</div><div><span class="" style="white-space:pre">    </span>GLuint MatrixID = glGetUniformLocation(programID, "MVP");</div><div><br></div><div><span class="" style="white-space:pre">       </span>// Get a handle for our buffers</div><div><span class="" style="white-space:pre">    </span>GLuint vertexPosition_modelspaceID = glGetAttribLocation(programID, "vertexPosition_modelspace");</div><div><span class="" style="white-space:pre">        </span>GLuint vertexColorID = glGetAttribLocation(programID, "vertexColor");</div><div><br></div><div><span class="" style="white-space:pre">   </span>// Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units</div><div><span class="" style="white-space:pre"> </span>glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);</div><div><br></div><div><span class="" style="white-space:pre">        </span>// Camera matrix</div><div><span class="" style="white-space:pre">   </span>glm::mat4 View = glm::lookAt(</div><div><span class="" style="white-space:pre">              </span>glm::vec3(4, 3, -3), // Camera is at (4,3,-3), in World Space</div><div><span class="" style="white-space:pre">              </span>glm::vec3(0, 0, 0), // and looks at the origin</div><div><span class="" style="white-space:pre">             </span>glm::vec3(0, 1, 0)  // Head is up (set to 0,-1,0 to look upside-down)</div><div><span class="" style="white-space:pre">             </span>);</div><div><span class="" style="white-space:pre"> </span>// Model matrix : an identity matrix (model will be at the origin)</div><div><span class="" style="white-space:pre"> </span>glm::mat4 Model = glm::mat4(1.0f);</div><div><span class="" style="white-space:pre"> </span>// Our ModelViewProjection : multiplication of our 3 matrices</div><div><span class="" style="white-space:pre">      </span>glm::mat4 MVP = Projection * View * Model; // Remember, matrix multiplication is the other way around</div><div><br></div><div><span class="" style="white-space:pre">     </span>GLuint vertexbuffer;</div><div><span class="" style="white-space:pre">       </span>glGenBuffers(1, &vertexbuffer);</div><div><span class="" style="white-space:pre">        </span>glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);</div><div><span class="" style="white-space:pre">       </span>glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);</div><div><br></div><div><span class="" style="white-space:pre">        </span>GLuint colorbuffer;</div><div><span class="" style="white-space:pre">        </span>glGenBuffers(1, &colorbuffer);</div><div><span class="" style="white-space:pre"> </span>glBindBuffer(GL_ARRAY_BUFFER, colorbuffer);</div><div><span class="" style="white-space:pre">        </span>glBufferData(GL_ARRAY_BUFFER, sizeof(g_color_buffer_data), g_color_buffer_data, GL_STATIC_DRAW);</div><div><br></div><div><span class="" style="white-space:pre">          </span>// Clear the screen</div><div><span class="" style="white-space:pre">                </span>glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);</div><div><br></div><div><span class="" style="white-space:pre">               </span>// Use our shader</div><div><span class="" style="white-space:pre">          </span>glUseProgram(programID);</div><div><br></div><div><span class="" style="white-space:pre">          </span>// Send our transformation to the currently bound shader, </div><div><span class="" style="white-space:pre">                </span>// in the "MVP" uniform</div><div><span class="" style="white-space:pre">          </span>glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);</div><div><br></div><div><span class="" style="white-space:pre">                </span>// 1rst attribute buffer : vertices</div><div><span class="" style="white-space:pre">                </span>glEnableVertexAttribArray(vertexPosition_modelspaceID);</div><div><span class="" style="white-space:pre">            </span>glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);</div><div><span class="" style="white-space:pre">               </span>glVertexAttribPointer(</div><div><span class="" style="white-space:pre">                     </span>vertexPosition_modelspaceID, // The attribute we want to configure</div><div><span class="" style="white-space:pre">                 </span>3,                           // size</div><div><span class="" style="white-space:pre">                  </span>GL_FLOAT,                    // type</div><div><span class="" style="white-space:pre">                     </span>GL_FALSE,                    // normalized?</div><div><span class="" style="white-space:pre">                      </span>0,                           // stride</div><div><span class="" style="white-space:pre">                        </span>(void*)0                     // array buffer offset</div><div><span class="" style="white-space:pre">                      </span>);</div><div><br></div><div><span class="" style="white-space:pre">                </span>// 2nd attribute buffer : colors</div><div><span class="" style="white-space:pre">           </span>glEnableVertexAttribArray(vertexColorID);</div><div><span class="" style="white-space:pre">          </span>glBindBuffer(GL_ARRAY_BUFFER, colorbuffer);</div><div><span class="" style="white-space:pre">                </span>glVertexAttribPointer(</div><div><span class="" style="white-space:pre">                     </span>vertexColorID,               // The attribute we want to configure</div><div><span class="" style="white-space:pre">                  </span>3,                           // size</div><div><span class="" style="white-space:pre">                  </span>GL_FLOAT,                    // type</div><div><span class="" style="white-space:pre">                     </span>GL_FALSE,                    // normalized?</div><div><span class="" style="white-space:pre">                      </span>0,                           // stride</div><div><span class="" style="white-space:pre">                        </span>(void*)0                     // array buffer offset</div><div><span class="" style="white-space:pre">                      </span>);</div><div><br></div><div><span class="" style="white-space:pre">                </span>// Draw the triangleS !</div><div><span class="" style="white-space:pre">            </span>glDrawArrays(GL_TRIANGLES, 0, 12 * 3); // 12*3 indices starting at 0 -> 12 triangles</div><div><br></div><div><br></div><div><span class="" style="white-space:pre">          </span>glDisableVertexAttribArray(vertexPosition_modelspaceID);</div><div><span class="" style="white-space:pre">           </span>glDisableVertexAttribArray(vertexColorID);</div><div><br></div><div><span class="" style="white-space:pre">                </span>SaveScreenGrab("mesa_snapshot.tga");</div><div><br></div><div><span class="" style="white-space:pre">    </span>// Cleanup VBO and shader</div><div><span class="" style="white-space:pre">  </span>glDeleteBuffers(1, &vertexbuffer);</div><div><span class="" style="white-space:pre">     </span>glDeleteBuffers(1, &colorbuffer);</div><div><span class="" style="white-space:pre">      </span>glDeleteProgram(programID);</div></div><div><br></div><div><br></div><div><br></div><div><b>vertex shader code:</b></div><div><div><br></div><div>#version 120</div><div><br></div><div>// Input vertex data, different for all executions of this shader.</div><div>attribute vec3 vertexPosition_modelspace;</div><div>attribute vec3 vertexColor;</div><div><br></div><div>// Output data ; will be interpolated for each fragment.</div><div>varying vec3 fragmentColor;</div><div>// Values that stay constant for the whole mesh.</div><div>uniform mat4 MVP;</div><div><br></div><div>void main(){<span class="" style="white-space:pre">   </span></div><div><br></div><div><span class="" style="white-space:pre">  </span>// Output position of the vertex, in clip space : MVP * position</div><div><span class="" style="white-space:pre">   </span>gl_Position =  MVP * vec4(vertexPosition_modelspace,1);</div><div><br></div><div><span class="" style="white-space:pre">  </span>// The color of each vertex will be interpolated</div><div><span class="" style="white-space:pre">   </span>// to produce the color of each fragment</div><div><span class="" style="white-space:pre">   </span>fragmentColor = vertexColor;</div><div>}</div></div><div><br></div><div><b>fragment shader code:</b></div><div><b><br></b></div><div><div>#version 120</div><div>// Interpolated values from the vertex shaders</div><div>varying vec3 fragmentColor;</div><div><br></div><div>void main(){</div><div><br></div><div><span class="" style="white-space:pre">     </span>gl_FragColor = fragmentColor;</div><div><br></div><div>}</div></div><div><br></div><div><br></div><div><br></div><div>Please guide me if I am doing something wrong here.</div><div><br></div><div><br></div><div><br></div><div>Thanks & Regards,</div><div>Vikram</div><div><br></div></div>