Вот код :
main.cpp:
Код: Выделить всё
int main(int argc, char** argv)
{
...
texture grass_texture;
grass_texture.load(textures_path + "grass_tile.png", 0);
renderable r_plane;
shape s_plane;
shape_maker::rectangle(s_plane, 10, 10);
s_plane.to_renderable(r_plane);
...
while (!glfwWindowShouldClose(window) && !quit)
{
...
glUseProgram(texture_shader.program);
glBindTexture(GL_TEXTURE_2D, grass_texture.id);
glUniformMatrix4fv(texture_shader["uModel"], 1, GL_FALSE, &stack.m()[0][0]);
glUniform1i(texture_shader["uColorImage"], 0);
r_plane.bind();
glDrawElements(r_plane().mode, r_plane().count, r_plane().itype, 0);
glBindTexture(GL_TEXTURE_2D, 0);
...
}
Код: Выделить всё
#pragma once
#include
#include
#include
struct texture {
texture() { }
~texture() { }
int x_size, y_size;
int n_components;
GLuint id;
GLuint load(std::string name, GLuint texture_unit)
{
unsigned char * data;
data = stbi_load(name.c_str(), &x_size, &y_size, &n_components, 0);
if (data == NULL)
{
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/78743887/opengl-texture-not-showing[/url]