mirror of
https://github.com/IllusionMan1212/C2048.git
synced 2026-10-24 02:12:31 +00:00
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:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user