Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have tried to follow nehe's opengl tutorial lesson 2. I use sfml for my window creation. The problem I have is that both the triangle and the quad don't show up on the screen:

#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <iostream>

void processEvents(sf::Window *app);
void processInput(sf::Window *app, const sf::Input &input);

void renderCube(sf::Window *app, sf::Clock *clock);
void renderGlScene(sf::Window *app);

void init();

int main()  {
    sf::Window app(sf::VideoMode(800, 600, 32), "Nehe Lesson 2");



    while (app.IsOpened())  {



    return EXIT_SUCCESS;

void init()  {
    glClearColor(0.f, 0.f, 0.f, 0.f);

    // Enable z-buffer and read and write

    // Setup a perpective projection
    gluPerspective(45.f, 1.f, 1.f, 500.f);


void processEvents(sf::Window *app)  {
    sf::Event event;

    while (app->GetEvent(event))  {
        if (event.Type == sf::Event::Closed)  {

        if (event.Type == sf::Event::KeyPressed &&
            event.Key.Code == sf::Key::Escape)  {

void renderGlScene(sf::Window *app)  {

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  // Clear the screen and the depth buffer
    glLoadIdentity();                   // Reset the view

    glTranslatef(-1.5f, 0.0f, -6.0f);   // Move Left 1.5 units and into the screen 6.0

        glVertex3f( 0.0f, 1.0f, 0.0f);  // Top
        glVertex3f(-1.0,-1.0f, 0.0f);  // Bottom Left
        glVertex3f( 1.0f,-1.0f, 0.0f);  // Bottom Right

    glTranslatef(3.0f, 0.0f, 0.0f);

    glBegin(GL_QUADS);  // Draw a quad
        glVertex3f(-1.0f, 1.0f, 0.0f);
        glVertex3f( 1.0f, 1.0f, 0.0f);
        glVertex3f( 1.0f,-1.0f, 0.0f);
        glVertex3f(-1.0f,-1.0f, 0.0f);

I would greatly appreciate it if someone could help me resolve my issue.

share|improve this question
have you tried setting the clear color to anything other than black to see if it works? – dreta Jul 6 '12 at 11:26
Okay, I fixed it, I just added glMatrixMode(GL_MODELVIEW); directly after I call glClear() in the rendering function. Thanks for trying to help, I really appreciate it! :) And this is old OpenGL? I had no idea, I'm very new to the world of C++. – Darestium Jul 6 '12 at 11:26
I think you might want to change the first glMatrixMode call in your init function to be glMatrixMode(GL_PROJECTION). Currently, you're creating a projection matrix in the modelview space, which I don't think is what you're after. You solved your issue, but my note is only to save you trouble later on :) – Ray Dey Jul 6 '12 at 11:53
@RayDey Cool! Thanks for the tip ;) – Darestium Jul 6 '12 at 12:15
up vote 1 down vote accepted

Changed init's from:




and added


to "renderGlScene(sf::Window *app)" directly after "glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)" is called.

share|improve this answer
That's right. OpenGL is state based, so your glMatrix calls always operate on the last matrix you selected. Here you were always operating on the MODELVIEW matrix and had no projection matrix. If you don't plan on changing the projection matrix again, you could put glMatrixMode( GL_MODELVIEW ); right after your gluPerspective(45.f, 1.f, 1.f, 500.f); call – bobobobo Jul 6 '12 at 15:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.