Open GL polygons not displaying

Posted by Darestium on Game Development See other posts from Game Development or by Darestium
Published on 2012-07-06T07:58:45Z Indexed on 2012/07/06 9:24 UTC
Read the original article Hit count: 243

Filed under:
|
|

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");

    app.UseVerticalSync(false);

    init();

    while (app.IsOpened())  {
        processEvents(&app);

        renderGlScene(&app);

        app.Display();
    }

    return EXIT_SUCCESS;
}

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

    // Enable z-buffer and read and write
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);

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

    glShadeModel(GL_SMOOTH);
}

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

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

        if (event.Type == sf::Event::KeyPressed &&
            event.Key.Code == sf::Key::Escape)  {
            app->Close();
        }
    }
}

void renderGlScene(sf::Window *app)  {
    app->SetActive();

    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

    glBegin(GL_TRIANGLES);
        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
    glEnd();

    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);
    glEnd();
}

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

© Game Development or respective owner

Related posts about c++

Related posts about opengl