SFML community forums

Help => General => Topic started by: Ninjasturm on October 20, 2010, 03:39:54 pm

Title: Get no picture by sing opengl
Post by: Ninjasturm on October 20, 2010, 03:39:54 pm
Hello Community,

i want to use OpenGL
but when i run this modfied example.

Code: [Select]

#include <SFML/Window.hpp>

int main()
{
    // Fenster erstellen
    sf::Window App(sf::VideoMode(800, 600, 32), "OpenGL");

    glClearDepth(1.f);
    glClearColor(0.f, 0.f, 0.f, 0.f);

    // Z - Buffer
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);

    // Projektion
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90.f, 1.f, 1.f, 500.f);

    // Hauptschleife
    while (App.IsOpened())
    {
        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();
            }
            if (Event.Type == sf::Event::Resized)
            {
                glViewport(0, 0, Event.Size.Width, Event.Size.Height);
            }
        }
        App.SetActive();

        // Fenster leeren
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glTranslatef(0.f, 0.f, -200.f);

        glBegin(GL_POLYGON);
            glVertex3f (0, 0, 0);
            glVertex3f (25, 0, 0);
            glVertex3f (0, 0, 25);
            glVertex3f (25, 0, 25);
        glEnd();

        App.Display();
    }

    return EXIT_SUCCESS;
}

i get no picture only a black screen.

thx for help
Title: Get no picture by sing opengl
Post by: Laurent on October 20, 2010, 03:52:26 pm
This could be a wrong OpenGL state, bad matrices, incorrect vertex order, ... it's hard to tell.

You should start with the Window sample from the SFML SDK, it does exactly the same thing (except that it draws a 3D cube) -- and it works.
Title: Get no picture by sing opengl
Post by: Ninjasturm on October 20, 2010, 03:55:57 pm
I used the example but now i want try it at my own.
Title: Get no picture by sing opengl
Post by: Laurent on October 20, 2010, 04:10:06 pm
Of course, but you can use it to see what's wrong in your code.