Advertisement
x89codered89x

TextureA

Mar 13th, 2011
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.15 KB | None | 0 0
  1. //Download - http://www.mediafire.com/?y8jp81765cr5pwx
  2.  
  3.  
  4.  
  5. ////////////////////////////////////////////////////////////
  6.  
  7. // Headers
  8.  
  9. ////////////////////////////////////////////////////////////
  10.  
  11. #include <SFML/Graphics.hpp>
  12.  
  13. #include <iostream>
  14.  
  15.  
  16.  
  17.  
  18.  
  19. ////////////////////////////////////////////////////////////
  20.  
  21. /// Entry point of application
  22.  
  23. ///
  24.  
  25. /// \return Application exit code
  26.  
  27. ///
  28.  
  29. ////////////////////////////////////////////////////////////
  30.  
  31. int main()
  32.  
  33. {
  34.  
  35.     // Create main window
  36.  
  37.     sf::RenderWindow App(sf::VideoMode(800, 600), "SFML OpenGL");
  38.  
  39.     App.PreserveOpenGLStates(true);
  40.  
  41.  
  42.     // Create a sprite for the background
  43.  
  44.     sf::Image BImage;
  45.  
  46.     if (!BImage.LoadFromFile("background.bmp"))
  47.  
  48.         return EXIT_FAILURE;
  49.  
  50.     sf::Sprite Background(BImage);
  51.  
  52.  
  53.     GLuint Texture = 0;
  54.  
  55.     {
  56.         sf::Image Image;
  57.  
  58.             if (!Image.LoadFromFile("cb.bmp"))
  59.  
  60.         return EXIT_FAILURE;
  61.  
  62.         glGenTextures(1, &Texture);
  63.  
  64.         glBindTexture(GL_TEXTURE_2D, Texture);
  65.  
  66.         //WTF
  67.         gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, Image.GetWidth(), Image.GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE, Image.GetPixelsPtr());
  68.  
  69.         //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  70.  
  71.         //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
  72.  
  73.     }
  74.  
  75.  
  76.  
  77.     // Enable Z-buffer read and write
  78.  
  79.     glEnable(GL_DEPTH_TEST);
  80.  
  81.     glDepthMask(GL_TRUE);
  82.  
  83.     glClearDepth(1.f);
  84.     glClearColor(0.f, 0.f, 0.f, 0.f);
  85.  
  86.  
  87.  
  88.     // Setup a perspective projection
  89.  
  90.     glMatrixMode(GL_PROJECTION);
  91.  
  92.     glLoadIdentity();
  93.  
  94.     gluPerspective(45.f, 4.0/3.0, 1.f, 500.f);
  95.  
  96.  
  97.  
  98.     // Bind our texture
  99.  
  100.     glEnable(GL_TEXTURE_2D);
  101.  
  102.     glBindTexture(GL_TEXTURE_2D, Texture);
  103.  
  104.     glColor4f(1.f, 1.f, 1.f, 1.f);
  105.  
  106.  
  107.  
  108.     // Create a clock for measuring the time elapsed
  109.  
  110.     sf::Clock Clock;
  111.  
  112.  
  113.  
  114.     // Start game loop
  115.  
  116.     while (App.IsOpened())
  117.  
  118.     {
  119.  
  120.         // Process events
  121.  
  122.         sf::Event Event;
  123.  
  124.         while (App.GetEvent(Event))
  125.  
  126.         {
  127.  
  128.             // Close window : exit
  129.  
  130.             if (Event.Type == sf::Event::Closed)
  131.  
  132.                 App.Close();
  133.  
  134.  
  135.  
  136.             // Escape key : exit
  137.  
  138.             if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
  139.  
  140.                 App.Close();
  141.  
  142.  
  143.  
  144.             // Adjust the viewport when the window is resized
  145.  
  146.             if (Event.Type == sf::Event::Resized)
  147.  
  148.             {
  149.                 glViewport(0, 0, Event.Size.Width, Event.Size.Height);
  150.                 glMatrixMode(GL_PROJECTION);
  151.  
  152.                 glLoadIdentity();
  153.  
  154.                 gluPerspective(45.f, (double) Event.Size.Width/ (double) Event.Size.Height, 1.f, 500.f);
  155.             }
  156.  
  157.          }
  158.  
  159.  
  160.  
  161.         // Draw background
  162.  
  163.         App.Draw(Background);
  164.  
  165.  
  166.  
  167.         // Clear depth buffer
  168.  
  169.         glClear(GL_DEPTH_BUFFER_BIT);
  170.  
  171.  
  172.  
  173.         // Apply some transformations
  174.  
  175.         glMatrixMode(GL_MODELVIEW);
  176.  
  177.         glLoadIdentity();
  178.  
  179.         glTranslatef(0.f, 0.f, -300.f);
  180.  
  181.         glRotatef(Clock.GetElapsedTime() * 100, 1.f, 0.f, 0.f);
  182.  
  183.         glRotatef(Clock.GetElapsedTime() * 100, 0.f, 1.f, 0.f);
  184.  
  185.         glRotatef(Clock.GetElapsedTime() * 100, 0.f, 0.f, 1.f);
  186.  
  187.         glTranslatef(50.f, 0.f, 0.f);
  188.  
  189.         // Draw a cube
  190.  
  191.         glBegin(GL_QUADS);
  192.  
  193.             glTexCoord2f(0, 0); glVertex3f(-50.f, -50.f, -50.f);
  194.  
  195.             glTexCoord2f(0, 1); glVertex3f(-50.f,  50.f, -50.f);
  196.  
  197.             glTexCoord2f(1, 1); glVertex3f( 50.f,  50.f, -50.f);
  198.  
  199.             glTexCoord2f(1, 0); glVertex3f( 50.f, -50.f, -50.f);
  200.  
  201.  
  202.  
  203.             glTexCoord2f(0, 0); glVertex3f(-50.f, -50.f, 50.f);
  204.  
  205.             glTexCoord2f(0, 1); glVertex3f(-50.f,  50.f, 50.f);
  206.  
  207.             glTexCoord2f(1, 1); glVertex3f( 50.f,  50.f, 50.f);
  208.  
  209.             glTexCoord2f(1, 0); glVertex3f( 50.f, -50.f, 50.f);
  210.  
  211.  
  212.  
  213.             glTexCoord2f(0, 0); glVertex3f(-50.f, -50.f, -50.f);
  214.  
  215.             glTexCoord2f(0, 1); glVertex3f(-50.f,  50.f, -50.f);
  216.  
  217.             glTexCoord2f(1, 1); glVertex3f(-50.f,  50.f,  50.f);
  218.  
  219.             glTexCoord2f(1, 0); glVertex3f(-50.f, -50.f,  50.f);
  220.  
  221.  
  222.  
  223.             glTexCoord2f(0, 0); glVertex3f(50.f, -50.f, -50.f);
  224.  
  225.             glTexCoord2f(0, 1); glVertex3f(50.f,  50.f, -50.f);
  226.  
  227.             glTexCoord2f(1, 1); glVertex3f(50.f,  50.f,  50.f);
  228.  
  229.             glTexCoord2f(1, 0); glVertex3f(50.f, -50.f,  50.f);
  230.  
  231.  
  232.  
  233.             glTexCoord2f(0, 1); glVertex3f(-50.f, -50.f,  50.f);
  234.  
  235.             glTexCoord2f(0, 0); glVertex3f(-50.f, -50.f, -50.f);
  236.  
  237.             glTexCoord2f(1, 0); glVertex3f( 50.f, -50.f, -50.f);
  238.  
  239.             glTexCoord2f(1, 1); glVertex3f( 50.f, -50.f,  50.f);
  240.  
  241.  
  242.  
  243.             glTexCoord2f(0, 1); glVertex3f(-50.f, 50.f,  50.f);
  244.  
  245.             glTexCoord2f(0, 0); glVertex3f(-50.f, 50.f, -50.f);
  246.  
  247.             glTexCoord2f(1, 0); glVertex3f( 50.f, 50.f, -50.f);
  248.  
  249.             glTexCoord2f(1, 1); glVertex3f( 50.f, 50.f,  50.f);
  250.  
  251.         glEnd();
  252.  
  253.         App.Display();
  254.  
  255.     }
  256.  
  257.  
  258.  
  259.     // Don't forget to destroy our texture
  260.  
  261.     glDeleteTextures(1, &Texture);
  262.  
  263.  
  264.  
  265.     return EXIT_SUCCESS;
  266.  
  267. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement