jdah / minecraft-weekend

Minecraft, but I made it in 48 hours.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

textures

ImTheSadra opened this issue · comments

Hi im using g++ SDL2 and opengl for a project
for my texture i use this code

#define GL_GLEXT_LEGACY
#define GL_GLEXT_PROTOTYPES 

#define STB_IMAGE_IMPLEMENTATION

#include <GL/glu.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include <SDL2/SDL.h>
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <string>

#include "image.h"

using namespace std;

class Texture{
public:
    GLuint id;

    SDL_Surface* surf;

    Texture(char filename[]){
        this->surf = SDL_LoadBMP_RW(SDL_RWFromFile((char*)filename, "rb"), 1);
        if(this->surf == NULL){
            cout << SDL_GetError() << endl;
        }

        glGenTextures(1, &this->id);
        glBindTexture(GL_TEXTURE_2D, this->id);
        
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        
        int width, height, nrChannels;
        unsigned char *data = stbi_load(
            (char*)filename, &width, &height,
            &nrChannels, 0
        );
        if (data) {
            glTexImage2D(
                GL_TEXTURE_2D, 0, GL_RGBA,
                width, height, 0, GL_RGBA,
                GL_UNSIGNED_BYTE, data
            );
            glGenerateMipmap(GL_TEXTURE_2D);
        }
        else
        {
            cout << "Failed to load texture" << endl;
        }

        auto err = glGetError();
        if (err != GL_NO_ERROR){
            char* error;
            switch (err)
            {
            case GL_INVALID_OPERATION:
                error = (char*)"INVALID OPERATION - 1282";
                break;
            
            default:
                stringstream text;
                text << "UNKNOW ERROR - ";
                text << err;
                error = (char*)text.str().c_str();
                break;
            }
            cout << "[TEXTURE ERROR] - " << error << endl;
        }
    }
};

image.h is stb_image.h
but i have this error
undefined reference to `glGenerateMipmap'

can you help me pls?

GitHub issues are not a forum for getting help for your own code. GitHub issues are for submitting bug reports and feature requests to the owner of this repository.

undefined reference means the function you are trying to use does not exist. (or you haven't imported it properly).