Advertisement
RichardWard

C++ - SFML - OpenGL hiba

Aug 30th, 2015
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.44 KB | None | 0 0
  1. #include <SFML/Window.hpp>
  2. #include <SFML/OpenGL.hpp>
  3. #include <gl\GLU.h>
  4. #include "SOIL.h";
  5. int texture[1];
  6.  
  7. int LoadGLTextures()
  8. {
  9.     texture[0] = SOIL_load_OGL_texture
  10.         (
  11.         "Crate.bmp",
  12.         SOIL_LOAD_AUTO,
  13.         SOIL_CREATE_NEW_ID,
  14.         SOIL_FLAG_INVERT_Y
  15.         );
  16.  
  17.     if(texture[0] == 0)
  18.         return false;
  19.     glBindTexture(GL_TEXTURE_2D, texture[0]);
  20.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  21.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  22.  
  23.     return true;
  24. }
  25.  
  26. int main()
  27. {
  28.     sf::Window window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, sf::ContextSettings(32));
  29.     window.setVerticalSyncEnabled(true);
  30.  
  31.     bool running = true;
  32.     while (running)
  33.     {
  34.         sf::Event event;
  35.         while (window.pollEvent(event))
  36.         {
  37.             if (event.type == sf::Event::Closed)
  38.             {
  39.                 running = false;
  40.             }
  41.             else if (event.type == sf::Event::Resized)
  42.             {
  43.                 glViewport(0, 0, event.size.width, event.size.height);
  44.             }
  45.         }
  46.  
  47.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  48.         glClearDepth(1.f);
  49.         glClearColor(0.f, 0.f, 0.f, 0.f);
  50.         glEnable(GL_DEPTH_TEST);
  51.         glDepthMask(GL_TRUE);
  52.  
  53.         glMatrixMode(GL_PROJECTION);
  54.         glLoadIdentity();
  55.         gluPerspective(90.f, 1.f, 1.f, 500.f);
  56.  
  57.                 glMatrixMode(GL_MODELVIEW);
  58.         glLoadIdentity();
  59.         glTranslatef(0.f, 0.f, -200.f);
  60.         glEnable(GL_TEXTURE_2D);
  61.             glBindTexture(GL_TEXTURE_2D, texture[0]);
  62.         glBegin(GL_QUADS);
  63.  
  64.             glVertex3f(-50.f, -50.f, -50.f);
  65.             glVertex3f(-50.f,  50.f, -50.f);
  66.             glVertex3f( 50.f,  50.f, -50.f);
  67.             glVertex3f( 50.f, -50.f, -50.f);
  68.  
  69.             glVertex3f(-50.f, -50.f, 50.f);
  70.             glVertex3f(-50.f,  50.f, 50.f);
  71.             glVertex3f( 50.f,  50.f, 50.f);
  72.             glVertex3f( 50.f, -50.f, 50.f);
  73.  
  74.             glVertex3f(-50.f, -50.f, -50.f);
  75.             glVertex3f(-50.f,  50.f, -50.f);
  76.             glVertex3f(-50.f,  50.f,  50.f);
  77.             glVertex3f(-50.f, -50.f,  50.f);
  78.  
  79.             glVertex3f(50.f, -50.f, -50.f);
  80.             glVertex3f(50.f,  50.f, -50.f);
  81.             glVertex3f(50.f,  50.f,  50.f);
  82.             glVertex3f(50.f, -50.f,  50.f);
  83.  
  84.             glVertex3f(-50.f, -50.f,  50.f);
  85.             glVertex3f(-50.f, -50.f, -50.f);
  86.             glVertex3f( 50.f, -50.f, -50.f);
  87.             glVertex3f( 50.f, -50.f,  50.f);
  88.  
  89.             glVertex3f(-50.f, 50.f,  50.f);
  90.             glVertex3f(-50.f, 50.f, -50.f);
  91.             glVertex3f( 50.f, 50.f, -50.f);
  92.             glVertex3f( 50.f, 50.f,  50.f);
  93.  
  94.         glEnd();
  95.         window.display();
  96.     }
  97.  
  98.  
  99.     return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement