SFML community forums

Help => Window => Topic started by: iride on August 23, 2012, 06:20:40 pm

Title: window title displaying junk
Post by: iride on August 23, 2012, 06:20:40 pm

#pragma comment(lib, "sfml-graphics.lib")
#pragma comment(lib, "sfml-window.lib")
#pragma comment(lib, "sfml-system.lib")
#pragma comment(lib, "sfml-audio.lib")


#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")


#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>
#include <SFML/Audio.hpp>

int main()
{
    // create the window
        sf::Window window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Close, sf::ContextSettings());
             

    // load resources, initialize the OpenGL states, ...
        glClearColor (0.0, 0.0, 0.0, 0.0);
        glClear (GL_COLOR_BUFFER_BIT);
        glColor3f (1.0, 1.0, 1.0);
        glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);


    // run the main loop
    bool running = true;
    while (running)
    {
        // handle events
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                // end the program
                running = false;
            }
            else if (event.type == sf::Event::Resized)
            {
                // adjust the viewport when the window is resized
                glViewport(0, 0, event.size.width, event.size.height);
            }
        }

        // clear the buffers
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        // draw...
                glBegin(GL_POLYGON);
                        glVertex3f (0.25, 0.25, 0.0);
                        glVertex3f (0.75, 0.25, 0.0);
                        glVertex3f (0.75, 0.75, 0.0);
                        glVertex3f (0.25, 0.75, 0.0);
                glEnd();



        // end the current frame (internally swaps the front and back buffers)
        window.display();
    }

    // release resources...

    return 0;
}

The above code is displaying junk window title, not "OpenGL".
What did I do wrong?
I'm using 2.0
Title: Re: window title displaying junk
Post by: eXpl0it3r on August 23, 2012, 06:30:23 pm
You're linking against the release libraries (without the '-d' postfix) but you're compile your application as debug. You can't mix release and debug with SFML. ;)

I strongly advice you against the use of #pragma comment linker commands, linking settings are not part of C++ code but are properties of the project, thus you should put them into the project settings, as explained in the official tutorial. ;)
Title: Re: window title displaying junk
Post by: iride on August 23, 2012, 08:52:23 pm
Thanks, i solved the problem.

I noticed that I didn't have to call glFlush() to render

does window.display() include glFlush()?
Title: Re: window title displaying junk
Post by: Laurent on August 23, 2012, 09:41:08 pm
Quote
does window.display() include glFlush()?
Yes.