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

Author Topic: [SOLVED] SFML Rectangle draws wrong color after GL calls  (Read 1777 times)

0 Members and 1 Guest are viewing this topic.

danthebeliever

  • Newbie
  • *
  • Posts: 10
    • View Profile
[SOLVED] SFML Rectangle draws wrong color after GL calls
« on: February 09, 2011, 11:06:41 pm »
After I do my GL calls, I display a rectangle on the screen depending upon user input. I am aware that by pressing T you will forever display the rectangle (correct functionality).

This is my code (for just the main loop):

Code: [Select]
sf::Shape Rect = sf::Shape::Rectangle(0,0,1920,1080,sf::Color::Black);
Rect.EnableFill(true);
Rect.SetPosition(0,0);

while (theVars->App.IsOpened())
    {
sf::Event event;
bool draw = false;
theVars->App.Clear();

while(theVars->App.GetEvent(event)){
if (event.Type == sf::Event::MouseButtonPressed) {
const sf::Input& Input = theVars->App.GetInput();
if (event.MouseButton.Button == sf::Mouse::Left) {
selectSquares(Input.IsKeyDown(sf::Key::LShift), event.MouseButton.X, event.MouseButton.Y);
}
}
if (event.Type == sf::Event::KeyPressed) {
keyDown(event.Key.Code);
}
if (theVars->App.GetInput().IsKeyDown(sf::Key::T)) {
draw = true;
}
}

// 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
        theVars->App.SetActive();

display();
// Finally, display rendered frame on screen
if(draw)
theVars->App.Draw(Rect);


        theVars->App.Display();
}


Note:: display() is all my OpenGL stuff.

When the rectangle gets drawn the color of the box changes.

Any help?

EDIT: This is caused when you enable lighting in Open GL code. In order to use SFML drawings and display the correct color, you must first disable lighting. You can then reenable it after you draw.

Working Code:

Code: [Select]
glDisable(GL_LIGHTING);
theVars->App.Draw(Rect);
glEnable(GL_LIGHTING);

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
[SOLVED] SFML Rectangle draws wrong color after GL calls
« Reply #1 on: February 09, 2011, 11:20:41 pm »
Could I get a screenshot of the error? Also what version are you using?
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

 

anything