Advertisement
Guest User

Untitled

a guest
Aug 25th, 2011
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.11 KB | None | 0 0
  1. #include <GL/glew.h>
  2.  
  3. #include <SFML/Graphics.hpp>
  4. #include <SFML/OpenGL.hpp>
  5.  
  6. #include <iostream>
  7.  
  8. #include <sstream>
  9. #include <string>
  10.  
  11. int main( int argc, const char* argv[] )
  12.  {
  13.     sf::RenderWindow App;
  14.     sf::Texture titleImage;
  15.  titleImage.LoadFromFile("./data/Title.png");
  16.  
  17.  sf::ContextSettings Settings;
  18.     Settings.DepthBits         = 24; // Request a 24 bits depth buffer
  19.     Settings.StencilBits       = 8;  // Request a 8 bits stencil buffer
  20.     Settings.AntialiasingLevel = 0;  // Request 2 levels of antialiasing
  21.     Settings.MajorVersion = 2;
  22.     Settings.MinorVersion = 1;
  23.  
  24.  
  25.  
  26.     App.Create(sf::VideoMode(800, 600, sf::VideoMode::GetDesktopMode().BitsPerPixel), "Test", sf::Style::Default ,Settings);
  27.  
  28.  
  29.     App.EnableVerticalSync(false);
  30.  
  31.  
  32.  
  33.     try{
  34.        std::cout << "Using OpenGL " << App.GetSettings().MajorVersion << "." << App.GetSettings().MinorVersion << std::endl;
  35.  
  36.        if ((App.GetSettings().MajorVersion < Settings.MajorVersion) || (App.GetSettings().MajorVersion == Settings.MajorVersion && App.GetSettings().MinorVersion < Settings.MinorVersion))
  37.        {
  38.           std::cout << "Sorry but a minimum of OpenGL "<< Settings.MajorVersion <<"."<< Settings.MinorVersion <<" is required"<<std::endl;
  39.           std::cout << "Try updating your drivers." << std::endl;
  40.           return false;
  41.        }
  42.  
  43.     }
  44.     catch(int e){
  45.        std::cout << "Failed to get OpenGL version. " << e << std::endl;
  46.  
  47.        return false;
  48.     }
  49.  
  50.     GLenum err = glewInit();
  51.     if (GLEW_OK != err)
  52.     {
  53.        /* Problem: glewInit failed, something is seriously wrong. */
  54.        std::cout << "Error: " << glewGetErrorString(err) << std::endl;
  55.        return false;
  56.     }
  57.     else
  58.     {
  59.        std::cout << "Using GLEW " << glewGetString(GLEW_VERSION) << std::endl;
  60.     }
  61.  
  62.  
  63.  
  64.     App.SetFramerateLimit(60 );
  65.     App.ShowMouseCursor(false);
  66.  
  67.  
  68.  while (App.IsOpened())
  69.        {
  70.           // Process events
  71.           sf::Event Event;
  72.           while (App.PollEvent(Event))
  73.           {
  74.               // Close window
  75.                  if (Event.Type == sf::Event::Closed)
  76.                      App.Close();
  77.  
  78.                  // Escape key pressed
  79.                  if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Escape))
  80.                      App.Close();
  81.  
  82.                  if (Event.Type == sf::Event::Resized)
  83.                      glViewport(0, 0, Event.Size.Width, Event.Size.Height);
  84.              }
  85.  
  86.  
  87.  
  88.              App.SetActive();
  89.              glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  90.                      // Dark blue background
  91.                      glClearColor(0.392156863f, 0.584313725f, 0.929411765f, 0.0f);
  92.  
  93.  
  94.  
  95.                      App.SaveGLStates();
  96.                     App.Draw(sf::Sprite(titleImage ));
  97.      std::stringstream ss;
  98.     ss << App.GetFrameTime();
  99.     sf::Text string(ss.str() + " ms",sf::Font::GetDefaultFont(), 14);
  100.     string.SetPosition(5,5);
  101.     App.Draw(string);
  102.      App.RestoreGLStates();
  103.  
  104.  
  105.  
  106.              // Display window contents on screen
  107.           App.Display();
  108.        }
  109.  
  110.  
  111.  
  112.  
  113.      return 0;
  114.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement