Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/glew.h>
- #include <SFML/Graphics.hpp>
- #include <SFML/OpenGL.hpp>
- #include <iostream>
- #include <sstream>
- #include <string>
- int main( int argc, const char* argv[] )
- {
- sf::RenderWindow App;
- sf::Texture titleImage;
- titleImage.LoadFromFile("./data/Title.png");
- 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
- Settings.MajorVersion = 2;
- Settings.MinorVersion = 1;
- App.Create(sf::VideoMode(800, 600, sf::VideoMode::GetDesktopMode().BitsPerPixel), "Test", sf::Style::Default ,Settings);
- App.EnableVerticalSync(false);
- try{
- std::cout << "Using OpenGL " << App.GetSettings().MajorVersion << "." << App.GetSettings().MinorVersion << std::endl;
- if ((App.GetSettings().MajorVersion < Settings.MajorVersion) || (App.GetSettings().MajorVersion == Settings.MajorVersion && App.GetSettings().MinorVersion < Settings.MinorVersion))
- {
- std::cout << "Sorry but a minimum of OpenGL "<< Settings.MajorVersion <<"."<< Settings.MinorVersion <<" is required"<<std::endl;
- std::cout << "Try updating your drivers." << std::endl;
- return false;
- }
- }
- catch(int e){
- std::cout << "Failed to get OpenGL version. " << e << std::endl;
- return false;
- }
- GLenum err = glewInit();
- if (GLEW_OK != err)
- {
- /* Problem: glewInit failed, something is seriously wrong. */
- std::cout << "Error: " << glewGetErrorString(err) << std::endl;
- return false;
- }
- else
- {
- std::cout << "Using GLEW " << glewGetString(GLEW_VERSION) << std::endl;
- }
- App.SetFramerateLimit(60 );
- App.ShowMouseCursor(false);
- while (App.IsOpened())
- {
- // Process events
- sf::Event Event;
- while (App.PollEvent(Event))
- {
- // Close window
- if (Event.Type == sf::Event::Closed)
- App.Close();
- // Escape key pressed
- if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Escape))
- App.Close();
- if (Event.Type == sf::Event::Resized)
- glViewport(0, 0, Event.Size.Width, Event.Size.Height);
- }
- App.SetActive();
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- // Dark blue background
- glClearColor(0.392156863f, 0.584313725f, 0.929411765f, 0.0f);
- App.SaveGLStates();
- App.Draw(sf::Sprite(titleImage ));
- std::stringstream ss;
- ss << App.GetFrameTime();
- sf::Text string(ss.str() + " ms",sf::Font::GetDefaultFont(), 14);
- string.SetPosition(5,5);
- App.Draw(string);
- App.RestoreGLStates();
- // Display window contents on screen
- App.Display();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement