changed project to use CLion to be cross platform

This commit is contained in:
Claire Schwarzer 2026-02-01 04:49:24 +01:00
parent 6fb3ffcfed
commit dcc5871929
463 changed files with 69347 additions and 296 deletions

54
Engine/texture.h Normal file
View file

@ -0,0 +1,54 @@
#pragma once
#include <iostream>
#include <glad/glad.h>
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image/stb_image.h>
class Texture
{
public:
unsigned int ID;
int width, height, nrChannels;
Texture(const char* texturePath, bool flip = false)
{
// Create the Texture and set our ID
glGenTextures(1, &ID);
glBindTexture(GL_TEXTURE_2D, ID);
// set the texture wrapping/filtering options (on the currently bound texture object)
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_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// Grab the texture from our path
if (flip)
stbi_set_flip_vertically_on_load(true);
unsigned char *data = stbi_load(texturePath, &width, &height, &nrChannels, 0);
if (data)
{
GLenum format = (nrChannels == 4) ? GL_RGBA : GL_RGB;
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
}
else
{
std::cout << "Failed to load texture" << std::endl;
}
if (flip)
stbi_set_flip_vertically_on_load(false);
stbi_image_free(data);
}
void Draw() const
{
glActiveTexture(GL_TEXTURE);
glBindTexture(GL_TEXTURE_2D, ID);
}
};