Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML2 SetActive() Failed to activate window context  (Read 2647 times)

0 Members and 1 Guest are viewing this topic.

mercurio7891

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
SFML2 SetActive() Failed to activate window context
« on: January 18, 2011, 12:27:59 pm »
Hi, I create a simple app and in the main loop when i do

App.SetActive(true);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

App.Display();

App.SetActive(false);

When running, it output on the console "Failed to activate window context". If I comment away App.SetActive(false); everything is normal.

Why is it that calling App.SetActive(false) would produce that error? Is there a change in the proper usage of SetActive() in SFML2.0?

P.S: this problem did not appear in SFML1.6

regards.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
SFML2 SetActive() Failed to activate window context
« Reply #1 on: January 18, 2011, 12:54:55 pm »
Can you please show a complete code that I can test?
Laurent Gomila - SFML developer

mercurio7891

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
SFML2 SetActive() Failed to activate window context
« Reply #2 on: January 18, 2011, 01:28:26 pm »
Here is the code. I took most of the code from the opengl tutorial for sfml1.6

http://www.sfml-dev.org/tutorials/1.6/window-opengl.php

Code: [Select]

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>


////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
void ThreadFunction()
{
    // Create the main window
    sf::ContextSettings Settings;
    Settings.DepthBits         = 24; // Request a 24 bits depth buffer
    Settings.StencilBits       = 8;  // Request a 8 bits stencil buffer
    Settings.AntialiasingLevel = 0;  // Request 2 levels of antialiasing
    sf::Window App(sf::VideoMode(1024, 768, 32), "SFML OpenGL", sf::Style::Close, Settings);

    // Set color and depth clear value
    glClearDepth(1.f);
    glClearColor(0.176f, 0.196f, 0.667f, 0.0f);

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

    // Setup a perspective projection
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90.f, 1.f, 1.f, 500.f);

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();

            // Escape key : exit
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                App.Close();

            // Resize event : adjust viewport
            if (Event.Type == sf::Event::Resized)
                glViewport(0, 0, Event.Size.Width, Event.Size.Height);
        }

        // Set the active window before using OpenGL commands
        // It's useless here because active window is always the same,
        // but don't forget it if you use multiple windows or controls
        App.SetActive(true);

        // Clear color and depth buffer
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        // Finally, display rendered frame on screen
        App.Display();

        App.SetActive(false);
    }

    std::cin.get();
}

int main()
{
    sf::Thread thread(&ThreadFunction);

    thread.Launch();

    return EXIT_SUCCESS;
}

 

anything