Advertisement
LittleFox94

sfmlNoShapeGL

Apr 28th, 2014
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <SFML/Window.hpp>
  3. #include <GL/gl.h>
  4.  
  5. int main(int argc, char* argv[])
  6. {
  7.     sf::RenderWindow window(sf::VideoMode(800, 600), sf::String("SFML noShapeGL"), sf::Style::Default, sf::ContextSettings(32,0,8,4,2));
  8.     window.setFramerateLimit(60);
  9.  
  10.     sf::RectangleShape shape(sf::Vector2f(50, 50));
  11.     shape.setPosition(100, 100);
  12.  
  13.     while(window.isOpen())
  14.     {
  15.         sf::Event event;
  16.         while(window.pollEvent(event))
  17.         {
  18.             switch(event.type)
  19.             {
  20.                 case sf::Event::Closed:
  21.                     window.close();
  22.                     break;
  23.             }
  24.         }
  25.  
  26.         window.setActive();
  27.         window.clear(sf::Color(0, 0, 0));
  28.  
  29.  
  30.         //////////////////////////////////////////////////////////////////////////
  31.         // With the line below it's working fine, without it nothing is drawed. //
  32.         //////////////////////////////////////////////////////////////////////////
  33.         //window.draw(shape);
  34.  
  35.         // custom GL-Rendering
  36.         glPushAttrib(GL_TRANSFORM_BIT);
  37.         glLoadIdentity();
  38.  
  39.         glPushAttrib(GL_CURRENT_BIT | GL_LINE_BIT);
  40.         glColor4f(1.0, 0, 0, 1.0);
  41.         glLineWidth(5);
  42.  
  43.         glBegin(GL_LINES);
  44.         {
  45.             glVertex2d(10, 50);
  46.             glVertex2d(50, 10);
  47.         }
  48.         glEnd();
  49.  
  50.         glPopAttrib();
  51.  
  52.         glPopAttrib();
  53.  
  54.         window.display();
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement