zephr/game: textures, icons, and buttons

- zephr: correctly set cursor when hovering button
- zephr: added texture loading and displaying
- zephr: added icon button
- game: added help and settings icon buttons
This commit is contained in:
2023-12-27 22:42:35 +02:00
parent 2fc8ac6456
commit 2f88c53a07
13 changed files with 263 additions and 57 deletions
+45
View File
@@ -0,0 +1,45 @@
#include "glad/gl.h"
#include "stb_image.h"
#include "core.h"
#include "texture.h"
TextureId load_texture(const char *path) {
int width, height, nrChannels;
unsigned char *data = stbi_load(path, &width, &height, &nrChannels, STBI_rgb_alpha);
GLuint texture_id;
u32 format = GL_RGBA;
switch (nrChannels) {
case 1:
format = GL_RED;
break;
case 2:
format = GL_RG;
break;
case 3:
format = GL_RGB;
break;
case 4:
format = GL_RGBA;
break;
}
glGenTextures(1, &texture_id);
glBindTexture(GL_TEXTURE_2D, texture_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);
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
stbi_image_free(data);
return texture_id;
}