SFML - Window does not appear?

Hi, I've been working a bit in SFML and OpenGL (1.1). Sadly, however, I am unable to get past the first step: creating a window. Here's my code (only the problem region is shown EDIT: entire thing there now):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <SFML/Window.hpp>

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

    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);

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

int main() {
    //!!Problem area begins here!!
    // Create the main window
    sf::Window App(sf::VideoMode(800, 600), "SFML Window");
    App.Show(true); //Added to attempt to get the window to show, still doesn't
    
    initGL();
    
    sf::Clock Clock;
    
    // Start game loop
    while (App.IsOpened()) {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event)) {
            switch (Event.Type) {
                case sf::Event::Closed:
                    App.Close();
                    break;
                default:
                    break;
            }
        }
        
        App.SetActive();
        //!!Problem Area Ends Here!!
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glTranslatef(0.f, 0.f, -200.f);
        glRotatef(Clock.GetElapsedTime() * 50, 1.f, 0.f, 0.f);
        glRotatef(Clock.GetElapsedTime() * 30, 0.f, 1.f, 0.f);
        glRotatef(Clock.GetElapsedTime() * 90, 0.f, 0.f, 1.f);
        
        glBegin(GL_QUADS);

            glVertex3f(-50.f, -50.f, -50.f);
            glVertex3f(-50.f,  50.f, -50.f);
            glVertex3f( 50.f,  50.f, -50.f);
            glVertex3f( 50.f, -50.f, -50.f);

            glVertex3f(-50.f, -50.f, 50.f);
            glVertex3f(-50.f,  50.f, 50.f);
            glVertex3f( 50.f,  50.f, 50.f);
            glVertex3f( 50.f, -50.f, 50.f);

            glVertex3f(-50.f, -50.f, -50.f);
            glVertex3f(-50.f,  50.f, -50.f);
            glVertex3f(-50.f,  50.f,  50.f);
            glVertex3f(-50.f, -50.f,  50.f);

            glVertex3f(50.f, -50.f, -50.f);
            glVertex3f(50.f,  50.f, -50.f);
            glVertex3f(50.f,  50.f,  50.f);
            glVertex3f(50.f, -50.f,  50.f);

            glVertex3f(-50.f, -50.f,  50.f);
            glVertex3f(-50.f, -50.f, -50.f);
            glVertex3f( 50.f, -50.f, -50.f);
            glVertex3f( 50.f, -50.f,  50.f);

            glVertex3f(-50.f, 50.f,  50.f);
            glVertex3f(-50.f, 50.f, -50.f);
            glVertex3f( 50.f, 50.f, -50.f);
            glVertex3f( 50.f, 50.f,  50.f);

        glEnd();
        
        App.Display();
    }
    
    return 0;
}

This does not produce any errors, but it doesn't work either. Upon starting the program, I get a console window - which is expected, as I am using the console entry point. However, the window itself never appears, nor does the console close out, indicating that it is still in the game loop. Any idea what might be wrong? I should add that I do have the closing brackets, I just didn't post that portion. EDIT: Posted now.
Last edited on
What does initGL(); do? It's possible you are butting heads with SFML, which already uses OpenGL. You shouldn't need to do any OpenGL prep since SFML already takes care of that.

Get rid of that call and see if you still have the problems.
1
2
3
4
5
6
7
8
9
10
11
void initGL() {
    glClearDepth(1.f);
    glClearColor(0.f, 0.f, 0.f, 0.f);

    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);

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

Also, I realize SFML has an OpenGL binding, which I am using. I tried doing what you suggested, but it still doesn't open at all.
1
2
3
4
5
6
7
8
9
10
      while (App.GetEvent(Event)) {
            switch (Event.Type) {
                case sf::Event::Closed:
                    App.Close();
                    break;
                default:
                    break;
            }
            App.Display();
      }
Note to self: post the entire code no matter how long. I do have that, cire, below all my OpenGL functions. Which is why I didn't post it, that portion is long. I'll edit my main post to include the entire main.cpp.
That's definitely weird. I don't see what could be causing it.

Have you ever gotten a window to show in any program? Like maybe one of the samples?
This is actually straight from the site - with a few exceptions, like putting all the initialization in a separate function, and using a switch statement for events, not ifs. Other than that, though, its the same. I think I got this to work before, but for whatever reason, it won't now.
Works fine for me. Is there any chance it's not linking properly? Visual studio likes to do that to me. "Hey! Your code didn't link properly. Do you want me to run the previously compiled version?" Clicking through without really looking has had me scratching my head once or twice when I've clicked 'start without debugging' on a needed-to-be-rebuilt project.
I'll look over my project config, see if everything is looking right.
Topic archived. No new replies allowed.