Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Download - http://www.mediafire.com/?y8jp81765cr5pwx
- ////////////////////////////////////////////////////////////
- // Headers
- ////////////////////////////////////////////////////////////
- #include <SFML/Graphics.hpp>
- #include <iostream>
- ////////////////////////////////////////////////////////////
- /// Entry point of application
- ///
- /// \return Application exit code
- ///
- ////////////////////////////////////////////////////////////
- int main()
- {
- // Create main window
- sf::RenderWindow App(sf::VideoMode(800, 600), "SFML OpenGL");
- App.PreserveOpenGLStates(true);
- // Create a sprite for the background
- sf::Image BImage;
- if (!BImage.LoadFromFile("background.bmp"))
- return EXIT_FAILURE;
- sf::Sprite Background(BImage);
- GLuint Texture = 0;
- {
- sf::Image Image;
- if (!Image.LoadFromFile("cb.bmp"))
- return EXIT_FAILURE;
- glGenTextures(1, &Texture);
- glBindTexture(GL_TEXTURE_2D, Texture);
- //WTF
- gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, Image.GetWidth(), Image.GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE, Image.GetPixelsPtr());
- //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- }
- // Enable Z-buffer read and write
- glEnable(GL_DEPTH_TEST);
- glDepthMask(GL_TRUE);
- glClearDepth(1.f);
- glClearColor(0.f, 0.f, 0.f, 0.f);
- // Setup a perspective projection
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(45.f, 4.0/3.0, 1.f, 500.f);
- // Bind our texture
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, Texture);
- glColor4f(1.f, 1.f, 1.f, 1.f);
- // Create a clock for measuring the time elapsed
- sf::Clock Clock;
- // 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();
- // Adjust the viewport when the window is resized
- if (Event.Type == sf::Event::Resized)
- {
- glViewport(0, 0, Event.Size.Width, Event.Size.Height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(45.f, (double) Event.Size.Width/ (double) Event.Size.Height, 1.f, 500.f);
- }
- }
- // Draw background
- App.Draw(Background);
- // Clear depth buffer
- glClear(GL_DEPTH_BUFFER_BIT);
- // Apply some transformations
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.f, 0.f, -300.f);
- glRotatef(Clock.GetElapsedTime() * 100, 1.f, 0.f, 0.f);
- glRotatef(Clock.GetElapsedTime() * 100, 0.f, 1.f, 0.f);
- glRotatef(Clock.GetElapsedTime() * 100, 0.f, 0.f, 1.f);
- glTranslatef(50.f, 0.f, 0.f);
- // Draw a cube
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0); glVertex3f(-50.f, -50.f, -50.f);
- glTexCoord2f(0, 1); glVertex3f(-50.f, 50.f, -50.f);
- glTexCoord2f(1, 1); glVertex3f( 50.f, 50.f, -50.f);
- glTexCoord2f(1, 0); glVertex3f( 50.f, -50.f, -50.f);
- glTexCoord2f(0, 0); glVertex3f(-50.f, -50.f, 50.f);
- glTexCoord2f(0, 1); glVertex3f(-50.f, 50.f, 50.f);
- glTexCoord2f(1, 1); glVertex3f( 50.f, 50.f, 50.f);
- glTexCoord2f(1, 0); glVertex3f( 50.f, -50.f, 50.f);
- glTexCoord2f(0, 0); glVertex3f(-50.f, -50.f, -50.f);
- glTexCoord2f(0, 1); glVertex3f(-50.f, 50.f, -50.f);
- glTexCoord2f(1, 1); glVertex3f(-50.f, 50.f, 50.f);
- glTexCoord2f(1, 0); glVertex3f(-50.f, -50.f, 50.f);
- glTexCoord2f(0, 0); glVertex3f(50.f, -50.f, -50.f);
- glTexCoord2f(0, 1); glVertex3f(50.f, 50.f, -50.f);
- glTexCoord2f(1, 1); glVertex3f(50.f, 50.f, 50.f);
- glTexCoord2f(1, 0); glVertex3f(50.f, -50.f, 50.f);
- glTexCoord2f(0, 1); glVertex3f(-50.f, -50.f, 50.f);
- glTexCoord2f(0, 0); glVertex3f(-50.f, -50.f, -50.f);
- glTexCoord2f(1, 0); glVertex3f( 50.f, -50.f, -50.f);
- glTexCoord2f(1, 1); glVertex3f( 50.f, -50.f, 50.f);
- glTexCoord2f(0, 1); glVertex3f(-50.f, 50.f, 50.f);
- glTexCoord2f(0, 0); glVertex3f(-50.f, 50.f, -50.f);
- glTexCoord2f(1, 0); glVertex3f( 50.f, 50.f, -50.f);
- glTexCoord2f(1, 1); glVertex3f( 50.f, 50.f, 50.f);
- glEnd();
- App.Display();
- }
- // Don't forget to destroy our texture
- glDeleteTextures(1, &Texture);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement