SFML 2.0 Opengl problem

Nov 7, 2013 at 12:18am
i was trying to combine opengl with sfml and the code worked but it can't draw anything to it. my assumption is that i need to pop and push opengl states but i get this error:

'class sf::Window' has no member named 'popOpenGLStates'|

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
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>

int main()
{
    /// create the window
    sf::Window window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, sf::ContextSettings(32));
    window.setVerticalSyncEnabled(true);

    /// load resources, initialize the OpenGL states, ...
    glLoadIdentity();
    glTranslatef(15.0f, 0.0f, -6.0f);

    /// 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_TRIANGLES);
        glVertex3f(0.f, 0.f, 0.f);
        glVertex3f(-1.f, -1.f, 0.f);
        glVertex3f(1.f, -1.f, 0.f);
        glEnd();

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

    /// release resources...

    return 0;
}
Nov 7, 2013 at 12:59am
Unless you're using SFML's draw functions (e.g. window.draw(...)) then you do not need to push or pop the openGL states.

I have a working example here that I literally just got working today:
https://github.com/LB--/Recipe-Spelunker/blob/fcc51df018e07357fcde87caeef72a7621d2d3e8/src/client/main.cpp
It has a lot of dependencies so you may not be able to compile it, but the code works. You can use it as a reference, but note that I am still new to this stuff too :)
Nov 7, 2013 at 2:42am
well do you know how i would draw the gl_triangle?
Nov 7, 2013 at 2:46am
I used this as a reference, it has a triangle in it:
https://github.com/xerpi/NeHe-SFML2.0/blob/master/nehe_lesson5.cpp
Topic archived. No new replies allowed.