Cub on s++ (with SFML library)



  • The program should cube and rotate it. I'm writing on the 64th system, but the 32nd program. It's the library.

    There are mistakes:

    введите сюда описание изображения

    Here's the code:

    #include <SFML/Graphics.hpp>
    #include <SFML/OpenGL.hpp>
    #pragma comment(lib, "glu32.lib")
    #include <gl/glu.h> 
    #include <iostream>
    using namespace sf;
    

    int main() {
    RenderWindow window(VideoMode(800, 600), "Minecraft C++");

    Texture t;
    t.loadFromFile("resources\background.jpg");
    Sprite background(t);
    
    GLuint texture = 0;
    {
        Image image;
        image.loadFromFile("resources\texture.jpg");
    
        glGenTextures(1, &amp;texture);
        glBindTexture(GL_TEXTURE_2D, texture);
        gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.getSize().x, image.getSize().y, 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);
    }
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glClearDepth(1.f);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90.f, 1.f, 1.f, 500.f);
    glEnable(GL_TEXTURE_2D);
    
    Clock Clock;
    while (window.isOpen()) {
        Event event;
        while (window.pollEvent(event)) {
            if (event.type == Event::Closed)
                window.close();
        }
    
        float time = 30;
        float size = 20.f;
    
        window.pushGLStates();
        window.draw(background);
        window.popGLStates();
    
        glClear(GL_DEPTH_BUFFER_BIT);
    
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glTranslatef(0, 0, -100);
        glRotatef(time, 50, 50, 0);
    
    
    
    
    
    
    
    
        glBindTexture(GL_TEXTURE_2D, texture);
        glBegin(GL_QUADS);
    
        glTexCoord2f(0, 0);   glVertex3f(-size, -size, -size);
        glTexCoord2f(1, 0);   glVertex3f(size, -size, -size);
        glTexCoord2f(1, 1);   glVertex3f(size, size, -size);
        glTexCoord2f(0, 1);   glVertex3f(-size, size, -size);
        glEnd();
    
    
        glTexCoord2f(0, 0); glVertex3f(size, -size, size);
        glTexCoord2f(1, 0); glVertex3f(-size, -size, size);
        glTexCoord2f(1, 1); glVertex3f(-size, size, size);
        glTexCoord2f(0, 1); glVertex3f(size, size, size);
        glEnd();
    
    
        glTexCoord2f(0, 0); glVertex3f(-size, -size, size);
        glTexCoord2f(1, 0); glVertex3f(-size, -size, -size);
        glTexCoord2f(1, 1); glVertex3f(-size, size, -size);
        glTexCoord2f(0, 1); glVertex3f(-size, size, size);
        glEnd();
    
    
        glTexCoord2f(0, 0); glVertex3f(size, -size, -size);
        glTexCoord2f(1, 0); glVertex3f(size, -size, size);
        glTexCoord2f(1, 1); glVertex3f(size, size, size);
        glTexCoord2f(0, 1); glVertex3f(size, size, -size);
        glEnd();
    
    
        glTexCoord2f(0, 0); glVertex3f(-size, -size, size);
        glTexCoord2f(1, 0); glVertex3f(size, -size, size);
        glTexCoord2f(1, 1); glVertex3f(size, -size, -size);
        glTexCoord2f(0, 1); glVertex3f(-size, -size, -size);
        glEnd();
    
    
        glTexCoord2f(0, 0); glVertex3f(-size, size, -size);
        glTexCoord2f(1, 0); glVertex3f(size, size, -size);
        glTexCoord2f(1, 1); glVertex3f(size, size, size);
        glTexCoord2f(0, 1); glVertex3f(-size, size, size);
        glEnd();
    
        window.display();
    }
    
    glDeleteTextures(1, &amp;texture);
    return 0;
    

    }

    What if we connect the library? #include <gl/glu.h> errors appear: введите сюда описание изображения



  • No. #include <gl/glu.h> You don't have the right C++ for a job with a squirrel. Compiler C++ doesn't see them.

    That's why you're making mistakes. C3861 And so on, I suppose it's a compiler's mistake.

    When you hook up. glu.hthe programme is compiled because the compiler has all the appropriate reference code available, but LNK errors are emerging. It's Linker's mistakes. So you didn't connect the computer library to opengl.

    You need to encrypt your program with the right library. Google to the question. link glu.h windows Is that it? https://stackoverflow.com/a/3939495/5006740


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2