Cube in c++ (with the SFML library)

The program should output the cube and rotate it. I write on a 64x system, but the program is on 32x. I didn't specify the paths.

Here are the errors:

enter a description of the image here

Here is 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, &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, &texture);
    return 0;
}

And if you connect the library #include <gl/glu.h>, then errors appear:enter a description of the image here

 0
Author: Kromster, 2016-05-26

2 answers

Without #include <gl/glu.h>, you don't have the declarations needed by the C++ language for working with liba (structures, classes, constants, etc.). The C++ compiler simply doesn't see them.

Therefore, you are given errors C3861 , etc., I believe these are compiler errors (never compiled under windows)

When you connect glu.h, the program compiles - because all the necessary source code is available for the compiler, but LNK * errors appear. These are linker errors. So you didn't connect the compiled library for working with opengl

You need to link your program to the correct library. Google answers the question link glu.h windows with this is

 1
Author: strangeqargo, 2017-05-23 12:39:03

There was the same problem. My problem was that I didn't have the opengl library. Just download it, install it in visual studio, and all the "glu" lines will start working.

 0
Author: LWProd, 2017-10-22 17:03:27